Skip to content

Commit

Permalink
114858: Create and Add Guards to item&bitstream routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zahraa Chreim committed May 8, 2024
1 parent 08028dc commit 4658ac8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/app/bitstream-page/bitstream-page-authorizations.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { inject } from '@angular/core';
import { CanActivateFn, ResolveFn } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { BitstreamPageResolver } from './bitstream-page.resolver';
import { Bitstream } from '../core/shared/bitstream.model';
import { dsoPageSingleFeatureGuard } from '../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
import { FeatureID } from '../core/data/feature-authorization/feature-id';
import { RemoteData } from '../core/data/remote-data';

/**
* Guard for preventing unauthorized access to certain {@link Bitstream} pages requiring specific authorizations.
* Checks authorization rights for managing policies.
*/
export const bitstreamPageAuthorizationsGuard: CanActivateFn =
dsoPageSingleFeatureGuard(
() => {
const bitstreamPageResolver = inject(BitstreamPageResolver);
return bitstreamPageResolver.resolve as ResolveFn<Observable<RemoteData<Bitstream>>>;
},
() => observableOf(FeatureID.CanManagePolicies)
);
3 changes: 2 additions & 1 deletion src/app/bitstream-page/bitstream-page-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BitstreamBreadcrumbResolver } from '../core/breadcrumbs/bitstream-bread
import { BitstreamBreadcrumbsService } from '../core/breadcrumbs/bitstream-breadcrumbs.service';
import { I18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
import { ThemedEditBitstreamPageComponent } from './edit-bitstream-page/themed-edit-bitstream-page.component';
import { bitstreamPageAuthorizationsGuard } from './bitstream-page-authorizations.guard';

const EDIT_BITSTREAM_PATH = ':id/edit';
const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
Expand Down Expand Up @@ -58,7 +59,7 @@ const EDIT_BITSTREAM_AUTHORIZATIONS_PATH = ':id/authorizations';
},
{
path: EDIT_BITSTREAM_AUTHORIZATIONS_PATH,

canActivate: [bitstreamPageAuthorizationsGuard],
children: [
{
path: 'create',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import { itemPageWithdrawGuard } from './item-page-withdraw.guard';
import { itemPageReinstateGuard } from './item-page-reinstate.guard';
import { itemPageRegisterDoiGuard } from './item-page-register-doi.guard';
import { itemPageVersionHistoryGuard } from './item-page-version-history.guard';
import { itemPagePrivateGuard } from './item-page-private.guard';
import { itemPageMoveGuard } from './item-page-move.guard';
import { itemPageDeleteGuard } from './item-page-delete.guard';
import { itemPageEditAuthorizationsGuard } from './item-page-edit-authorizations.guard';

/**
* Routing module that handles the routing for the Edit Item page administrator functionality
Expand Down Expand Up @@ -142,6 +146,7 @@ import { itemPageVersionHistoryGuard } from './item-page-version-history.guard';
{
path: ITEM_EDIT_PRIVATE_PATH,
component: ItemPrivateComponent,
canActivate: [itemPagePrivateGuard]
},
{
path: ITEM_EDIT_PUBLIC_PATH,
Expand All @@ -150,11 +155,13 @@ import { itemPageVersionHistoryGuard } from './item-page-version-history.guard';
{
path: ITEM_EDIT_DELETE_PATH,
component: ItemDeleteComponent,
canActivate: [itemPageDeleteGuard]
},
{
path: ITEM_EDIT_MOVE_PATH,
component: ItemMoveComponent,
data: { title: 'item.edit.move.title' },
canActivate: [itemPageMoveGuard]
},
{
path: ITEM_EDIT_REGISTER_DOI_PATH,
Expand All @@ -179,7 +186,8 @@ import { itemPageVersionHistoryGuard } from './item-page-version-history.guard';
resourcePolicy: ResourcePolicyResolver
},
component: ResourcePolicyEditComponent,
data: { title: 'resource-policies.edit.page.title' }
data: { title: 'resource-policies.edit.page.title' },
canActivate: [itemPageEditAuthorizationsGuard]
},
{
path: '',
Expand Down
23 changes: 23 additions & 0 deletions src/app/item-page/edit-item-page/item-page-delete.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { inject } from '@angular/core';
import {
dsoPageSingleFeatureGuard
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
import { Item } from '../../core/shared/item.model';
import { ItemPageResolver } from '../item-page.resolver';
import { CanActivateFn, ResolveFn } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { RemoteData } from '../../core/data/remote-data';

/**
* Guard for preventing unauthorized access to certain {@link Item} pages requiring specific authorizations.
* Checks authorization rights for deleting items.
*/
export const itemPageDeleteGuard: CanActivateFn =
dsoPageSingleFeatureGuard(
() => {
const itemPageResolver = inject(ItemPageResolver);
return itemPageResolver.resolve as ResolveFn<Observable<RemoteData<Item>>>;
},
() => observableOf(FeatureID.CanDelete)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { inject } from '@angular/core';
import {
dsoPageSingleFeatureGuard
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
import { Item } from '../../core/shared/item.model';
import { ItemPageResolver } from '../item-page.resolver';
import { CanActivateFn, ResolveFn } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { RemoteData } from '../../core/data/remote-data';

/**
* Guard for preventing unauthorized access to certain {@link Item} pages requiring specific authorizations.
* Checks authorization rights for managing policies.
*/
export const itemPageEditAuthorizationsGuard: CanActivateFn =
dsoPageSingleFeatureGuard(
() => {
const itemPageResolver = inject(ItemPageResolver);
return itemPageResolver.resolve as ResolveFn<Observable<RemoteData<Item>>>;
},
() => observableOf(FeatureID.CanManagePolicies)
);
23 changes: 23 additions & 0 deletions src/app/item-page/edit-item-page/item-page-move.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { inject } from '@angular/core';
import {
dsoPageSingleFeatureGuard
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
import { Item } from '../../core/shared/item.model';
import { ItemPageResolver } from '../item-page.resolver';
import { CanActivateFn, ResolveFn } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { RemoteData } from '../../core/data/remote-data';

/**
* Guard for preventing unauthorized access to certain {@link Item} pages requiring specific authorizations.
* Checks authorization rights for moving items.
*/
export const itemPageMoveGuard: CanActivateFn =
dsoPageSingleFeatureGuard(
() => {
const itemPageResolver = inject(ItemPageResolver);
return itemPageResolver.resolve as ResolveFn<Observable<RemoteData<Item>>>;
},
() => observableOf(FeatureID.CanMove)
);
23 changes: 23 additions & 0 deletions src/app/item-page/edit-item-page/item-page-private.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { inject } from '@angular/core';
import {
dsoPageSingleFeatureGuard
} from '../../core/data/feature-authorization/feature-authorization-guard/dso-page-single-feature.guard';
import { Item } from '../../core/shared/item.model';
import { ItemPageResolver } from '../item-page.resolver';
import { CanActivateFn, ResolveFn } from '@angular/router';
import { Observable, of as observableOf } from 'rxjs';
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
import { RemoteData } from '../../core/data/remote-data';

/**
* Guard for preventing unauthorized access to certain {@link Item} pages requiring specific authorizations.
* Checks authorization rights for making items private.
*/
export const itemPagePrivateGuard: CanActivateFn =
dsoPageSingleFeatureGuard(
() => {
const itemPageResolver = inject(ItemPageResolver);
return itemPageResolver.resolve as ResolveFn<Observable<RemoteData<Item>>>;
},
() => observableOf(FeatureID.CanMakePrivate)
);

0 comments on commit 4658ac8

Please sign in to comment.