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
9 changes: 9 additions & 0 deletions src/app/core/store/provider/provider.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Selector } from '@ngxs/store';

import { ReviewPermissions } from '@osf/shared/enums';
import { ProviderShortInfoModel } from '@osf/shared/models';

import { ProviderStateModel } from './provider.model';
Expand All @@ -10,4 +11,12 @@ export class ProviderSelectors {
static getCurrentProvider(state: ProviderStateModel): ProviderShortInfoModel | null {
return state.currentProvider;
}

@Selector([ProviderState])
static hasAdminAccess(state: ProviderStateModel): boolean {
return (
state.currentProvider?.permissions?.some((permission) => permission === ReviewPermissions.SetUpModeration) ||
false
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="flex flex-column gap-4 md:flex-row md:gap-6">
<osf-search-input class="w-full" [control]="searchControl" [placeholder]="'common.search.title' | translate" />

@if (isCurrentUserAdminModerator()) {
@if (hasAdminAccess()) {
<div class="ml-auto w-full md:w-4">
<p-button
class="w-full"
Expand All @@ -20,7 +20,7 @@
[isLoading]="isModeratorsLoading()"
[currentUserId]="currentUser()?.id"
[tableParams]="tableParams()"
[isCurrentUserAdminModerator]="isCurrentUserAdminModerator()"
[hasAdminAccess]="hasAdminAccess()"
(pageChanged)="pageChanged($event)"
(update)="updateModerator($event)"
(remove)="removeModerator($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';

import { ProviderSelectors } from '@core/store/provider';
import { UserSelectors } from '@core/store/user';
import { SearchInputComponent } from '@osf/shared/components';
import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants';
import { ResourceType } from '@osf/shared/enums';
import { TableParameters } from '@osf/shared/models';
import { CustomConfirmationService, CustomDialogService, ToastService } from '@osf/shared/services';

import { AddModeratorType, ModeratorPermission } from '../../enums';
import { AddModeratorType } from '../../enums';
import { ModeratorDialogAddModel, ModeratorModel } from '../../models';
import {
AddModerator,
Expand Down Expand Up @@ -70,6 +71,7 @@ export class ModeratorsListComponent implements OnInit {
initialModerators = select(ModeratorsSelectors.getModerators);
isModeratorsLoading = select(ModeratorsSelectors.isModeratorsLoading);
moderatorsTotalCount = select(ModeratorsSelectors.getModeratorsTotalCount);
hasAdminAccess = select(ProviderSelectors.hasAdminAccess);
currentUser = select(UserSelectors.getCurrentUser);

readonly tableParams = computed<TableParameters>(() => ({
Expand All @@ -78,17 +80,6 @@ export class ModeratorsListComponent implements OnInit {
paginator: this.moderatorsTotalCount() > DEFAULT_TABLE_PARAMS.rows,
}));

isCurrentUserAdminModerator = computed(() => {
const currentUserId = this.currentUser()?.id;
const initialModerators = this.initialModerators();
if (!currentUserId) return false;

return initialModerators.some(
(moderator: ModeratorModel) =>
moderator.userId === currentUserId && moderator.permission === ModeratorPermission.Admin
);
});

actions = createDispatchMap({
loadModerators: LoadModerators,
updateSearchValue: UpdateModeratorsSearchValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</td>
<td>
<div>
@if (isCurrentUserAdminModerator()) {
@if (hasAdminAccess()) {
<osf-select
[options]="permissionsOptions"
[placeholder]="'project.contributors.permissionFilter'"
Expand Down Expand Up @@ -89,15 +89,15 @@
</div>
</td>
<td>
@if (isCurrentUserAdminModerator() || currentUserId() === item.id) {
@if (hasAdminAccess() || currentUserId() === item.id) {
<p-button
class="danger-icon-btn"
icon="fas fa-trash"
severity="danger"
text
(onClick)="removeModerator(item)"
[ariaLabel]="'common.buttons.delete' | translate"
[disabled]="!isCurrentUserAdminModerator() && currentUserId() !== item.id"
[disabled]="!hasAdminAccess() && currentUserId() !== item.id"
/>
}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ModeratorsTableComponent {
isLoading = input(false);
tableParams = input.required<TableParameters>();
currentUserId = input.required<string | undefined>();
isCurrentUserAdminModerator = input.required<boolean>();
hasAdminAccess = input.required<boolean>();

update = output<ModeratorModel>();
remove = output<ModeratorModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class PreprintModerationMapper {
return {
id: response.id,
name: response.attributes.name,
permissions: response.attributes.permissions,
reviewsCommentsAnonymous: response.attributes.reviews_comments_anonymous,
reviewsCommentsPrivate: response.attributes.reviews_comments_private,
reviewsWorkflow: response.attributes.reviews_workflow,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ReviewPermissions } from '@osf/shared/enums';

export interface PreprintProviderModerationInfo {
id: string;
name: string;
submissionCount?: number;
permissions: ReviewPermissions[];
reviewsCommentsAnonymous: boolean;
reviewsCommentsPrivate: boolean;
reviewsWorkflow: string;
submissionCount?: number;
supportEmail: string | null;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createDispatchMap } from '@ngxs/store';

import { TranslatePipe } from '@ngx-translate/core';

import { Tab, TabList, TabPanels, Tabs } from 'primeng/tabs';
Expand All @@ -13,6 +15,7 @@ import { IS_MEDIUM, Primitive } from '@osf/shared/helpers';

import { PREPRINT_MODERATION_TABS } from '../../constants';
import { PreprintModerationTab } from '../../enums';
import { GetPreprintProvider } from '../../store/preprint-moderation';

@Component({
selector: 'osf-preprint-moderation',
Expand Down Expand Up @@ -41,8 +44,19 @@ export class PreprintModerationComponent implements OnInit {

selectedTab = PreprintModerationTab.Submissions;

private readonly actions = createDispatchMap({ getPreprintProvider: GetPreprintProvider });

ngOnInit(): void {
this.selectedTab = this.route.snapshot.firstChild?.data['tab'] as PreprintModerationTab;

const id = this.route.snapshot.params['providerId'];

if (!id) {
this.router.navigate(['/not-found']);
return;
}

this.actions.getPreprintProvider(id);
}

onTabChange(value: Primitive): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { catchError, forkJoin, map, Observable, of, switchMap } from 'rxjs';
import { inject, Injectable } from '@angular/core';

import { ENVIRONMENT } from '@core/provider/environment.provider';
import { JsonApiResponse, PaginatedData, ResponseJsonApi } from '@osf/shared/models';
import { PaginatedData, ResponseJsonApi } from '@osf/shared/models';
import { JsonApiService } from '@osf/shared/services';

import { PreprintSubmissionsSort } from '../enums';
Expand Down Expand Up @@ -36,15 +36,15 @@ export class PreprintModerationService {
const baseUrl = `${this.apiUrl}/providers/preprints/?filter[permissions]=view_actions,set_up_moderation`;

return this.jsonApiService
.get<JsonApiResponse<PreprintRelatedCountJsonApi[], null>>(baseUrl)
.get<ResponseJsonApi<PreprintRelatedCountJsonApi[]>>(baseUrl)
.pipe(map((response) => response.data.map((x) => PreprintModerationMapper.fromPreprintRelatedCounts(x))));
}

getPreprintProvider(id: string): Observable<PreprintProviderModerationInfo> {
const baseUrl = `${this.apiUrl}/providers/preprints/${id}/?related_counts=true`;

return this.jsonApiService
.get<JsonApiResponse<PreprintRelatedCountJsonApi, null>>(baseUrl)
.get<ResponseJsonApi<PreprintRelatedCountJsonApi>>(baseUrl)
.pipe(map((response) => PreprintModerationMapper.fromPreprintRelatedCounts(response.data)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class ModeratorsState {
}

@Action(UpdateModerator)
updateCollectionModerator(ctx: StateContext<ModeratorsStateModel>, action: UpdateModerator) {
updateModerator(ctx: StateContext<ModeratorsStateModel>, action: UpdateModerator) {
const state = ctx.getState();

if (!action.resourceType) {
Expand All @@ -108,7 +108,7 @@ export class ModeratorsState {
}

@Action(DeleteModerator)
deleteCollectionModerator(ctx: StateContext<ModeratorsStateModel>, action: DeleteModerator) {
deleteModerator(ctx: StateContext<ModeratorsStateModel>, action: DeleteModerator) {
const state = ctx.getState();

if (!action.resourceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { catchError, forkJoin, map, switchMap, tap } from 'rxjs';

import { inject, Injectable } from '@angular/core';

import { SetCurrentProvider } from '@core/store/provider';
import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants';
import { ResourceType } from '@osf/shared/enums';
import { CurrentResourceType, ResourceType } from '@osf/shared/enums';
import { handleSectionError } from '@osf/shared/helpers';
import { ContributorsService } from '@osf/shared/services';

Expand Down Expand Up @@ -92,6 +93,16 @@ export class PreprintModerationState {
tap((data) => {
const exists = ctx.getState().preprintProviders.data.some((p) => p.id === data.id);

ctx.dispatch(
new SetCurrentProvider({
id: data.id,
name: data.name,
type: CurrentResourceType.Preprints,
permissions: data.permissions,
reviewsWorkflow: data.reviewsWorkflow,
})
);

ctx.setState(
patch({
preprintProviders: patch({
Expand Down
Loading