Skip to content

Commit d347254

Browse files
nsemetsNazar690rrromchIk
authored
Fix/registration permissions (#490)
* fix(permissions): added permissions * fix(updates): updates * feat(metadata): Implemented permissions for metadata page * feat(registry-resource): Implemented permissions for resources page * fix(registration): Implemented permissions * fix(registration): Fixed write user permissions * fix(registration): Fixed permissions for My registrations * fix(registry): updated registry models and mappers * fix(registry): fixed registry status * fix(mapper): fixed registry mapper --------- Co-authored-by: Nazar Semets <[email protected]> Co-authored-by: Roma <[email protected]>
1 parent 7599813 commit d347254

22 files changed

+282
-130
lines changed

src/app/features/registry/components/registry-revisions/registry-revisions.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ export class RegistryRevisionsComponent {
3535

3636
revisions = computed(() => {
3737
let schemaResponses = this.registry()?.schemaResponses || [];
38+
3839
if (this.registryAcceptedUnapproved) {
3940
this.unApprovedRevisionId =
4041
schemaResponses.find((response) => response.reviewsState === RevisionReviewStates.Unapproved)?.id || null;
4142
}
43+
4244
schemaResponses = this.isModeration()
4345
? schemaResponses
4446
: schemaResponses.filter((r) => r.reviewsState === RevisionReviewStates.Approved);

src/app/features/registry/components/registry-statuses/registry-statuses.component.html

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
<p-accordion-content>
88
<div class="flex flex-column pt-4 gap-2">
99
<h3 class="font-normal">{{ 'registry.overview.statuses.' + registry()?.status + '.short' | translate }}</h3>
10-
<p>
11-
{{
12-
'registry.overview.statuses.' + registry()?.status + '.long' | translate: { embargoEndDate: embargoEndDate }
13-
}}
14-
</p>
10+
<div class="flex">
11+
<p>
12+
{{
13+
'registry.overview.statuses.' + registry()?.status + '.long'
14+
| translate: { embargoEndDate: embargoEndDate }
15+
}}
16+
</p>
17+
18+
@if (isAccepted()) {
19+
<a class="font-bold ml-1" [routerLink]="['/', registry()?.associatedProjectId]">
20+
{{ 'registry.overview.statuses.accepted.project' | translate }}</a
21+
>.
22+
}
23+
</div>
24+
1525
@if (canEdit()) {
1626
@if (canWithdraw()) {
1727
<p-button
@@ -21,6 +31,7 @@ <h3 class="font-normal">{{ 'registry.overview.statuses.' + registry()?.status +
2131
styleClass="w-full mt-2"
2232
></p-button>
2333
}
34+
2435
@if (isEmbargo()) {
2536
<p-button
2637
(onClick)="openEndEmbargoDialog()"

src/app/features/registry/components/registry-statuses/registry-statuses.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Button } from 'primeng/button';
77
import { DialogService } from 'primeng/dynamicdialog';
88

99
import { ChangeDetectionStrategy, Component, computed, HostBinding, inject, input } from '@angular/core';
10+
import { RouterLink } from '@angular/router';
1011

1112
import { RegistrationReviewStates, RegistryStatus, RevisionReviewStates } from '@osf/shared/enums';
1213
import { CustomConfirmationService } from '@osf/shared/services';
@@ -17,7 +18,7 @@ import { WithdrawDialogComponent } from '../withdraw-dialog/withdraw-dialog.comp
1718

1819
@Component({
1920
selector: 'osf-registry-statuses',
20-
imports: [Accordion, AccordionContent, AccordionHeader, AccordionPanel, TranslatePipe, Button],
21+
imports: [Accordion, AccordionContent, AccordionHeader, AccordionPanel, TranslatePipe, Button, RouterLink],
2122
templateUrl: './registry-statuses.component.html',
2223
styleUrl: './registry-statuses.component.scss',
2324
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -36,13 +37,12 @@ export class RegistryStatusesComponent {
3637
readonly customConfirmationService = inject(CustomConfirmationService);
3738
readonly actions = createDispatchMap({ makePublic: MakePublic });
3839

39-
canWithdraw = computed(() => {
40-
return this.registry()?.reviewsState === RegistrationReviewStates.Accepted && !this.isModeration();
41-
});
40+
canWithdraw = computed(
41+
() => this.registry()?.reviewsState === RegistrationReviewStates.Accepted && !this.isModeration()
42+
);
4243

43-
isEmbargo = computed(() => {
44-
return this.registry()?.status === RegistryStatus.Embargo;
45-
});
44+
isAccepted = computed(() => this.registry()?.reviewsState === RegistrationReviewStates.Accepted);
45+
isEmbargo = computed(() => this.registry()?.status === RegistryStatus.Embargo);
4646

4747
get embargoEndDate() {
4848
const embargoEndDate = this.registry()?.embargoEndDate;
Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { RegistryOverview, RegistryOverviewJsonApiData } from '@osf/features/registry/models';
2-
import { MapRegistryStatus, ReviewPermissionsMapper } from '@osf/shared/mappers';
3-
import { RegistrationMapper } from '@osf/shared/mappers/registration';
1+
import { IdentifiersMapper, LicensesMapper } from '@osf/shared/mappers';
2+
import { MapRegistryStatus, RegistrationMapper, RegistrationNodeMapper } from '@osf/shared/mappers/registration';
3+
4+
import { RegistryOverview, RegistryOverviewJsonApiData } from '../models';
45

56
export function MapRegistryOverview(data: RegistryOverviewJsonApiData): RegistryOverview | null {
67
return {
@@ -16,16 +17,15 @@ export function MapRegistryOverview(data: RegistryOverviewJsonApiData): Registry
1617
category: data.attributes?.category,
1718
customCitation: data.attributes?.custom_citation,
1819
isFork: data.attributes?.fork,
19-
accessRequestsEnabled: data.attributes?.accessRequestsEnabled,
20+
accessRequestsEnabled: data.attributes?.access_requests_enabled,
2021
nodeLicense: data.attributes.node_license
2122
? {
2223
copyrightHolders: data.attributes.node_license.copyright_holders,
2324
year: data.attributes.node_license.year,
2425
}
2526
: undefined,
26-
license: data.embeds?.license?.data?.attributes,
2727
registrationType: data.attributes?.registration_supplement,
28-
doi: data.attributes?.doi,
28+
doi: data.attributes?.article_doi,
2929
tags: data.attributes?.tags,
3030
contributors: data.embeds?.bibliographic_contributors?.data.map((contributor) => ({
3131
id: contributor?.embeds?.users?.data?.id,
@@ -35,46 +35,47 @@ export function MapRegistryOverview(data: RegistryOverviewJsonApiData): Registry
3535
middleName: contributor?.embeds?.users?.data?.attributes?.middle_names,
3636
type: contributor?.embeds?.users?.data?.type,
3737
})),
38-
identifiers: data.embeds?.identifiers?.data.map((identifier) => ({
39-
id: identifier.id,
40-
type: identifier.type,
41-
value: identifier.attributes.value,
42-
category: identifier.attributes.category,
43-
})),
44-
analyticsKey: data.attributes?.analyticsKey,
38+
identifiers: IdentifiersMapper.fromJsonApi(data.embeds.identifiers),
39+
analyticsKey: data.attributes?.analytics_key,
4540
currentUserCanComment: data.attributes.current_user_can_comment,
4641
currentUserPermissions: data.attributes.current_user_permissions,
4742
currentUserIsContributor: data.attributes.current_user_is_contributor,
4843
currentUserIsContributorOrGroupMember: data.attributes.current_user_is_contributor_or_group_member,
4944
citation: data.relationships?.citation?.data?.id,
50-
wikiEnabled: data.attributes.wikiEnabled,
45+
wikiEnabled: data.attributes.wiki_enabled,
5146
region: data.relationships.region?.data,
5247
hasData: data.attributes.has_data,
5348
hasAnalyticCode: data.attributes.has_analytic_code,
5449
hasMaterials: data.attributes.has_materials,
5550
hasPapers: data.attributes.has_papers,
5651
hasSupplements: data.attributes.has_supplements,
57-
questions: data.attributes.registration_responses,
52+
license: LicensesMapper.fromLicenseDataJsonApi(data.embeds.license.data),
5853
registrationSchemaLink: data.relationships.registration_schema.links.related.href,
5954
associatedProjectId: data.relationships?.registered_from?.data?.id,
6055
schemaResponses: data.embeds?.schema_responses?.data?.map((item) => RegistrationMapper.fromSchemaResponse(item)),
61-
provider: {
62-
id: data.embeds?.provider.data.id,
63-
name: data.embeds?.provider.data.attributes.name,
64-
permissions: data.embeds?.provider.data.attributes.permissions,
65-
},
56+
provider: RegistrationNodeMapper.getRegistrationProviderShortInfo(data.embeds.provider.data),
6657
status: MapRegistryStatus(data.attributes),
6758
revisionStatus: data.attributes.revision_state,
6859
reviewsState: data.attributes.reviews_state,
69-
links: {
70-
files: data?.embeds?.files?.data?.[0]?.relationships?.files?.links?.related?.href,
71-
},
7260
archiving: data.attributes.archiving,
73-
currentUserIsModerator: ReviewPermissionsMapper.fromProviderResponse(data.embeds?.provider.data),
7461
withdrawn: data.attributes.withdrawn || false,
7562
withdrawalJustification: data.attributes.withdrawal_justification,
7663
dateWithdrawn: data.attributes.date_withdrawn || null,
7764
embargoEndDate: data.attributes.embargo_end_date || null,
7865
rootParentId: data.relationships.root?.data?.id,
7966
} as RegistryOverview;
8067
}
68+
69+
export function MapRegistrationOverview(data: RegistryOverviewJsonApiData) {
70+
const registrationAttributes = RegistrationNodeMapper.getRegistrationNodeAttributes(data.id, data.attributes);
71+
const providerInfo = RegistrationNodeMapper.getRegistrationProviderShortInfo(data.embeds.provider.data);
72+
const identifiers = IdentifiersMapper.fromJsonApi(data.embeds.identifiers);
73+
const license = LicensesMapper.fromLicenseDataJsonApi(data.embeds.license.data);
74+
75+
return {
76+
...registrationAttributes,
77+
provider: providerInfo,
78+
identifiers: identifiers,
79+
license: license,
80+
};
81+
}

src/app/features/registry/models/get-registry-overview-json-api.model.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { RegistrationReviewStates, RevisionReviewStates } from '@osf/shared/enums';
22
import {
33
ApiData,
4+
IdentifiersJsonApiData,
45
JsonApiResponseWithMeta,
6+
LicenseDataJsonApi,
57
MetaAnonymousJsonApi,
6-
ProviderDataJsonApi,
8+
RegistrationNodeAttributesJsonApi,
9+
RegistryProviderDetailsJsonApi,
10+
ResponseJsonApi,
711
SchemaResponseDataJsonApi,
812
} from '@osf/shared/models';
913

@@ -14,7 +18,7 @@ export type GetRegistryOverviewJsonApi = JsonApiResponseWithMeta<
1418
>;
1519

1620
export type RegistryOverviewJsonApiData = ApiData<
17-
RegistryOverviewJsonApiAttributes,
21+
RegistrationNodeAttributesJsonApi,
1822
RegistryOverviewJsonApiEmbed,
1923
RegistryOverviewJsonApiRelationships,
2024
null
@@ -87,26 +91,9 @@ export interface RegistryOverviewJsonApiEmbed {
8791
}[];
8892
};
8993
license: {
90-
data: {
91-
id: string;
92-
type: string;
93-
attributes: {
94-
name: string;
95-
text: string;
96-
url: string;
97-
};
98-
};
99-
};
100-
identifiers: {
101-
data: {
102-
id: string;
103-
type: string;
104-
attributes: {
105-
category: string;
106-
value: string;
107-
};
108-
}[];
94+
data: LicenseDataJsonApi;
10995
};
96+
identifiers: ResponseJsonApi<IdentifiersJsonApiData[]>;
11097
schema_responses: {
11198
data: SchemaResponseDataJsonApi[];
11299
};
@@ -124,7 +111,7 @@ export interface RegistryOverviewJsonApiEmbed {
124111
};
125112
}[];
126113
};
127-
provider: { data: ProviderDataJsonApi };
114+
provider: { data: RegistryProviderDetailsJsonApi };
128115
}
129116

130117
export interface RegistryOverviewJsonApiRelationships {

src/app/features/registry/models/registry-overview.models.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { ProjectOverviewContributor } from '@osf/features/project/overview/models';
2-
import { RegistrationQuestions } from '@osf/features/registry/models';
32
import {
3+
Identifier,
44
IdTypeModel,
55
LicenseModel,
66
LicensesOption,
77
MetaAnonymousJsonApi,
88
ProviderShortInfoModel,
9+
RegistrationNodeModel,
10+
RegistrationResponses,
911
SchemaResponse,
1012
SubjectModel,
1113
} from '@osf/shared/models';
@@ -33,12 +35,7 @@ export interface RegistryOverview {
3335
nodeLicense?: LicensesOption;
3436
license?: LicenseModel;
3537
licenseUrl?: string;
36-
identifiers?: {
37-
id: string;
38-
type: string;
39-
category: string;
40-
value: string;
41-
}[];
38+
identifiers?: Identifier[];
4239
analyticsKey: string;
4340
currentUserCanComment: boolean;
4441
currentUserPermissions: UserPermissions[];
@@ -53,25 +50,34 @@ export interface RegistryOverview {
5350
hasMaterials: boolean;
5451
hasPapers: boolean;
5552
hasSupplements: boolean;
56-
questions: RegistrationQuestions;
53+
questions: RegistrationResponses;
5754
registrationSchemaLink: string;
5855
associatedProjectId: string;
5956
schemaResponses: SchemaResponse[];
6057
status: RegistryStatus;
6158
revisionStatus: RevisionReviewStates;
6259
reviewsState?: RegistrationReviewStates;
63-
links: {
64-
files: string;
65-
};
6660
archiving: boolean;
6761
embargoEndDate: string;
68-
currentUserIsModerator: boolean;
6962
withdrawn: boolean;
7063
withdrawalJustification?: string;
7164
dateWithdrawn: string | null;
7265
rootParentId: string | null;
7366
}
7467

68+
export interface RegistrationOverviewModel extends RegistrationNodeModel {
69+
type: string;
70+
registrationSchemaLink: string;
71+
associatedProjectId: string;
72+
citation: string;
73+
provider?: ProviderShortInfoModel;
74+
contributors: ProjectOverviewContributor[];
75+
license?: LicenseModel;
76+
identifiers?: Identifier[];
77+
schemaResponses: SchemaResponse[];
78+
status: RegistryStatus;
79+
}
80+
7581
export interface RegistryOverviewWithMeta {
7682
registry: RegistryOverview | null;
7783
meta?: MetaAnonymousJsonApi;

src/app/features/registry/pages/registry-overview/registry-overview.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ export class RegistryOverviewComponent {
109109
this.areSubjectsLoading()
110110
);
111111

112-
canMakeDecision = computed(() => {
113-
return !this.registry()?.archiving && !this.registry()?.withdrawn && this.isModeration;
114-
});
112+
canMakeDecision = computed(() => !this.registry()?.archiving && !this.registry()?.withdrawn && this.isModeration);
115113

116114
isRootRegistration = computed(() => {
117115
const rootId = this.registry()?.rootParentId;

src/app/features/registry/store/registry-overview/registry-overview.actions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RegistrationQuestions } from '@osf/shared/models';
21
import { ReviewActionPayload } from '@osf/shared/models/review-action';
32

43
export class GetRegistryById {
@@ -16,10 +15,7 @@ export class GetRegistryInstitutions {
1615
export class GetSchemaBlocks {
1716
static readonly type = '[Registry Overview] Get Schema Blocks';
1817

19-
constructor(
20-
public schemaLink: string,
21-
public questions: RegistrationQuestions
22-
) {}
18+
constructor(public schemaLink: string) {}
2319
}
2420

2521
export class WithdrawRegistration {

src/app/features/registry/store/registry-overview/registry-overview.state.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export class RegistryOverviewState {
6666
isAnonymous: response.meta?.anonymous ?? false,
6767
});
6868

69-
if (registryOverview?.registrationSchemaLink && registryOverview?.questions) {
70-
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink, registryOverview.questions));
69+
if (registryOverview?.registrationSchemaLink) {
70+
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink));
7171
}
7272
}),
7373
catchError((error) => handleSectionError(ctx, 'registry', error))
@@ -142,8 +142,8 @@ export class RegistryOverviewState {
142142
},
143143
});
144144

145-
if (registryOverview?.registrationSchemaLink && registryOverview?.questions) {
146-
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink, registryOverview.questions));
145+
if (registryOverview?.registrationSchemaLink) {
146+
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink));
147147
}
148148
}),
149149
catchError((error) => handleSectionError(ctx, 'registry', error))
@@ -169,8 +169,9 @@ export class RegistryOverviewState {
169169
error: null,
170170
},
171171
});
172-
if (registryOverview?.registrationSchemaLink && registryOverview?.questions) {
173-
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink, registryOverview.questions));
172+
173+
if (registryOverview?.registrationSchemaLink) {
174+
ctx.dispatch(new GetSchemaBlocks(registryOverview.registrationSchemaLink));
174175
}
175176
}),
176177
catchError((error) => handleSectionError(ctx, 'registry', error))

src/app/shared/mappers/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ export * from './emails.mapper';
99
export * from './files/files.mapper';
1010
export * from './filters/filter-option.mapper';
1111
export * from './filters/reusable-filter.mapper';
12+
export * from './identifiers.mapper';
1213
export * from './institutions';
1314
export * from './licenses.mapper';
1415
export * from './nodes';
1516
export * from './notification-subscription.mapper';
1617
export * from './registration-provider.mapper';
17-
export * from './registry';
1818
export * from './resource-overview.mappers';
1919
export * from './review-actions.mapper';
20-
export * from './review-permissions.mapper';
2120
export * from './subjects';
2221
export * from './user';
2322
export * from './user-related-counts';

0 commit comments

Comments
 (0)