Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { of as observableOf } from 'rxjs';
import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard';
import { Observable } from 'rxjs/internal/Observable';
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { AuthService } from '../core/auth/auth.service';

@Injectable({
providedIn: 'root'
Expand All @@ -17,8 +18,9 @@ import { FeatureID } from '../core/data/feature-authorization/feature-id';
export class CollectionPageAdministratorGuard extends DsoPageFeatureGuard<Collection> {
constructor(protected resolver: CollectionPageResolver,
protected authorizationService: AuthorizationDataService,
protected router: Router) {
super(resolver, authorizationService, router);
protected router: Router,
protected authService: AuthService) {
super(resolver, authorizationService, router, authService);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/app/+collection-page/collection-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
import { Item } from '../core/shared/item.model';
import {
getSucceededRemoteData,
redirectOn404Or401,
redirectOn4xx,
toDSpaceObjectListRD
} from '../core/shared/operators';

import { fadeIn, fadeInOut } from '../shared/animations/fade';
import { hasNoValue, hasValue, isNotEmpty } from '../shared/empty.util';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { AuthService } from '../core/auth/auth.service';

@Component({
selector: 'ds-collection-page',
Expand Down Expand Up @@ -51,7 +52,8 @@ export class CollectionPageComponent implements OnInit {
private searchService: SearchService,
private metadata: MetadataService,
private route: ActivatedRoute,
private router: Router
private router: Router,
private authService: AuthService,
) {
this.paginationConfig = new PaginationComponentOptions();
this.paginationConfig.id = 'collection-page-pagination';
Expand All @@ -63,7 +65,7 @@ export class CollectionPageComponent implements OnInit {
ngOnInit(): void {
this.collectionRD$ = this.route.data.pipe(
map((data) => data.dso as RemoteData<Collection>),
redirectOn404Or401(this.router),
redirectOn4xx(this.router, this.authService),
take(1)
);
this.logoRD$ = this.collectionRD$.pipe(
Expand Down
6 changes: 4 additions & 2 deletions src/app/+community-page/community-page-administrator.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { of as observableOf } from 'rxjs';
import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard';
import { Observable } from 'rxjs/internal/Observable';
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { AuthService } from '../core/auth/auth.service';

@Injectable({
providedIn: 'root'
Expand All @@ -17,8 +18,9 @@ import { FeatureID } from '../core/data/feature-authorization/feature-id';
export class CommunityPageAdministratorGuard extends DsoPageFeatureGuard<Community> {
constructor(protected resolver: CommunityPageResolver,
protected authorizationService: AuthorizationDataService,
protected router: Router) {
super(resolver, authorizationService, router);
protected router: Router,
protected authService: AuthService) {
super(resolver, authorizationService, router, authService);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/app/+community-page/community-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { MetadataService } from '../core/metadata/metadata.service';

import { fadeInOut } from '../shared/animations/fade';
import { hasValue } from '../shared/empty.util';
import { redirectOn404Or401 } from '../core/shared/operators';
import { redirectOn4xx } from '../core/shared/operators';
import { AuthService } from '../core/auth/auth.service';

@Component({
selector: 'ds-community-page',
Expand All @@ -39,15 +40,16 @@ export class CommunityPageComponent implements OnInit {
private communityDataService: CommunityDataService,
private metadata: MetadataService,
private route: ActivatedRoute,
private router: Router
private router: Router,
private authService: AuthService,
) {

}

ngOnInit(): void {
this.communityRD$ = this.route.data.pipe(
map((data) => data.dso as RemoteData<Community>),
redirectOn404Or401(this.router)
redirectOn4xx(this.router, this.authService)
);
this.logoRD$ = this.communityRD$.pipe(
map((rd: RemoteData<Community>) => rd.payload),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/ro
import { Observable } from 'rxjs/internal/Observable';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { of as observableOf } from 'rxjs';
import { AuthService } from '../../core/auth/auth.service';

@Injectable({
providedIn: 'root'
Expand All @@ -17,8 +18,9 @@ import { of as observableOf } from 'rxjs';
export class ItemPageReinstateGuard extends DsoPageFeatureGuard<Item> {
constructor(protected resolver: ItemPageResolver,
protected authorizationService: AuthorizationDataService,
protected router: Router) {
super(resolver, authorizationService, router);
protected router: Router,
protected authService: AuthService) {
super(resolver, authorizationService, router, authService);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/app/+item-page/edit-item-page/item-page-withdraw.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/ro
import { Observable } from 'rxjs/internal/Observable';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { of as observableOf } from 'rxjs';
import { AuthService } from '../../core/auth/auth.service';

@Injectable({
providedIn: 'root'
Expand All @@ -17,8 +18,9 @@ import { of as observableOf } from 'rxjs';
export class ItemPageWithdrawGuard extends DsoPageFeatureGuard<Item> {
constructor(protected resolver: ItemPageResolver,
protected authorizationService: AuthorizationDataService,
protected router: Router) {
super(resolver, authorizationService, router);
protected router: Router,
protected authService: AuthService) {
super(resolver, authorizationService, router, authService);
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/app/+item-page/full/full-item-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
createSuccessfulRemoteDataObject,
createSuccessfulRemoteDataObject$
} from '../../shared/remote-data.utils';
import { AuthService } from '../../core/auth/auth.service';

const mockItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
Expand All @@ -45,7 +46,14 @@ describe('FullItemPageComponent', () => {
let comp: FullItemPageComponent;
let fixture: ComponentFixture<FullItemPageComponent>;

let authService: AuthService;

beforeEach(async(() => {
authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
setRedirectUrl: {}
});

TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
Expand All @@ -57,7 +65,8 @@ describe('FullItemPageComponent', () => {
providers: [
{provide: ActivatedRoute, useValue: routeStub},
{provide: ItemDataService, useValue: {}},
{provide: MetadataService, useValue: metadataServiceStub}
{provide: MetadataService, useValue: metadataServiceStub},
{ provide: AuthService, useValue: authService },
],

schemas: [NO_ERRORS_SCHEMA]
Expand Down
5 changes: 3 additions & 2 deletions src/app/+item-page/full/full-item-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MetadataService } from '../../core/metadata/metadata.service';

import { fadeInOut } from '../../shared/animations/fade';
import { hasValue } from '../../shared/empty.util';
import { AuthService } from '../../core/auth/auth.service';

/**
* This component renders a simple item page.
Expand All @@ -35,8 +36,8 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit {

metadata$: Observable<MetadataMap>;

constructor(route: ActivatedRoute, router: Router, items: ItemDataService, metadataService: MetadataService) {
super(route, router, items, metadataService);
constructor(route: ActivatedRoute, router: Router, items: ItemDataService, metadataService: MetadataService, authService: AuthService) {
super(route, router, items, metadataService, authService);
}

/*** AoT inheritance fix, will hopefully be resolved in the near future **/
Expand Down
6 changes: 4 additions & 2 deletions src/app/+item-page/item-page-administrator.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DsoPageFeatureGuard } from '../core/data/feature-authorization/feature-
import { Observable } from 'rxjs/internal/Observable';
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { of as observableOf } from 'rxjs';
import { AuthService } from '../core/auth/auth.service';

@Injectable({
providedIn: 'root'
Expand All @@ -17,8 +18,9 @@ import { of as observableOf } from 'rxjs';
export class ItemPageAdministratorGuard extends DsoPageFeatureGuard<Item> {
constructor(protected resolver: ItemPageResolver,
protected authorizationService: AuthorizationDataService,
protected router: Router) {
super(resolver, authorizationService, router);
protected router: Router,
protected authService: AuthService) {
super(resolver, authorizationService, router, authService);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/app/+item-page/simple/item-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
createFailedRemoteDataObject$, createPendingRemoteDataObject$, createSuccessfulRemoteDataObject,
createSuccessfulRemoteDataObject$
} from '../../shared/remote-data.utils';
import { AuthService } from '../../core/auth/auth.service';

const mockItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
Expand All @@ -29,6 +30,7 @@ const mockItem: Item = Object.assign(new Item(), {
describe('ItemPageComponent', () => {
let comp: ItemPageComponent;
let fixture: ComponentFixture<ItemPageComponent>;
let authService: AuthService;

const mockMetadataService = {
/* tslint:disable:no-empty */
Expand All @@ -40,6 +42,11 @@ describe('ItemPageComponent', () => {
});

beforeEach(async(() => {
authService = jasmine.createSpyObj('authService', {
isAuthenticated: observableOf(true),
setRedirectUrl: {}
});

TestBed.configureTestingModule({
imports: [TranslateModule.forRoot({
loader: {
Expand All @@ -52,7 +59,8 @@ describe('ItemPageComponent', () => {
{provide: ActivatedRoute, useValue: mockRoute},
{provide: ItemDataService, useValue: {}},
{provide: MetadataService, useValue: mockMetadataService},
{provide: Router, useValue: {}}
{provide: Router, useValue: {}},
{ provide: AuthService, useValue: authService },
],

schemas: [NO_ERRORS_SCHEMA]
Expand Down
6 changes: 4 additions & 2 deletions src/app/+item-page/simple/item-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { Item } from '../../core/shared/item.model';
import { MetadataService } from '../../core/metadata/metadata.service';

import { fadeInOut } from '../../shared/animations/fade';
import { redirectOn404Or401 } from '../../core/shared/operators';
import { redirectOn4xx } from '../../core/shared/operators';
import { ViewMode } from '../../core/shared/view-mode.model';
import { AuthService } from '../../core/auth/auth.service';

/**
* This component renders a simple item page.
Expand Down Expand Up @@ -48,6 +49,7 @@ export class ItemPageComponent implements OnInit {
private router: Router,
private items: ItemDataService,
private metadataService: MetadataService,
private authService: AuthService,
) { }

/**
Expand All @@ -56,7 +58,7 @@ export class ItemPageComponent implements OnInit {
ngOnInit(): void {
this.itemRD$ = this.route.data.pipe(
map((data) => data.dso as RemoteData<Item>),
redirectOn404Or401(this.router)
redirectOn4xx(this.router, this.authService)
);
this.metadataService.processRemoteData(this.itemRD$);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/app-routing-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function getDSORoute(dso: DSpaceObject): string {
}
}

export const UNAUTHORIZED_PATH = '401';
export const FORBIDDEN_PATH = '403';

export function getUnauthorizedRoute() {
return `/${UNAUTHORIZED_PATH}`;
export function getForbiddenRoute() {
return `/${FORBIDDEN_PATH}`;
}

export const PAGE_NOT_FOUND_PATH = '404';
Expand Down
8 changes: 4 additions & 4 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import { AuthBlockingGuard } from './core/auth/auth-blocking.guard';
import { PageNotFoundComponent } from './pagenotfound/pagenotfound.component';
import { AuthenticatedGuard } from './core/auth/authenticated.guard';
import { SiteAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/site-administrator.guard';
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
import {
UNAUTHORIZED_PATH,
WORKFLOW_ITEM_MODULE_PATH,
FORGOT_PASSWORD_PATH,
REGISTER_PATH,
PROFILE_MODULE_PATH,
ADMIN_MODULE_PATH,
BITSTREAM_MODULE_PATH,
INFO_MODULE_PATH
INFO_MODULE_PATH,
FORBIDDEN_PATH,
} from './app-routing-paths';
import { COLLECTION_MODULE_PATH } from './+collection-page/collection-page-routing-paths';
import { COMMUNITY_MODULE_PATH } from './+community-page/community-page-routing-paths';
import { ITEM_MODULE_PATH } from './+item-page/item-page-routing-paths';
import { ReloadGuard } from './core/reload/reload.guard';
import { EndUserAgreementCurrentUserGuard } from './core/end-user-agreement/end-user-agreement-current-user.guard';
import { SiteRegisterGuard } from './core/data/feature-authorization/feature-authorization-guard/site-register.guard';
import { ForbiddenComponent } from './forbidden/forbidden.component';

@NgModule({
imports: [
Expand Down Expand Up @@ -68,7 +68,7 @@ import { SiteRegisterGuard } from './core/data/feature-authorization/feature-aut
},
{ path: 'processes', loadChildren: './process-page/process-page.module#ProcessPageModule', canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] },
{ path: INFO_MODULE_PATH, loadChildren: './info/info.module#InfoModule' },
{ path: UNAUTHORIZED_PATH, component: UnauthorizedComponent },
{ path: FORBIDDEN_PATH, component: ForbiddenComponent },
{
path: 'statistics',
loadChildren: './statistics-page/statistics-page-routing.module#StatisticsPageRoutingModule',
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { SharedModule } from './shared/shared.module';
import { BreadcrumbsComponent } from './breadcrumbs/breadcrumbs.component';
import { environment } from '../environments/environment';
import { BrowserModule } from '@angular/platform-browser';
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
import { ForbiddenComponent } from './forbidden/forbidden.component';

export function getBase() {
return environment.ui.nameSpace;
Expand Down Expand Up @@ -116,6 +116,8 @@ const DECLARATIONS = [
NotificationComponent,
NotificationsBoardComponent,
SearchNavbarComponent,
BreadcrumbsComponent,
ForbiddenComponent,
];

const EXPORTS = [
Expand All @@ -133,8 +135,6 @@ const EXPORTS = [
],
declarations: [
...DECLARATIONS,
BreadcrumbsComponent,
UnauthorizedComponent,
],
exports: [
...EXPORTS
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export class AuthService {
* Clear redirect url
*/
clearRedirectUrl() {
this.store.dispatch(new SetRedirectUrlAction(''));
this.store.dispatch(new SetRedirectUrlAction(undefined));
this.storage.remove(REDIRECT_COOKIE);
}

Expand Down
Loading