Skip to content

Commit

Permalink
disable new folder when the user does not have write permission
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopagno committed Dec 18, 2024
1 parent 2ddc604 commit 290974f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {
v3ErrorIdentifierOutboundRequestForbidden,
} from 'core-app/features/hal/resources/error-resource';

type Alert = 'none'|'noAccess'|'managedFolderNoAccess'|'managedFolderNotFound';
type Alert = 'none'|'noAccess'|'managedFolderNoAccess'|'managedFolderNotFound'|'cannotCreateFolder';

@Directive()
export abstract class FilePickerBaseModalComponent extends OpModalComponent implements OnInit, OnDestroy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<button
type="button"
class="button spot-action-bar--action"
[disabled]="!canCreateFolder"
(click)="createAndNavigateToFolder()"
>
<span class="spot-icon spot-icon_folder-add op-files-tab--icon op-files-tab--icon_forums"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
alertNoAccess: this.i18n.t('js.storages.files.project_folder_no_access'),
alertNoManagedProjectFolder: this.i18n.t('js.storages.files.managed_project_folder_not_available'),
alertNoAccessToManagedProjectFolder: this.i18n.t('js.storages.files.managed_project_folder_no_access'),
alertCannotCreateFolder: this.i18n.t('js.storages.files.cannot_create_folder'),
content: {
empty: this.i18n.t('js.storages.files.empty_folder'),
emptyHint: this.i18n.t('js.storages.files.empty_folder_location_hint'),
Expand Down Expand Up @@ -102,6 +103,14 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
return this.currentDirectory.permissions.some((value) => value === 'writeable');
}

public get canCreateFolder():boolean {
if (!this.currentDirectory) {
return false;
}

return this.currentDirectory.permissions.some((value) => value === 'writeable');
}

public get alertText():Observable<string> {
return this.showAlert
.pipe(
Expand All @@ -113,6 +122,8 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
return this.text.alertNoAccessToManagedProjectFolder;
case 'managedFolderNotFound':
return this.text.alertNoManagedProjectFolder;
case 'cannotCreateFolder':
return this.text.alertCannotCreateFolder;
case 'none':
return '';
default:
Expand Down Expand Up @@ -183,8 +194,9 @@ export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
name: value,
parent_id: this.currentDirectory.id,
},
).subscribe((newlyCreatedDirectory) => {
this.changeLevel(newlyCreatedDirectory);
).subscribe({
next: (newlyCreatedDirectory) => this.changeLevel(newlyCreatedDirectory),
error: (_) => this.showAlert.next('cannotCreateFolder'),
});
}
}
1 change: 1 addition & 0 deletions modules/storages/config/locales/js-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ en:
newest data, and try again.
managed_project_folder_no_access: >
You have no access yet to the managed project folder. Please wait a bit and try again.
cannot_create_folder: Failed to create folder. Avoid using special characters and symbols.
upload_keep_both: "Keep both"
upload_replace: "Replace"

Expand Down

0 comments on commit 290974f

Please sign in to comment.