@samitouri / QOSami-HFS / commits / 5419cc30

fix: 'delete' command was offered for virtual folders, and possibly other entries that cannot be deleted

Massimo Melina committed Nov 4, 2024 at 17:19 UTC 5419cc30d1da708f02699b7d3a4de14cf3faef04
3 files changed +3 -3
frontend/src/state.ts
+1 -1
@@ -156,7 +156,7 @@ export class DirEntry implements StringifyProps<ServerDirEntry> {
156 return this.p?.includes('A') || state.props?.can_archive && !this.p?.includes('a')
157 }
158 canDelete() {
159 - return state.props?.can_delete || this.p?.includes('d')
159 + return this.p?.includes('D') || state.props?.can_delete && !this.p?.includes('d')
160 }
161 canSelect() {
162 if (this.url) return false
src/api.get_file_list.ts
+1 -1
@@ -122,7 +122,7 @@ export const get_file_list: ApiHandler = async ({ uri='/', offset, limit, search
122 const pr = node.can_read === WHO_NO_ONE && !(isFolder && filesInsideCould()) ? 'r'
123 : !hasPermission(node, 'can_read', ctx) ? 'R'
124 : ''
125 - const pd = !can_delete && hasPermission(node, 'can_delete', ctx) ? 'd' : ''
125 + const pd = Boolean(can_delete) === hasPermission(node, 'can_delete', ctx) ? '' : can_delete ? 'd' : 'D'
126 const pa = Boolean(can_archive) === hasPermission(node, 'can_archive', ctx) ? '' : can_archive ? 'a' : 'A'
127 return {
128 n: name + (isFolder ? '/' : ''),
src/vfs.ts
+1 -1
@@ -217,7 +217,7 @@ export function statusCodeForMissingPerm(node: VfsNode, perm: keyof VfsPerms, ct
217 return ret
218
219 function getCode() {
220 - if (!node.source && perm === 'can_upload') // Upload possible only if we know where to store. First check node.source because is supposedly faster.
220 + if (!node.source && (perm === 'can_upload' || perm === 'can_delete')) // Upload possible only if we know where to store. First check node.source because is supposedly faster.
221 return HTTP_FORBIDDEN
222 // calculate value of permission resolving references to other permissions, avoiding infinite loop
223 let who: Who | undefined