Skip to content
Open
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
@@ -1,11 +1,13 @@
<p-card class="w-full">
<h2>{{ 'common.labels.contributors' | translate }}</h2>

<div class="warning-message mt-4 mb-3">
<p-message icon="fas fa-circle-exclamation" severity="error">
{{ 'preprints.preprintContributorsWarning' | translate }}
</p-message>
</div>
@if (hasAdminAccess()) {
<div class="warning-message mt-4 mb-3">
<p-message icon="fas fa-circle-exclamation" severity="error">
{{ 'preprints.preprintContributorsWarning' | translate }}
</p-message>
</div>
}

<osf-contributors-table
class="w-full"
Expand All @@ -14,22 +16,25 @@ <h2>{{ 'common.labels.contributors' | translate }}</h2>
[isLoading]="isContributorsLoading()"
[showLoadMore]="hasMoreContributors()"
[isLoadingMore]="isLoadingMore()"
[hasAdminAccess]="hasAdminAccess()"
(remove)="removeContributor($event)"
(loadMore)="loadMoreContributors()"
/>
<div class="flex justify-content-end mt-3">
@if (hasChanges) {
<div class="flex gap-2 mr-4">
<p-button (onClick)="cancel()" severity="info" [label]="'common.buttons.cancel' | translate" />
<p-button (onClick)="save()" [label]="'common.buttons.save' | translate" />
</div>
}
<p-button
class="w-full md:w-auto"
styleClass="w-full"
[label]="'preprints.addContributorBySearch' | translate"
type="submit"
(onClick)="openAddContributorDialog()"
/>
</div>
@if (hasAdminAccess()) {
<div class="flex justify-content-end mt-3">
@if (hasChanges) {
<div class="flex gap-2 mr-4">
<p-button (onClick)="cancel()" severity="info" [label]="'common.buttons.cancel' | translate" />
<p-button (onClick)="save()" [label]="'common.buttons.save' | translate" />
</div>
}
<p-button
class="w-full md:w-auto"
styleClass="w-full"
[label]="'preprints.addContributorBySearch' | translate"
type="submit"
(onClick)="openAddContributorDialog()"
/>
</div>
}
</p-card>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Store } from '@ngxs/store';

import { MockComponent, MockProvider } from 'ng-mocks';
import { MockComponent, MockProvider, ngMocks } from 'ng-mocks';

import { of } from 'rxjs';

import { ComponentFixture, TestBed } from '@angular/core/testing';

import { PreprintStepperSelectors } from '@osf/features/preprints/store/preprint-stepper';
import { ContributorsTableComponent } from '@osf/shared/components/contributors/contributors-table/contributors-table.component';
import { AddContributorType } from '@osf/shared/enums/contributors/add-contributor-type.enum';
import { ResourceType } from '@osf/shared/enums/resource-type.enum';
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('PreprintsContributorsComponent', () => {
{ selector: ContributorsSelectors.isContributorsLoadingMore, value: false },
{ selector: ContributorsSelectors.getContributorsPageSize, value: 10 },
{ selector: ContributorsSelectors.getContributorsTotalCount, value: 1 },
{ selector: PreprintStepperSelectors.hasAdminAccess, value: true },
];

function setup(overrides?: {
Expand Down Expand Up @@ -109,6 +111,24 @@ describe('PreprintsContributorsComponent', () => {
expect(component.contributors()).not.toBe(mockContributors);
});

it('should allow admin to manage contributors', () => {
setup();

expect(ngMocks.input(ngMocks.find(ContributorsTableComponent), 'hasAdminAccess')).toBe(true);
expect(fixture.nativeElement.querySelector('p-message')).toBeTruthy();
expect(fixture.nativeElement.querySelectorAll('p-button').length).toBe(1);
});

it('should show contributors as read-only without admin access', () => {
setup({ selectorOverrides: [{ selector: PreprintStepperSelectors.hasAdminAccess, value: false }] });
component.contributors.set([{ ...MOCK_CONTRIBUTOR, fullName: 'Updated Name' }]);
fixture.detectChanges();

expect(ngMocks.input(ngMocks.find(ContributorsTableComponent), 'hasAdminAccess')).toBe(false);
expect(fixture.nativeElement.querySelector('p-message')).toBeNull();
expect(fixture.nativeElement.querySelectorAll('p-button').length).toBe(0);
});

it('should compute hasChanges correctly', () => {
setup();
expect(component.hasChanges).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

import { PreprintStepperSelectors } from '@osf/features/preprints/store/preprint-stepper';
import { AddContributorDialogComponent } from '@osf/shared/components/contributors/add-contributor-dialog/add-contributor-dialog.component';
import { AddUnregisteredContributorDialogComponent } from '@osf/shared/components/contributors/add-unregistered-contributor-dialog/add-unregistered-contributor-dialog.component';
import { ContributorsTableComponent } from '@osf/shared/components/contributors/contributors-table/contributors-table.component';
Expand Down Expand Up @@ -65,6 +66,7 @@ export class PreprintsContributorsComponent implements OnInit {
readonly hasMoreContributors = select(ContributorsSelectors.hasMoreContributors);
readonly isLoadingMore = select(ContributorsSelectors.isContributorsLoadingMore);
readonly pageSize = select(ContributorsSelectors.getContributorsPageSize);
readonly hasAdminAccess = select(PreprintStepperSelectors.hasAdminAccess);

readonly actions = createDispatchMap({
getContributors: GetAllContributors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { PreprintTombstoneComponent } from '../../components/preprint-details/pr
import { PreprintWarningBannerComponent } from '../../components/preprint-details/preprint-warning-banner/preprint-warning-banner.component';
import { ShareAndDownloadComponent } from '../../components/preprint-details/share-and-download/share-and-download.component';
import { StatusBannerComponent } from '../../components/preprint-details/status-banner/status-banner.component';
import { ReviewsState } from '../../enums';
import { ProviderReviewsWorkflow, ReviewsState } from '../../enums';
import {
FetchPreprintDetails,
FetchPreprintRequestActions,
Expand Down Expand Up @@ -407,6 +407,68 @@ describe('PreprintDetailsComponent', () => {
expect(component.editButtonVisible()).toBe(true);
});

it('should show edit button for previous version of preprint', () => {
setup({
selectorOverrides: [
{
selector: PreprintSelectors.getPreprint,
value: { ...mockPreprint, isLatestVersion: false, reviewsState: ReviewsState.Accepted },
},
],
});

expect(component.editButtonVisible()).toBe(true);
});

it('should show edit button for previous version of postmoderation preprint', () => {
setup({
selectorOverrides: [
{
selector: PreprintProvidersSelectors.getPreprintProviderDetails('osf'),
value: { ...mockProvider, reviewsWorkflow: ProviderReviewsWorkflow.PostModeration },
},
{
selector: PreprintSelectors.getPreprint,
value: { ...mockPreprint, isLatestVersion: false, reviewsState: ReviewsState.Accepted },
},
],
});

expect(component.editButtonVisible()).toBe(true);
});

it('should hide edit button for previous version when user does not have write access', () => {
setup({
selectorOverrides: [
{
selector: PreprintSelectors.getPreprint,
value: { ...mockPreprint, isLatestVersion: false, reviewsState: ReviewsState.Accepted },
},
{ selector: PreprintSelectors.hasWriteAccess, value: false },
],
});

expect(component.editButtonVisible()).toBe(false);
});

it('should hide edit button for withdrawn previous version', () => {
setup({
selectorOverrides: [
{
selector: PreprintSelectors.getPreprint,
value: {
...mockPreprint,
isLatestVersion: false,
reviewsState: ReviewsState.Withdrawn,
dateWithdrawn: '2024-01-01',
},
},
],
});

expect(component.editButtonVisible()).toBe(false);
});

it('should show edit button for pending premoderation preprint', () => {
setup({
selectorOverrides: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
}
}

return false;
return !preprintIsRejected;
});

editButtonLabel = computed(() => {
Expand Down
Loading