Skip to content

Commit 0939378

Browse files
authored
Fix/649 moderation tab (#400)
* fix(users): added 5 more columns options * fix(summary): fixed charts numbers display * fix(institutions): updates * fix(users-state): removed unused code * fix(collections): updated imports * fix(provider): updated collection and registration providers * fix(registry-provider): updated provider for registrations * fix(moderation-tab): updated provider setup * fix(tests): fixed unit tests * fix(conflict): removed code from conflict * fix(banner): fixed code in banner component * fix(collections): fixed visibility of collections tab * fix(collections): fixed subjects bug * fix(moderators): fixed moderators and contributors search
1 parent db8b5ee commit 0939378

File tree

111 files changed

+711
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+711
-558
lines changed

src/app/core/components/nav-menu/nav-menu.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import { toSignal } from '@angular/core/rxjs-interop';
1212
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive } from '@angular/router';
1313

1414
import { MENU_ITEMS } from '@core/constants';
15+
import { ProviderSelectors } from '@core/store/provider';
1516
import { filterMenuItems, updateMenuItems } from '@osf/core/helpers';
1617
import { RouteContext } from '@osf/core/models';
1718
import { AuthService } from '@osf/core/services';
1819
import { UserSelectors } from '@osf/core/store/user';
1920
import { IconComponent } from '@osf/shared/components';
20-
import { CurrentResourceType } from '@osf/shared/enums';
21+
import { CurrentResourceType, ReviewPermissions } from '@osf/shared/enums';
2122
import { getViewOnlyParam } from '@osf/shared/helpers';
2223
import { WrapFnPipe } from '@osf/shared/pipes';
2324
import { CurrentResourceSelectors } from '@osf/shared/stores';
@@ -37,14 +38,15 @@ export class NavMenuComponent {
3738

3839
private readonly isAuthenticated = select(UserSelectors.isAuthenticated);
3940
private readonly currentResource = select(CurrentResourceSelectors.getCurrentResource);
41+
private readonly provider = select(ProviderSelectors.getCurrentProvider);
4042

4143
readonly mainMenuItems = computed(() => {
4244
const isAuthenticated = this.isAuthenticated();
4345
const filtered = filterMenuItems(MENU_ITEMS, isAuthenticated);
4446

4547
const routeContext: RouteContext = {
4648
resourceId: this.currentResourceId(),
47-
providerId: this.currentProviderId(),
49+
providerId: this.provider()?.id,
4850
isProject:
4951
this.currentResource()?.type === CurrentResourceType.Projects &&
5052
this.currentResourceId() === this.currentResource()?.id,
@@ -53,6 +55,12 @@ export class NavMenuComponent {
5355
this.currentResourceId() === this.currentResource()?.id,
5456
isPreprint: this.isPreprintRoute(),
5557
preprintReviewsPageVisible: this.canUserViewReviews(),
58+
registrationModerationPageVisible:
59+
this.provider()?.type === CurrentResourceType.Registrations &&
60+
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
61+
collectionModerationPageVisible:
62+
this.provider()?.type === CurrentResourceType.Collections &&
63+
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
5664
isCollections: this.isCollectionsRoute() || false,
5765
currentUrl: this.router.url,
5866
isViewOnly: !!getViewOnlyParam(this.router),

src/app/core/constants/nav-items.constant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export const MENU_ITEMS: MenuItem[] = [
329329
routerLink: 'moderation',
330330
label: 'navigation.moderation',
331331
visible: false,
332-
routerLinkActiveOptions: { exact: true },
332+
routerLinkActiveOptions: { exact: false },
333333
},
334334
],
335335
},

src/app/core/helpers/nav-menu.helper.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function updateMenuItems(menuItems: MenuItem[], ctx: RouteContext): MenuI
6161
}
6262

6363
if (item.id === 'collections') {
64-
return { ...item, visible: ctx.isCollections };
64+
return updateCollectionMenuItem(item, ctx);
6565
}
6666

6767
return item;
@@ -137,6 +137,15 @@ function updateRegistryMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
137137
}
138138
return { ...subItem, visible: false, expanded: false };
139139
}
140+
141+
if (subItem.id === 'registries-moderation') {
142+
return {
143+
...subItem,
144+
visible: ctx.registrationModerationPageVisible,
145+
routerLink: ['/registries', ctx.providerId, 'moderation'],
146+
};
147+
}
148+
140149
return subItem;
141150
});
142151

@@ -169,3 +178,20 @@ function updatePreprintMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
169178

170179
return { ...item, expanded: ctx.isPreprint, items };
171180
}
181+
182+
function updateCollectionMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
183+
const isCollections = ctx.isCollections;
184+
185+
const items = (item.items || []).map((subItem) => {
186+
if (subItem.id === 'collections-moderation') {
187+
return {
188+
...subItem,
189+
visible: isCollections && ctx.collectionModerationPageVisible,
190+
routerLink: ['/collections', ctx.providerId, 'moderation'],
191+
};
192+
}
193+
return subItem;
194+
});
195+
196+
return { ...item, items, visible: ctx.isCollections };
197+
}

src/app/core/models/route-context.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface RouteContext {
55
isRegistry: boolean;
66
isPreprint: boolean;
77
preprintReviewsPageVisible?: boolean;
8+
registrationModerationPageVisible?: boolean;
9+
collectionModerationPageVisible?: boolean;
810
isCollections: boolean;
911
currentUrl?: string;
1012
isViewOnly?: boolean;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { ProviderModel } from '@osf/shared/models';
1+
import { ProviderShortInfoModel } from '@osf/shared/models';
22

33
export class SetCurrentProvider {
44
static readonly type = '[Provider] Set Current Provider';
5-
constructor(public provider: ProviderModel) {}
5+
constructor(public provider: ProviderShortInfoModel) {}
6+
}
7+
8+
export class ClearCurrentProvider {
9+
static readonly type = '[Provider] Clear Current Provider';
610
}

src/app/core/store/provider/provider.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ProviderModel } from '@osf/shared/models';
1+
import { ProviderShortInfoModel } from '@osf/shared/models';
22

33
export interface ProviderStateModel {
4-
currentProvider: ProviderModel | null;
4+
currentProvider: ProviderShortInfoModel | null;
55
}
66

77
export const PROVIDER_STATE_INITIAL: ProviderStateModel = {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Selector } from '@ngxs/store';
22

3-
import { ProviderModel } from '@osf/shared/models';
3+
import { ProviderShortInfoModel } from '@osf/shared/models';
44

55
import { ProviderStateModel } from './provider.model';
66
import { ProviderState } from './provider.state';
77

88
export class ProviderSelectors {
99
@Selector([ProviderState])
10-
static getCurrentProvider(state: ProviderStateModel): ProviderModel | null {
10+
static getCurrentProvider(state: ProviderStateModel): ProviderShortInfoModel | null {
1111
return state.currentProvider;
1212
}
1313
}

src/app/core/store/provider/provider.state.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Action, State, StateContext } from '@ngxs/store';
22

33
import { Injectable } from '@angular/core';
44

5-
import { SetCurrentProvider } from './provider.actions';
5+
import { ClearCurrentProvider, SetCurrentProvider } from './provider.actions';
66
import { PROVIDER_STATE_INITIAL, ProviderStateModel } from './provider.model';
77

88
@State<ProviderStateModel>({
@@ -13,8 +13,11 @@ import { PROVIDER_STATE_INITIAL, ProviderStateModel } from './provider.model';
1313
export class ProviderState {
1414
@Action(SetCurrentProvider)
1515
setCurrentProvider(ctx: StateContext<ProviderStateModel>, action: SetCurrentProvider) {
16-
ctx.patchState({
17-
currentProvider: action.provider,
18-
});
16+
ctx.patchState({ currentProvider: action.provider });
17+
}
18+
19+
@Action(ClearCurrentProvider)
20+
clearCurrentProvider(ctx: StateContext<ProviderStateModel>) {
21+
ctx.setState(PROVIDER_STATE_INITIAL);
1922
}
2023
}

src/app/core/store/user/user.actions.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ export class UpdateProfileSettingsUser {
4545
constructor(public payload: Partial<User>) {}
4646
}
4747

48-
export class SetUserAsModerator {
49-
static readonly type = '[User] Set User As Moderator';
50-
}
51-
5248
export class AcceptTermsOfServiceByUser {
5349
static readonly type = '[User] Accept Terms Of Service';
5450
}

src/app/core/store/user/user.selectors.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ export class UserSelectors {
5858
return state.currentUser.data?.social;
5959
}
6060

61-
@Selector([UserState])
62-
static isCurrentUserModerator(state: UserStateModel): boolean {
63-
return !!state.currentUser.data?.isModerator;
64-
}
65-
6661
@Selector([UserState])
6762
static getCanViewReviews(state: UserStateModel): boolean {
6863
return state.currentUser.data?.canViewReviews || false;

0 commit comments

Comments
 (0)