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
4 changes: 4 additions & 0 deletions src/app/features/files/constants/file-provider.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export const FileProvider = {
WebDav: 'webdav',
S3: 's3',
GitHub: 'github',
Bitbucket: 'bitbucket',
GitLab: 'gitlab',
Figshare: 'figshare',
Dataverse: 'dataverse',
};
4 changes: 3 additions & 1 deletion src/app/features/files/pages/files/files.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<p-button icon="fas fa-info-circle blue-icon" severity="secondary" text (onClick)="showInfoDialog()"></p-button>

@if (canEdit() && !hasViewOnly()) {
@if (canUploadFiles() && !hasViewOnly()) {
<p-button
[disabled]="isButtonDisabled()"
outlined
Expand Down Expand Up @@ -128,8 +128,10 @@
[actions]="filesTreeActions"
[viewOnly]="!canEdit()"
[viewOnlyDownloadable]="isViewOnlyDownloadable()"
[supportUpload]="canUploadFiles()"
[resourceId]="resourceId()"
[provider]="provider()"
[allowedMenuActions]="allowedMenuActions()"
(folderIsOpening)="folderIsOpening($event)"
(entryFileClicked)="navigateToFile($event)"
(uploadFilesConfirmed)="uploadFiles($event)"
Expand Down
40 changes: 38 additions & 2 deletions src/app/features/files/pages/files/files.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
GetConfiguredStorageAddons,
GetFiles,
GetRootFolders,
GetStorageSupportedFeatures,
RenameEntry,
ResetState,
SetCurrentFolder,
Expand All @@ -58,7 +59,7 @@ import {
SetSort,
} from '@osf/features/files/store';
import { ALL_SORT_OPTIONS, FILE_SIZE_LIMIT } from '@osf/shared/constants';
import { ResourceType, UserPermissions } from '@osf/shared/enums';
import { FileMenuType, ResourceType, SupportedFeature, UserPermissions } from '@osf/shared/enums';
import { hasViewOnlyParam, IS_MEDIUM } from '@osf/shared/helpers';
import { CurrentResourceSelectors, GetResourceDetails } from '@osf/shared/stores';
import {
Expand Down Expand Up @@ -136,6 +137,7 @@ export class FilesComponent {
setCurrentProvider: SetCurrentProvider,
resetState: ResetState,
getResourceDetails: GetResourceDetails,
getStorageSupportedFeatures: GetStorageSupportedFeatures,
});

readonly files = select(FilesSelectors.getFiles);
Expand All @@ -149,6 +151,7 @@ export class FilesComponent {
readonly isRootFoldersLoading = select(FilesSelectors.isRootFoldersLoading);
readonly configuredStorageAddons = select(FilesSelectors.getConfiguredStorageAddons);
readonly isConfiguredStorageAddonsLoading = select(FilesSelectors.isConfiguredStorageAddonsLoading);
readonly supportedFeatures = select(FilesSelectors.getStorageSupportedFeatures);

isMedium = toSignal(inject(IS_MEDIUM));

Expand Down Expand Up @@ -179,6 +182,12 @@ export class FilesComponent {
[ResourceType.Registration, 'registrations'],
]);

readonly allowedMenuActions = computed(() => {
const provider = this.provider();
const supportedFeatures = this.supportedFeatures()[provider] || [];
return this.mapMenuActions(supportedFeatures);
});

readonly rootFoldersOptions = computed(() => {
const rootFolders = this.rootFolders();
const addons = this.configuredStorageAddons();
Expand Down Expand Up @@ -206,7 +215,13 @@ export class FilesComponent {
return !details.isRegistration && hasAdminOrWrite;
});

readonly isViewOnlyDownloadable = computed(() => this.resourceType() === ResourceType.Registration);
readonly isViewOnlyDownloadable = computed(
() => this.allowedMenuActions()[FileMenuType.Download] && this.resourceType() === ResourceType.Registration
);

canUploadFiles = computed(
() => this.supportedFeatures()[this.provider()]?.includes(SupportedFeature.AddUpdateFiles) && this.canEdit()
);

isButtonDisabled = computed(() => this.fileIsUploading() || this.isFilesLoading());

Expand Down Expand Up @@ -256,12 +271,16 @@ export class FilesComponent {
const currentRootFolder = this.currentRootFolder();
if (currentRootFolder) {
const provider = currentRootFolder.folder?.provider;
const storageId = currentRootFolder.folder?.id;
// [NM TODO] Check if other providers allow revisions
this.allowRevisions = provider === FileProvider.OsfStorage;
this.isGoogleDrive.set(provider === FileProvider.GoogleDrive);
if (this.isGoogleDrive()) {
this.setGoogleAccountId();
}
if (storageId) {
this.actions.getStorageSupportedFeatures(storageId, provider);
}
this.actions.setCurrentProvider(provider ?? FileProvider.OsfStorage);
this.actions.setCurrentFolder(currentRootFolder.folder);
}
Expand Down Expand Up @@ -511,6 +530,23 @@ export class FilesComponent {
}
}

private mapMenuActions(supportedFeatures: SupportedFeature[]): Record<FileMenuType, boolean> {
return {
[FileMenuType.Download]: supportedFeatures.includes(SupportedFeature.DownloadAsZip),
[FileMenuType.Rename]: supportedFeatures.includes(SupportedFeature.AddUpdateFiles),
[FileMenuType.Delete]: supportedFeatures.includes(SupportedFeature.DeleteFiles),
[FileMenuType.Move]:
supportedFeatures.includes(SupportedFeature.CopyInto) &&
supportedFeatures.includes(SupportedFeature.DeleteFiles) &&
supportedFeatures.includes(SupportedFeature.AddUpdateFiles),
[FileMenuType.Embed]: true,
[FileMenuType.Share]: true,
[FileMenuType.Copy]:
supportedFeatures.includes(SupportedFeature.CopyInto) &&
supportedFeatures.includes(SupportedFeature.AddUpdateFiles),
};
}

openGoogleFilePicker(): void {
this.googleFilePickerComponent()?.createPicker();
this.updateFilesList();
Expand Down
9 changes: 9 additions & 0 deletions src/app/features/files/store/files.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ export class GetConfiguredStorageAddons {
constructor(public resourceUri: string) {}
}

export class GetStorageSupportedFeatures {
static readonly type = '[Files] Get Storage Supported Features';

constructor(
public storageId: string,
public providerName: string
) {}
}

export class ResetState {
static readonly type = '[Files] Reset State';
}
11 changes: 11 additions & 0 deletions src/app/features/files/store/files.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SupportedFeature } from '@osf/shared/enums';
import { ContributorModel, OsfFile, ResourceMetadata } from '@shared/models';
import { ConfiguredAddonModel } from '@shared/models/addons';
import { AsyncStateModel, AsyncStateWithTotalCount } from '@shared/models/store';
Expand All @@ -22,6 +23,7 @@ export interface FilesStateModel {
rootFolders: AsyncStateModel<OsfFile[] | null>;
configuredStorageAddons: AsyncStateModel<ConfiguredAddonModel[] | null>;
isAnonymous: boolean;
storageSupportedFeatures: Record<string, SupportedFeature[]>;
}

export const FILES_STATE_DEFAULTS: FilesStateModel = {
Expand Down Expand Up @@ -83,4 +85,13 @@ export const FILES_STATE_DEFAULTS: FilesStateModel = {
error: null,
},
isAnonymous: false,
storageSupportedFeatures: {
[FileProvider.OsfStorage]: [
SupportedFeature.AddUpdateFiles,
SupportedFeature.DeleteFiles,
SupportedFeature.DownloadAsZip,
SupportedFeature.FileVersions,
SupportedFeature.CopyInto,
],
},
};
6 changes: 6 additions & 0 deletions src/app/features/files/store/files.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Selector } from '@ngxs/store';

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

import { OsfFileCustomMetadata, OsfFileRevision } from '../models';
Expand Down Expand Up @@ -137,4 +138,9 @@ export class FilesSelectors {
static isConfiguredStorageAddonsLoading(state: FilesStateModel): boolean {
return state.configuredStorageAddons.isLoading;
}

@Selector([FilesState])
static getStorageSupportedFeatures(state: FilesStateModel): Record<string, SupportedFeature[]> {
return state.storageSupportedFeatures || {};
}
}
25 changes: 24 additions & 1 deletion src/app/features/files/store/files.state.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Action, State, StateContext } from '@ngxs/store';

import { catchError, finalize, forkJoin, tap } from 'rxjs';
import { catchError, EMPTY, finalize, forkJoin, tap } from 'rxjs';

import { inject, Injectable } from '@angular/core';

import { SupportedFeature } from '@osf/shared/enums';
import { handleSectionError } from '@osf/shared/helpers';
import { FilesService, ToastService } from '@osf/shared/services';

Expand All @@ -22,6 +23,7 @@ import {
GetMoveFileFiles,
GetRootFolderFiles,
GetRootFolders,
GetStorageSupportedFeatures,
RenameEntry,
ResetState,
SetCurrentFolder,
Expand Down Expand Up @@ -303,6 +305,27 @@ export class FilesState {
);
}

@Action(GetStorageSupportedFeatures)
getStorageSupportedFeatures(ctx: StateContext<FilesStateModel>, action: GetStorageSupportedFeatures) {
const state = ctx.getState();
if (state.storageSupportedFeatures[action.providerName]) {
return EMPTY;
}
return this.filesService.getExternalStorageService(action.storageId).pipe(
tap((addon) => {
const providerName = addon.externalServiceName;
const currentFeatures = state.storageSupportedFeatures;
ctx.patchState({
storageSupportedFeatures: {
...currentFeatures,
[providerName]: (addon.supportedFeatures ?? []) as SupportedFeature[],
},
});
}),
catchError((error) => handleSectionError(ctx, 'storageSupportedFeatures', error))
);
}

@Action(ResetState)
resetState(ctx: StateContext<FilesStateModel>) {
ctx.patchState(FILES_STATE_DEFAULTS);
Expand Down
23 changes: 17 additions & 6 deletions src/app/shared/components/file-menu/file-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Component, computed, inject, input, output, viewChild } from '@angular/
import { Router } from '@angular/router';

import { FileMenuType } from '@osf/shared/enums';
import { FileMenuAction, FileMenuData } from '@osf/shared/models';
import { FileMenuAction, FileMenuData, FileMenuFlags } from '@osf/shared/models';
import { MenuManagerService } from '@osf/shared/services';
import { hasViewOnlyParam } from '@shared/helpers';

Expand All @@ -21,9 +21,10 @@ import { hasViewOnlyParam } from '@shared/helpers';
export class FileMenuComponent {
private router = inject(Router);
private menuManager = inject(MenuManagerService);
isFolder = input<boolean>(false);
allowedActions = input<FileMenuFlags>({} as FileMenuFlags);
menu = viewChild.required<TieredMenu>('menu');
action = output<FileMenuAction>();
isFolder = input<boolean>(false);

hasViewOnly = computed(() => {
return hasViewOnlyParam(this.router);
Expand Down Expand Up @@ -108,8 +109,16 @@ export class FileMenuComponent {

menuItems = computed(() => {
if (this.hasViewOnly()) {
const allowedActionsForFiles = [FileMenuType.Download, FileMenuType.Embed, FileMenuType.Share, FileMenuType.Copy];
const allowedActionsForFolders = [FileMenuType.Download, FileMenuType.Copy];
const allowedActionsForFiles = [
FileMenuType.Download,
FileMenuType.Embed,
FileMenuType.Share,
FileMenuType.Copy,
].filter((action) => this.allowedActions()[action]);

const allowedActionsForFolders = [FileMenuType.Download, FileMenuType.Copy].filter(
(action) => this.allowedActions()[action]
);

const allowedActions = this.isFolder() ? allowedActionsForFolders : allowedActionsForFiles;

Expand All @@ -128,9 +137,11 @@ export class FileMenuComponent {

if (this.isFolder()) {
const disallowedActions = [FileMenuType.Share, FileMenuType.Embed];
return this.allMenuItems.filter((item) => !disallowedActions.includes(item.id as FileMenuType));
return this.allMenuItems.filter(
(item) => !disallowedActions.includes(item.id as FileMenuType) && this.allowedActions()[item.id as FileMenuType]
);
}
return this.allMenuItems;
return this.allMenuItems.filter((item) => this.allowedActions()[item.id as FileMenuType]);
});

onMenuToggle(event: Event): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div #dropZoneContainer class="drop-zone-container flex flex-1">
@if (!hasViewOnly()) {
@if (!hasViewOnly() && supportUpload()) {
<div
class="drop-zone"
[class.active]="isDragOver()"
Expand Down Expand Up @@ -27,8 +27,8 @@
styleClass="w-full md:w-[30rem]"
class="tree-table"
(onNodeDrop)="dropNode($event)"
[draggableNodes]="!viewOnly()"
[droppableNodes]="!viewOnly()"
[draggableNodes]="!viewOnly() && supportUpload()"
[droppableNodes]="!viewOnly() && supportUpload()"
draggableScope="self"
droppableScope="self"
>
Expand Down Expand Up @@ -76,6 +76,7 @@
<osf-file-menu
(action)="onFileMenuAction($event, file)"
[isFolder]="file.kind === 'folder'"
[allowedActions]="allowedMenuActions()"
osfStopPropagation
>
</osf-file-menu>
Expand Down Expand Up @@ -106,7 +107,7 @@
}
@if (!files().length) {
<div class="empty-state-container p-4">
@if (hasViewOnly()) {
@if (hasViewOnly() || !supportUpload()) {
<h3 class="font-normal mb-4 text-no-transform">{{ 'files.emptyState' | translate }}</h3>
} @else {
<div class="drop-text">
Expand Down
4 changes: 3 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 @@ -36,7 +36,7 @@ import { embedDynamicJs, embedStaticHtml } from '@osf/features/files/constants';
import { StopPropagationDirective } from '@osf/shared/directives';
import { FileMenuType } from '@osf/shared/enums';
import { hasViewOnlyParam } from '@osf/shared/helpers';
import { FileLabelModel, FileMenuAction, FilesTreeActions, OsfFile } from '@osf/shared/models';
import { FileLabelModel, FileMenuAction, FileMenuFlags, FilesTreeActions, OsfFile } from '@osf/shared/models';
import { FileSizePipe } from '@osf/shared/pipes';
import { CustomConfirmationService, FilesService, ToastService } from '@osf/shared/services';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
Expand Down Expand Up @@ -88,6 +88,8 @@ export class FilesTreeComponent implements OnDestroy, AfterViewInit {
viewOnly = input<boolean>(true);
viewOnlyDownloadable = input<boolean>(false);
provider = input<string>();
allowedMenuActions = input<FileMenuFlags>({} as FileMenuFlags);
supportUpload = input<boolean>(true);
isDragOver = signal(false);
hasViewOnly = computed(() => hasViewOnlyParam(this.router) || this.viewOnly());

Expand Down
11 changes: 11 additions & 0 deletions src/app/shared/enums/addon-supported-features.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum SupportedFeature {
AddUpdateFiles = 'ADD_UPDATE_FILES',
CopyInto = 'COPY_INTO',
DeleteFiles = 'DELETE_FILES',
DownloadAsZip = 'DOWNLOAD_AS_ZIP',
FileVersions = 'FILE_VERSIONS',
Forking = 'FORKING',
Logs = 'LOGS',
Permissions = 'PERMISSIONS',
Registering = 'REGISTERING',
}
1 change: 1 addition & 0 deletions src/app/shared/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './addon-form-controls.enum';
export * from './addon-service-names.enum';
export * from './addon-supported-features.enum';
export * from './addon-tab.enum';
export * from './addon-type.enum';
export * from './addons-category.enum';
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/models/files/file-menu-action.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export interface FileMenuAction {
export interface FileMenuData {
type: string;
}

export type FileMenuFlags = Record<FileMenuType, boolean>;
10 changes: 10 additions & 0 deletions src/app/shared/services/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
} from '@osf/features/files/models';
import {
AddFileResponse,
AddonGetResponseJsonApi,
AddonModel,
ApiData,
ConfiguredAddonGetResponseJsonApi,
ConfiguredAddonModel,
Expand Down Expand Up @@ -318,4 +320,12 @@ export class FilesService {
})
);
}

getExternalStorageService(serviceId: string): Observable<AddonModel> {
return this.jsonApiService
.get<
JsonApiResponse<AddonGetResponseJsonApi, null>
>(`${this.addonsApiUrl}/configured-storage-addons/${serviceId}/external_storage_service/`)
.pipe(map((response) => AddonMapper.fromResponse(response.data)));
}
}
Loading