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
6 changes: 6 additions & 0 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export const routes: Routes = [
import('./core/components/request-access/request-access.component').then((mod) => mod.RequestAccessComponent),
data: { skipBreadcrumbs: true },
},
{
path: 'not-found',
loadComponent: () =>
import('./core/components/page-not-found/page-not-found.component').then((mod) => mod.PageNotFoundComponent),
data: { skipBreadcrumbs: true },
},
{
path: ':id/files/:provider/:fileId',
loadComponent: () =>
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/components/nav-menu/nav-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class NavMenuComponent {
preprintReviewsPageVisible: this.canUserViewReviews(),
registrationModerationPageVisible:
this.provider()?.type === CurrentResourceType.Registrations &&
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions) &&
!!this.provider()?.reviewsWorkflow,
collectionModerationPageVisible:
this.provider()?.type === CurrentResourceType.Collections &&
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
Expand Down
35 changes: 35 additions & 0 deletions src/app/core/guards/registration-moderation.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Store } from '@ngxs/store';

import { map, switchMap, take } from 'rxjs';

import { inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router';

import { GetRegistryProvider, RegistrationProviderSelectors } from '@osf/shared/stores/registration-provider';

export const registrationModerationGuard: CanActivateFn = (route) => {
const store = inject(Store);
const router = inject(Router);

const provider = store.selectSnapshot(RegistrationProviderSelectors.getBrandedProvider);

if (provider?.reviewsWorkflow) {
return true;
}
const id = route.params['providerId'];
return store.dispatch(new GetRegistryProvider(id)).pipe(
switchMap(() => {
return store.select(RegistrationProviderSelectors.getBrandedProvider).pipe(
take(1),
map((provider) => {
if (!provider?.reviewsWorkflow) {
router.navigate(['/not-found']);
return false;
}

return true;
})
);
})
);
};
3 changes: 2 additions & 1 deletion src/app/features/registries/registries.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { provideStates } from '@ngxs/store';

import { Routes } from '@angular/router';

import { registrationModerationGuard } from '@core/guards/registration-moderation.guard';
import { authGuard } from '@osf/core/guards';
import { RegistriesComponent } from '@osf/features/registries/registries.component';
import { RegistriesState } from '@osf/features/registries/store';
Expand Down Expand Up @@ -43,7 +44,7 @@ export const registriesRoutes: Routes = [
},
{
path: ':providerId/moderation',
canActivate: [authGuard],
canActivate: [authGuard, registrationModerationGuard],
loadChildren: () =>
import('@osf/features/moderation/registry-moderation.routes').then((c) => c.registryModerationRoutes),
},
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/mappers/registration-provider.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class RegistrationProviderMapper {
}
: null,
iri: response.links.iri,
reviewsWorkflow: response.attributes.reviews_workflow,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class RegistrationNodeMapper {
name: provider.attributes.name,
permissions: provider.attributes.permissions,
type: CurrentResourceType.Registrations,
reviewsWorkflow: provider.attributes.reviews_workflow,
};
}
}
1 change: 1 addition & 0 deletions src/app/shared/models/provider/provider.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ProviderShortInfoModel {
name: string;
type: CurrentResourceType;
permissions?: ReviewPermissions[];
reviewsWorkflow?: string;
}

export interface BaseProviderModel {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/models/provider/registry-provider.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface RegistryProviderDetails {
permissions: ReviewPermissions[];
brand: Brand | null;
iri: string;
reviewsWorkflow: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const stateName = '[Registry Provider Search]';
export class GetRegistryProvider {
static readonly type = `${stateName} Get Registry Provider`;

constructor(public providerName: string) {}
constructor(public providerId: string) {}
}

export class ClearRegistryProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Action, State, StateContext } from '@ngxs/store';
import { patch } from '@ngxs/store/operators';

import { catchError, of, tap } from 'rxjs';

Expand Down Expand Up @@ -30,14 +29,14 @@ export class RegistrationProviderState {
const state = ctx.getState();

const currentProvider = state.currentBrandedProvider.data;

if (currentProvider?.name === action.providerName) {
if (currentProvider && currentProvider?.id === action.providerId) {
ctx.dispatch(
new SetCurrentProvider({
id: currentProvider.id,
name: currentProvider.name,
id: currentProvider?.id,
name: currentProvider?.name,
type: CurrentResourceType.Registrations,
permissions: currentProvider.permissions,
permissions: currentProvider?.permissions,
reviewsWorkflow: currentProvider?.reviewsWorkflow,
})
);

Expand All @@ -51,24 +50,23 @@ export class RegistrationProviderState {
},
});

return this.registrationProvidersService.getProviderBrand(action.providerName).pipe(
return this.registrationProvidersService.getProviderBrand(action.providerId).pipe(
tap((provider) => {
ctx.setState(
patch({
currentBrandedProvider: patch({
data: provider,
isLoading: false,
error: null,
}),
})
);
ctx.patchState({
currentBrandedProvider: {
data: provider,
isLoading: false,
error: null,
},
});

ctx.dispatch(
new SetCurrentProvider({
id: provider.id,
name: provider.name,
type: CurrentResourceType.Registrations,
permissions: provider.permissions,
reviewsWorkflow: provider.reviewsWorkflow,
})
);
}),
Expand All @@ -78,6 +76,6 @@ export class RegistrationProviderState {

@Action(ClearRegistryProvider)
clearRegistryProvider(ctx: StateContext<RegistrationProviderStateModel>) {
ctx.setState(patch({ ...REGISTRIES_PROVIDER_SEARCH_STATE_DEFAULTS }));
ctx.patchState({ ...REGISTRIES_PROVIDER_SEARCH_STATE_DEFAULTS });
}
}
Loading