Skip to content

Commit 0113de1

Browse files
authored
[ENG-9042] Each registries, preprints, and collections provider sets a default license in admin. (#796)
- Ticket: https://openscience.atlassian.net/browse/ENG-9042 - Feature flag: n/a ## Purpose Each registries, preprints, and collections provider sets a default license in admin. ## Summary of Changes These should be preselected on all registration drafts on that provider, and the user can change them from there. All provider types need a serialized default license.
1 parent cd31559 commit 0113de1

11 files changed

Lines changed: 47 additions & 13 deletions

File tree

src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h2 class="mb-2">{{ 'shared.license.title' | translate }}</h2>
1616
</p>
1717
<osf-license
1818
[licenses]="licenses()"
19-
[selectedLicenseId]="createdPreprint()?.licenseId"
19+
[selectedLicenseId]="createdPreprint()?.licenseId || defaultLicense()"
2020
[selectedLicenseOptions]="createdPreprint()?.licenseOptions"
2121
[fullWidthSelect]="true"
2222
(createLicense)="createLicense($event)"

src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { InputText } from 'primeng/inputtext';
99
import { Message } from 'primeng/message';
1010
import { Tooltip } from 'primeng/tooltip';
1111

12-
import { ChangeDetectionStrategy, Component, inject, input, OnInit, output } from '@angular/core';
12+
import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output, signal } from '@angular/core';
1313
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
1414

1515
import { formInputLimits } from '@osf/features/preprints/constants';
@@ -81,6 +81,24 @@ export class PreprintsMetadataStepComponent implements OnInit {
8181
provider = input.required<PreprintProviderDetails | undefined>();
8282
nextClicked = output<void>();
8383
backClicked = output<void>();
84+
defaultLicense = signal<string | undefined>(undefined);
85+
86+
constructor() {
87+
effect(() => {
88+
const licenses = this.licenses();
89+
const preprint = this.createdPreprint();
90+
91+
if (licenses.length && preprint && !preprint.licenseId && preprint.defaultLicenseId) {
92+
const defaultLicense = licenses.find((license) => license.id === preprint?.defaultLicenseId);
93+
if (defaultLicense) {
94+
this.defaultLicense.set(defaultLicense.id);
95+
if (!defaultLicense.requiredFields.length) {
96+
this.actions.saveLicense(defaultLicense.id);
97+
}
98+
}
99+
}
100+
});
101+
}
84102

85103
ngOnInit() {
86104
this.actions.fetchLicenses();

src/app/features/preprints/mappers/preprints.mapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class PreprintsMapper {
8383
articleDoiLink: response.links.doi,
8484
embeddedLicense: null,
8585
providerId: response.relationships?.provider?.data?.id,
86+
defaultLicenseId: response.attributes.default_license_id,
8687
};
8788
}
8889

src/app/features/preprints/models/preprint-json-api.models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface PreprintAttributesJsonApi {
3737
why_no_prereg: StringOrNull;
3838
prereg_links: string[];
3939
prereg_link_info: PreregLinkInfo | null;
40+
default_license_id: string;
4041
}
4142

4243
export interface PreprintRelationshipsJsonApi {

src/app/features/preprints/models/preprint.models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface PreprintModel {
4747
articleDoiLink?: string;
4848
identifiers?: IdentifierModel[];
4949
providerId: string;
50+
defaultLicenseId?: string;
5051
}
5152

5253
export interface PreprintFilesLinks {

src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export class PreprintStepperState {
8787
if (action.payload.isPublished) {
8888
ctx.setState(patch({ hasBeenSubmitted: true }));
8989
}
90-
9190
ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) }));
9291
}),
9392
catchError((error) => handleSectionError(ctx, 'preprint', error))

src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2 class="mb-2">{{ 'shared.license.title' | translate }}</h2>
1111
<osf-license
1212
[licenses]="licenses()"
1313
[fullWidthSelect]="true"
14-
[selectedLicenseId]="selectedLicense()?.id"
14+
[selectedLicenseId]="selectedLicense()?.id || control().get('id')?.value"
1515
[selectedLicenseOptions]="selectedLicense()?.options"
1616
(createLicense)="createLicense($event)"
1717
(selectLicense)="selectLicense($event)"

src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TranslatePipe } from '@ngx-translate/core';
55
import { Card } from 'primeng/card';
66
import { Message } from 'primeng/message';
77

8-
import { ChangeDetectionStrategy, Component, effect, inject, input, untracked } from '@angular/core';
8+
import { ChangeDetectionStrategy, Component, effect, inject, input } from '@angular/core';
99
import { FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
1010
import { ActivatedRoute } from '@angular/router';
1111

@@ -64,18 +64,29 @@ export class RegistriesLicenseComponent {
6464

6565
effect(() => {
6666
const licenses = this.licenses();
67-
const selectedLicense = untracked(() => this.selectedLicense());
67+
const selectedLicense = this.selectedLicense();
68+
const defaultLicenseId = this.draftRegistration()?.defaultLicenseId;
6869

69-
if (!licenses.length || !selectedLicense) {
70+
if (!licenses.length) {
7071
return;
7172
}
7273

73-
if (!licenses.find((license) => license.id === selectedLicense.id)) {
74-
this.control().patchValue({
75-
id: null,
76-
});
77-
this.control().markAsTouched();
78-
this.control().updateValueAndValidity();
74+
if (
75+
defaultLicenseId &&
76+
(!selectedLicense?.id || !licenses.find((license) => license.id === selectedLicense?.id))
77+
) {
78+
const defaultLicense = licenses.find((license) => license.id === defaultLicenseId);
79+
if (defaultLicense) {
80+
this.control().patchValue({
81+
id: defaultLicense.id,
82+
});
83+
this.control().markAsTouched();
84+
this.control().updateValueAndValidity();
85+
86+
if (!defaultLicense.requiredFields.length) {
87+
this.actions.saveLicense(this.draftId, defaultLicense.id);
88+
}
89+
}
7990
}
8091
});
8192
}

src/app/shared/mappers/registration/registration.mapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class RegistrationMapper {
4747
},
4848
providerId: response.relationships.provider?.data?.id || '',
4949
hasProject: !!response.attributes.has_project,
50+
defaultLicenseId: response.attributes?.default_license_id,
5051
components: [],
5152
currentUserPermissions: response.attributes.current_user_permissions,
5253
};

src/app/shared/models/registration/draft-registration.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface DraftRegistrationModel {
1818
branchedFrom?: Partial<ProjectModel>;
1919
providerId: string;
2020
hasProject: boolean;
21+
defaultLicenseId?: string;
2122
components: Partial<ProjectModel>[];
2223
currentUserPermissions: UserPermissions[];
2324
}

0 commit comments

Comments
 (0)