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
Expand Up @@ -19,6 +19,7 @@ describe('MetadataRegistryInfoComponent', () => {
iri: 'https://example.com/registry',
reviewsWorkflow: 'standard',
allowSubmissions: true,
allowUpdates: true,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('RegistryProviderHeroComponent', () => {
iri: '',
reviewsWorkflow: '',
allowSubmissions: false,
allowUpdates: true,
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,20 @@ export class JustificationComponent implements OnDestroy {

private initStepValidation(): void {
effect(() => {
const currentIndex = this.currentStepIndex();
const pages = this.pages();
const revisionData = this.schemaResponseRevisionData();
const stepState = untracked(() => this.stepsState());

if (currentIndex > 0) {
if (this.currentStepIndex() > 0) {
this.actions.updateStepState('0', true, stepState?.[0]?.touched || false);
}

if (pages.length && currentIndex > 0 && revisionData) {
for (let i = 1; i < currentIndex; i++) {
const pageStep = pages[i - 1];
if (this.pages().length && this.currentStepIndex() > 0 && this.schemaResponseRevisionData()) {
for (let i = 1; i < this.currentStepIndex(); i++) {
const pageStep = this.pages()[i - 1];
const isStepInvalid =
pageStep?.questions?.some((question) => {
const questionData = revisionData[question.responseKey!];
const questionData = this.schemaResponseRevisionData()[question.responseKey!];
return question.required && (Array.isArray(questionData) ? !questionData.length : !questionData);
}) || false;
}) ?? false;
this.actions.updateStepState(i.toString(), isStepInvalid, stepState?.[i]?.touched || false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const MOCK_PROVIDER: RegistryProviderDetails = {
iri: 'http://iri.example.com',
reviewsWorkflow: 'pre-moderation',
allowSubmissions: true,
allowUpdates: true,
};

describe('RegistriesProviderSearchComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<p-button
class="w-full"
styleClass="w-full"
(onClick)="updateRegistration.emit(registry()?.id!)"
(onClick)="startUpdateRegistration()"
[label]="'common.buttons.update' | translate"
[loading]="isSubmitting()"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ describe('RegistryRevisionsComponent', () => {
expect(spy).toHaveBeenCalledWith(1);
});

it('should emit updateRegistration with registry id on startUpdateRegistration', () => {
const { component } = setup();
const spy = vi.fn();
component.updateRegistration.subscribe(spy);

component.startUpdateRegistration();

expect(spy).toHaveBeenCalledWith(MOCK_REGISTRY.id);
});

it('should not emit updateRegistration when registry id is missing on startUpdateRegistration', () => {
const { fixture, component } = setup();
const spy = vi.fn();
component.updateRegistration.subscribe(spy);
fixture.componentRef.setInput('registry', { ...MOCK_REGISTRY, id: '' });
fixture.detectChanges();

component.startUpdateRegistration();

expect(spy).not.toHaveBeenCalled();
});

it('should emit continueUpdate on continueUpdateHandler', () => {
const { component } = setup();
const spy = vi.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ export class RegistryRevisionsComponent {
});
});

startUpdateRegistration() {
const registryId = this.registry()?.id;

if (!registryId) {
return;
}

this.updateRegistration.emit(registryId);
}

emitOpenRevision(index: number) {
this.openRevision.emit(index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h4 class="mb-1">
(continueUpdate)="onContinueUpdateRegistration()"
[isModeration]="isModeration()"
[isSubmitting]="isSchemaResponsesLoading()"
[canEdit]="hasAdminAccess()"
[canEdit]="canUpdate()"
>
</osf-registry-revisions>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SchemaResponse } from '@osf/shared/models/registration/schema-response.
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ViewOnlyLinkHelperService } from '@osf/shared/services/view-only-link-helper.service';
import { RegistrationProviderSelectors } from '@osf/shared/stores/registration-provider';

import { MOCK_REGISTRATION_OVERVIEW_MODEL } from '@testing/mocks/registration-overview-model.mock';
import { createMockSchemaResponse } from '@testing/mocks/schema-response.mock';
Expand All @@ -28,7 +29,7 @@ import { CustomDialogServiceMock } from '@testing/providers/custom-dialog-provid
import { LoaderServiceMock, provideLoaderServiceMock } from '@testing/providers/loader-service.mock';
import { ActivatedRouteMockBuilder } from '@testing/providers/route-provider.mock';
import { RouterMockBuilder } from '@testing/providers/router-provider.mock';
import { provideMockStore } from '@testing/providers/store-provider.mock';
import { BaseSetupOverrides, mergeSignalOverrides, provideMockStore } from '@testing/providers/store-provider.mock';
import { ToastServiceMock } from '@testing/providers/toast-provider.mock';
import { ViewOnlyLinkHelperMock } from '@testing/providers/view-only-link-helper.mock';

Expand All @@ -44,7 +45,7 @@ import { RegistrySelectors } from '../../store/registry';

import { RegistryOverviewComponent } from './registry-overview.component';

interface SetupOverrides {
interface SetupOverrides extends BaseSetupOverrides {
registry?: RegistrationOverviewModel | null;
schemaResponses?: SchemaResponse[];
queryParams?: Record<string, string>;
Expand All @@ -67,6 +68,19 @@ function setup(overrides: SetupOverrides = {}) {
const mockLoaderService = new LoaderServiceMock();
const mockToastService = ToastServiceMock.simple();
const mockViewOnlyHelper = ViewOnlyLinkHelperMock.simple(overrides.hasViewOnly);
const signalDefaults = [
{ selector: RegistrySelectors.getRegistry, value: registry },
{ selector: RegistrySelectors.isRegistryLoading, value: false },
{ selector: RegistrySelectors.isRegistryAnonymous, value: false },
{ selector: RegistrySelectors.getSchemaResponses, value: schemaResponses },
{ selector: RegistrySelectors.isSchemaResponsesLoading, value: false },
{ selector: RegistrySelectors.getSchemaBlocks, value: [] },
{ selector: RegistrySelectors.isSchemaBlocksLoading, value: false },
{ selector: RegistrySelectors.areReviewActionsLoading, value: false },
{ selector: RegistrySelectors.getSchemaResponse, value: schemaResponses[0] ?? null },
{ selector: RegistrySelectors.hasAdminAccess, value: false },
{ selector: RegistrationProviderSelectors.allowUpdates, value: false },
];

TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -94,18 +108,7 @@ function setup(overrides: SetupOverrides = {}) {
MockProvider(ToastService, mockToastService),
MockProvider(ViewOnlyLinkHelperService, mockViewOnlyHelper),
provideMockStore({
signals: [
{ selector: RegistrySelectors.getRegistry, value: registry },
{ selector: RegistrySelectors.isRegistryLoading, value: false },
{ selector: RegistrySelectors.isRegistryAnonymous, value: false },
{ selector: RegistrySelectors.getSchemaResponses, value: schemaResponses },
{ selector: RegistrySelectors.isSchemaResponsesLoading, value: false },
{ selector: RegistrySelectors.getSchemaBlocks, value: [] },
{ selector: RegistrySelectors.isSchemaBlocksLoading, value: false },
{ selector: RegistrySelectors.areReviewActionsLoading, value: false },
{ selector: RegistrySelectors.getSchemaResponse, value: schemaResponses[0] ?? null },
{ selector: RegistrySelectors.hasAdminAccess, value: false },
],
signals: mergeSignalOverrides(signalDefaults, overrides.selectorOverrides),
}),
],
});
Expand Down Expand Up @@ -181,6 +184,30 @@ describe('RegistryOverviewComponent', () => {
expect(component.canMakeDecision()).toBe(false);
});

it('should compute canUpdate as true when admin access and provider updates are allowed', () => {
const { component } = setup({
registry: MOCK_REGISTRATION_OVERVIEW_MODEL,
selectorOverrides: [
{ selector: RegistrySelectors.hasAdminAccess, value: true },
{ selector: RegistrationProviderSelectors.allowUpdates, value: true },
],
});

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

it('should compute canUpdate as false when provider updates are not allowed', () => {
const { component } = setup({
registry: MOCK_REGISTRATION_OVERVIEW_MODEL,
selectorOverrides: [
{ selector: RegistrySelectors.hasAdminAccess, value: true },
{ selector: RegistrationProviderSelectors.allowUpdates, value: false },
],
});

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

it('should compute isInitialState from reviewsState', () => {
const { component } = setup({
registry: { ...MOCK_REGISTRATION_OVERVIEW_MODEL, reviewsState: RegistrationReviewStates.Initial },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { ToastService } from '@osf/shared/services/toast.service';
import { ViewOnlyLinkHelperService } from '@osf/shared/services/view-only-link-helper.service';
import { GetBookmarksCollectionId } from '@osf/shared/stores/bookmarks';
import { GetBibliographicContributors } from '@osf/shared/stores/contributors';
import { RegistrationProviderSelectors } from '@osf/shared/stores/registration-provider';

import { ArchivingMessageComponent } from '../../components/archiving-message/archiving-message.component';
import { RegistrationOverviewToolbarComponent } from '../../components/registration-overview-toolbar/registration-overview-toolbar.component';
Expand Down Expand Up @@ -98,6 +99,7 @@ export class RegistryOverviewComponent implements OnInit, OnDestroy {
readonly areReviewActionsLoading = select(RegistrySelectors.areReviewActionsLoading);
readonly currentRevision = select(RegistrySelectors.getSchemaResponse);
readonly hasAdminAccess = select(RegistrySelectors.hasAdminAccess);
readonly allowUpdates = select(RegistrationProviderSelectors.allowUpdates);

readonly selectedRevisionIndex = signal(0);

Expand All @@ -112,6 +114,8 @@ export class RegistryOverviewComponent implements OnInit, OnDestroy {
() => !this.registry()?.archiving && !this.registry()?.withdrawn && this.isModeration()
);

readonly canUpdate = computed(() => this.hasAdminAccess() && this.allowUpdates());

isRootRegistration = computed(() => {
const rootId = this.registry()?.rootParentId;
return !rootId || rootId === this.registry()?.id;
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 @@ -35,6 +35,7 @@ export class RegistrationProviderMapper {
iri: response.links.iri,
reviewsWorkflow: response.attributes.reviews_workflow,
allowSubmissions: response.attributes.allow_submissions,
allowUpdates: response.attributes.allow_updates,
};
}
}
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 @@ -11,4 +11,5 @@ export interface RegistryProviderDetails {
iri: string;
reviewsWorkflow: string;
allowSubmissions: boolean;
allowUpdates: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ export class RegistrationProviderSelectors {
static isBrandedProviderLoading(state: RegistrationProviderStateModel) {
return state.currentBrandedProvider.isLoading;
}

@Selector([RegistrationProviderState])
static allowUpdates(state: RegistrationProviderStateModel) {
return state.currentBrandedProvider.data?.allowUpdates ?? false;
}
}
Loading