Skip to content

Commit ded1b50

Browse files
authored
fix(view-only-link): fixed file detail page (#625)
* fix(view-only-link): fixed file detail page * fix(social): updated linkedin
1 parent 367c543 commit ded1b50

5 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/app/core/guards/is-file.guard.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export const isFileGuard: CanMatchFn = (route: Route, segments: UrlSegment[]) =>
1414

1515
const id = segments[0]?.path;
1616
const isMetadataPath = segments[1]?.path === 'metadata';
17+
18+
const urlObj = new URL(window.location.href);
19+
const viewOnly = urlObj.searchParams.get('view_only');
20+
const extras = viewOnly ? { queryParams: { view_only: viewOnly } } : {};
21+
1722
if (!id) {
1823
return false;
1924
}
@@ -25,7 +30,7 @@ export const isFileGuard: CanMatchFn = (route: Route, segments: UrlSegment[]) =>
2530
return true;
2631
}
2732
if (currentResource.parentId) {
28-
router.navigate(['/', currentResource.parentId, 'files', id], { queryParamsHandling: 'preserve' });
33+
router.navigate(['/', currentResource.parentId, 'files', id], extras);
2934
return false;
3035
}
3136
}
@@ -45,7 +50,7 @@ export const isFileGuard: CanMatchFn = (route: Route, segments: UrlSegment[]) =>
4550
return true;
4651
}
4752
if (resource.parentId) {
48-
router.navigate(['/', resource.parentId, 'files', id], { queryParamsHandling: 'preserve' });
53+
router.navigate(['/', resource.parentId, 'files', id], extras);
4954
return false;
5055
}
5156
}

src/app/features/files/components/file-resource-metadata/file-resource-metadata.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ <h4>{{ 'files.detail.resourceMetadata.fields.dateModified' | translate }}</h4>
9898
@if (isResourceContributorsLoading()) {
9999
<p-skeleton width="100%" height="4rem" />
100100
} @else {
101-
@if (contributors().length && !hasViewOnly()) {
101+
@if (hasViewOnly() || contributors().length) {
102102
<div class="flex flex-column gap-2">
103103
<h4>{{ 'common.labels.contributors' | translate }}</h4>
104104

105-
<osf-contributors-list [contributors]="contributors()"></osf-contributors-list>
105+
<osf-contributors-list [contributors]="contributors()" [anonymous]="hasViewOnly()"></osf-contributors-list>
106106
</div>
107107
}
108108
}

src/app/features/metadata/services/metadata.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ export class MetadataService {
102102
'page[size]': 20,
103103
};
104104

105+
// [NS] TODO: Check if it can be simplified
105106
let cedarUrl = `${this.apiUrl}/${this.urlMap.get(resourceType)}/${resourceId}/cedar_metadata_records/`;
107+
106108
if (url) {
107-
cedarUrl = `${url}cedar_metadata_records/`;
109+
cedarUrl = this.getMetadataUrl(url);
108110
}
109111

110112
return this.jsonApiService.get<CedarMetadataRecordJsonApi>(cedarUrl, params);
@@ -212,4 +214,16 @@ export class MetadataService {
212214

213215
return params;
214216
}
217+
218+
private getMetadataUrl(url: string): string {
219+
const parsedUrl = new URL(url);
220+
221+
if (!parsedUrl.pathname.endsWith('/')) {
222+
parsedUrl.pathname += '/';
223+
}
224+
225+
parsedUrl.pathname += 'cedar_metadata_records/';
226+
227+
return parsedUrl.toString();
228+
}
215229
}

src/app/shared/constants/social-links.const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const SOCIAL_LINKS: SocialLinksModel[] = [
1212
{
1313
id: 2,
1414
label: 'settings.profileSettings.social.labels.linkedIn',
15-
address: 'https://linkedin.com/',
15+
address: 'https://linkedin.com/in/',
1616
placeholder: 'in/userID, profie/view?profileID, or pub/pubID',
1717
key: 'linkedIn',
1818
icon: 'linkedin.svg',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class ContributorsMapper {
2020
}
2121

2222
static getContributor(response: ContributorDataJsonApi): ContributorModel {
23-
const userEmbed = response.embeds.users;
23+
const userEmbed = response.embeds?.users;
24+
2425
const errorMeta = userEmbed?.errors && userEmbed.errors.length > 0 ? userEmbed.errors[0]?.meta : null;
2526
const userData = userEmbed?.data;
2627

0 commit comments

Comments
 (0)