Skip to content
Merged
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
@@ -1,7 +1,7 @@
<div class="p-4 flex flex-column gap-2">
<h2>{{ 'files.detail.keywords.title' | translate }}</h2>

@if (!hasViewOnly()) {
@if (!hasViewOnly() && hasWriteAccess()) {
<div class="flex align-items-center gap-2">
<input pInputText class="flex-1" [formControl]="keywordControl" />

Expand All @@ -19,10 +19,12 @@ <h2>{{ 'files.detail.keywords.title' | translate }}</h2>
@for (tag of tags(); track $index) {
<p-chip
[label]="tag"
[removeIcon]="hasViewOnly() ? '' : 'fas fa-close'"
[removable]="!hasViewOnly()"
[removeIcon]="hasViewOnly() || !hasWriteAccess() ? '' : 'fas fa-close'"
[removable]="!hasViewOnly() && hasWriteAccess()"
(onRemove)="deleteTag(tag)"
></p-chip>
} @empty {
<p>{{ 'project.overview.metadata.noTags' | translate }}</p>
}
</div>
} @else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class FileKeywordsComponent {
readonly tags = select(FilesSelectors.getFileTags);
readonly isTagsLoading = select(FilesSelectors.isFileTagsLoading);
readonly file = select(FilesSelectors.getOpenedFile);
readonly hasWriteAccess = select(FilesSelectors.hasWriteAccess);
readonly hasViewOnly = computed(() => hasViewOnlyParam(this.router));

keywordControl = new FormControl('', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ <h2>{{ 'files.detail.fileMetadata.title' | translate }}</h2>
(onClick)="downloadFileMetadata()"
/>

<p-button
severity="secondary"
(onClick)="openEditFileMetadataDialog()"
[label]="'files.detail.fileMetadata.edit' | translate"
></p-button>
@if (hasWriteAccess()) {
<p-button
severity="secondary"
(onClick)="openEditFileMetadataDialog()"
[label]="'files.detail.fileMetadata.edit' | translate"
></p-button>
}
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class FileMetadataComponent {

fileMetadata = select(FilesSelectors.getFileCustomMetadata);
isLoading = select(FilesSelectors.isFileMetadataLoading);
hasWriteAccess = select(FilesSelectors.hasWriteAccess);
hasViewOnly = computed(() => hasViewOnlyParam(this.router));

readonly languageCodes = languageCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,7 @@ export class MoveFileDialogComponent {
first = 0;
filesLink = '';

readonly isFolderSame = computed(() => {
const stack = this.foldersStack();
if (stack.length === 0) {
return true;
}
const parentFolder = stack[stack.length - 1];
return this.currentFolder()?.id === parentFolder?.id;
});
readonly isFolderSame = computed(() => this.currentFolder()?.id === this.config.data.fileFolderId);

get isMoveAction() {
return this.config.data.action === 'move';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</p-menu>
</div>
}
@if (file() && !isAnonymous() && !hasViewOnly()) {
@if (showDeleteButton()) {
<p-button
severity="danger"
[ariaLabel]="'common.buttons.delete' | translate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class FileDetailComponent {
isResourceContributorsLoading = select(FilesSelectors.isResourceContributorsLoading);
fileRevisions = select(FilesSelectors.getFileRevisions);
isFileRevisionLoading = select(FilesSelectors.isFileRevisionsLoading);
hasWriteAccess = select(FilesSelectors.hasWriteAccess);

hasViewOnly = computed(() => hasViewOnlyParam(this.router));

Expand Down Expand Up @@ -187,6 +188,8 @@ export class FileDetailComponent {
selectedCedarTemplate = signal<CedarMetadataDataTemplateJsonApi | null>(null);
cedarFormReadonly = signal<boolean>(true);

showDeleteButton = computed(() => this.hasWriteAccess() && this.file() && !this.isAnonymous() && !this.hasViewOnly());

private readonly metaTagsData = computed(() => {
if (this.isFileLoading() || this.isFileCustomMetadataLoading() || this.isResourceContributorsLoading()) {
return null;
Expand Down Expand Up @@ -304,7 +307,7 @@ export class FileDetailComponent {

copyToClipboard(embedHtml: string): void {
this.clipboard.copy(embedHtml);
this.toastService.showSuccess('files.toast.detail.copiedToClipboard');
this.toastService.showSuccess('files.detail.toast.copiedToClipboard');
}

deleteEntry(link: string): void {
Expand All @@ -313,9 +316,7 @@ export class FileDetailComponent {
this.actions
.deleteEntry(this.resourceId, link)
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.router.navigate([redirectUrl]);
});
.subscribe(() => this.router.navigate([redirectUrl]));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/app/features/files/store/files.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Selector } from '@ngxs/store';

import { SupportedFeature } from '@osf/shared/enums';
import { SupportedFeature, UserPermissions } from '@osf/shared/enums';
import { ConfiguredAddonModel, ContributorModel, OsfFile, ResourceMetadata } from '@shared/models';

import { OsfFileCustomMetadata, OsfFileRevision } from '../models';
Expand Down Expand Up @@ -143,4 +143,9 @@ export class FilesSelectors {
static getStorageSupportedFeatures(state: FilesStateModel): Record<string, SupportedFeature[]> {
return state.storageSupportedFeatures || {};
}

@Selector([FilesState])
static hasWriteAccess(state: FilesStateModel): boolean {
return state.openedFile.data?.target?.currentUserPermissions?.includes(UserPermissions.Write) || false;
}
}
3 changes: 2 additions & 1 deletion src/app/shared/components/files-tree/files-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
action: action,
storageName: this.storage()?.label,
foldersStack: [...this.foldersStack],
fileFolderId: this.currentFolder()?.id,
},
})
.onClose.subscribe((foldersStack) => {
Expand All @@ -390,7 +391,7 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {

copyToClipboard(embedHtml: string): void {
this.clipboard.copy(embedHtml);
this.toastService.showSuccess('files.toast.detail.copiedToClipboard');
this.toastService.showSuccess('files.detail.toast.copiedToClipboard');
}

async dropNode(event: TreeNodeDropEvent) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/models/resource-metadata.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Identifier } from '@shared/models/identifiers/identifier.model';
import { Identifier } from './identifiers';

export interface ResourceMetadata {
title: string;
Expand Down
Loading