diff --git a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.html b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.html
index 77e60fe11..3d20423c3 100644
--- a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.html
+++ b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.html
@@ -16,7 +16,7 @@
{{ 'shared.license.title' | translate }}
();
nextClicked = output();
backClicked = output();
+ defaultLicense = signal(undefined);
+
+ constructor() {
+ effect(() => {
+ const licenses = this.licenses();
+ const preprint = this.createdPreprint();
+
+ if (licenses.length && preprint && !preprint.licenseId && preprint.defaultLicenseId) {
+ const defaultLicense = licenses.find((license) => license.id === preprint?.defaultLicenseId);
+ if (defaultLicense) {
+ this.defaultLicense.set(defaultLicense.id);
+ if (!defaultLicense.requiredFields.length) {
+ this.actions.saveLicense(defaultLicense.id);
+ }
+ }
+ }
+ });
+ }
ngOnInit() {
this.actions.fetchLicenses();
diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts
index 51ead14da..feee05b82 100644
--- a/src/app/features/preprints/mappers/preprints.mapper.ts
+++ b/src/app/features/preprints/mappers/preprints.mapper.ts
@@ -82,6 +82,7 @@ export class PreprintsMapper {
articleDoiLink: response.links.doi,
embeddedLicense: null,
providerId: response.relationships?.provider?.data?.id,
+ defaultLicenseId: response.attributes.default_license_id,
};
}
diff --git a/src/app/features/preprints/models/preprint-json-api.models.ts b/src/app/features/preprints/models/preprint-json-api.models.ts
index 9761ef0fa..3fa417f48 100644
--- a/src/app/features/preprints/models/preprint-json-api.models.ts
+++ b/src/app/features/preprints/models/preprint-json-api.models.ts
@@ -37,6 +37,7 @@ export interface PreprintAttributesJsonApi {
why_no_prereg: StringOrNull;
prereg_links: string[];
prereg_link_info: PreregLinkInfo | null;
+ default_license_id: string;
}
export interface PreprintRelationshipsJsonApi {
diff --git a/src/app/features/preprints/models/preprint.models.ts b/src/app/features/preprints/models/preprint.models.ts
index f4ad604b4..5a0c9a3a0 100644
--- a/src/app/features/preprints/models/preprint.models.ts
+++ b/src/app/features/preprints/models/preprint.models.ts
@@ -47,6 +47,7 @@ export interface PreprintModel {
articleDoiLink?: string;
identifiers?: IdentifierModel[];
providerId: string;
+ defaultLicenseId?: string;
}
export interface PreprintFilesLinks {
diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts
index bd43281ba..aac8b9157 100644
--- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts
+++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts
@@ -138,7 +138,6 @@ export class PreprintStepperState {
if (action.payload.isPublished) {
ctx.setState(patch({ hasBeenSubmitted: true }));
}
-
ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) }));
}),
catchError((error) => handleSectionError(ctx, 'preprint', error))
diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html
index da782b1e3..0366f69b3 100644
--- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html
+++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html
@@ -11,7 +11,7 @@ {{ 'shared.license.title' | translate }}
{
const licenses = this.licenses();
- const selectedLicense = untracked(() => this.selectedLicense());
+ const selectedLicense = this.selectedLicense();
+ const defaultLicenseId = this.draftRegistration()?.defaultLicenseId;
- if (!licenses.length || !selectedLicense) {
+ if (!licenses.length) {
return;
}
- if (!licenses.find((license) => license.id === selectedLicense.id)) {
- this.control().patchValue({
- id: null,
- });
- this.control().markAsTouched();
- this.control().updateValueAndValidity();
+ if (
+ defaultLicenseId &&
+ (!selectedLicense?.id || !licenses.find((license) => license.id === selectedLicense?.id))
+ ) {
+ const defaultLicense = licenses.find((license) => license.id === defaultLicenseId);
+ if (defaultLicense) {
+ this.control().patchValue({
+ id: defaultLicense.id,
+ });
+ this.control().markAsTouched();
+ this.control().updateValueAndValidity();
+
+ if (!defaultLicense.requiredFields.length) {
+ this.actions.saveLicense(this.draftId, defaultLicense.id);
+ }
+ }
}
});
}
diff --git a/src/app/shared/mappers/registration/registration.mapper.ts b/src/app/shared/mappers/registration/registration.mapper.ts
index 43040ec85..41fbe6ef4 100644
--- a/src/app/shared/mappers/registration/registration.mapper.ts
+++ b/src/app/shared/mappers/registration/registration.mapper.ts
@@ -47,6 +47,7 @@ export class RegistrationMapper {
},
providerId: response.relationships.provider?.data?.id || '',
hasProject: !!response.attributes.has_project,
+ defaultLicenseId: response.attributes?.default_license_id,
components: [],
currentUserPermissions: response.attributes.current_user_permissions,
};
diff --git a/src/app/shared/models/registration/draft-registration.model.ts b/src/app/shared/models/registration/draft-registration.model.ts
index 4d0230e0d..4a18222ac 100644
--- a/src/app/shared/models/registration/draft-registration.model.ts
+++ b/src/app/shared/models/registration/draft-registration.model.ts
@@ -18,6 +18,7 @@ export interface DraftRegistrationModel {
branchedFrom?: Partial;
providerId: string;
hasProject: boolean;
+ defaultLicenseId?: string;
components: Partial[];
currentUserPermissions: UserPermissions[];
}
diff --git a/src/app/shared/models/registration/registration-json-api.model.ts b/src/app/shared/models/registration/registration-json-api.model.ts
index 1a6d64e12..1e38892af 100644
--- a/src/app/shared/models/registration/registration-json-api.model.ts
+++ b/src/app/shared/models/registration/registration-json-api.model.ts
@@ -39,6 +39,7 @@ export interface DraftRegistrationAttributesJsonApi {
datetime_updated: string;
description: string;
has_project: boolean;
+ default_license_id?: string;
node_license: LicenseRecordJsonApi;
registration_metadata: Record;
registration_responses: Record;