Browse Source

delete folder

pull/6727/head
Kornel Javor 1 year ago
parent
commit
59fad3a1bd
2 changed files with 62 additions and 36 deletions
  1. 87
      server/graph/resolvers/asset.js
  2. 11
      server/graph/schemas/asset.graphql

87
server/graph/resolvers/asset.js

@ -33,7 +33,7 @@ module.exports = {
},
async allFolders(obj, args, context) {
const results = await WIKI.models.assetFolders.query();
return results.filter(folder => {
return results.filter(folder => {
const path = folder.slug;
return WIKI.auth.checkAccess(context.req.user, ['read:assets'], { path });
});
@ -80,35 +80,35 @@ module.exports = {
},
// new one
async createFolderWithId(obj, args, context) {
try {
const folderSlug = sanitize(args.slug).toLowerCase();
const parentFolderId = args.parentFolderId === 0 ? null : args.parentFolderId;
const result = await WIKI.models.assetFolders.query().where({
parentId: parentFolderId,
slug: folderSlug
}).first();
if (!result) {
const newFolder = await WIKI.models.assetFolders.query().insert({
slug: folderSlug,
name: folderSlug,
parentId: parentFolderId
});
return {
folderId: newFolder.id,
parentId: newFolder.parentId,
response: graphHelper.generateSuccess('Asset Folder has been created successfully.')
};
} else {
throw new WIKI.Error.AssetFolderExists();
}
} catch (err) {
try {
const folderSlug = sanitize(args.slug).toLowerCase();
const parentFolderId = args.parentFolderId === 0 ? null : args.parentFolderId;
const result = await WIKI.models.assetFolders.query().where({
parentId: parentFolderId,
slug: folderSlug
}).first();
if (!result) {
const newFolder = await WIKI.models.assetFolders.query().insert({
slug: folderSlug,
name: folderSlug,
parentId: parentFolderId
});
return {
folderId: null,
response: graphHelper.generateError(err)
folderId: newFolder.id,
parentId: newFolder.parentId,
response: graphHelper.generateSuccess('Asset Folder has been created successfully.')
};
} else {
throw new WIKI.Error.AssetFolderExists();
}
},
} catch (err) {
return {
folderId: null,
response: graphHelper.generateError(err)
};
}
},
/**
* Rename an Asset
*/
@ -239,11 +239,32 @@ module.exports = {
} catch (err) {
return graphHelper.generateError(err)
}
},
async deleteFolder(obj, args, context) {
try {
const folderId = args.id;
// Check if the folder exists
const folder = await WIKI.models.assetFolders.query().findById(folderId);
if (!folder) {
throw new WIKI.Error.AssetFolderInvalid();
}
// Check permissions
const folderPath = folder.slug;
if (!WIKI.auth.checkAccess(context.req.user, ['manage:assets'], { path: folderPath })) {
throw new WIKI.Error.AssetFolderDeleteForbidden();
}
// Delete the folder (must be empty)
await WIKI.models.assetFolders.query().deleteById(folderId);
return {
responseResult: graphHelper.generateSuccess('Asset Folder has been deleted successfully.')
};
} catch (err) {
return graphHelper.generateError(err);
}
}
}
// File: {
// folder(fl) {
// return fl.getFolder()
// }
// }
}
}

11
server/graph/schemas/asset.graphql

@ -42,8 +42,8 @@ createFolder(
parentFolderId: Int!
slug: String!
name: String
): FolderCreationResponse @auth(requires: ["manage:system", "write:assets"])
): FolderCreationResponse @auth(requires: ["manage:system", "write:assets"])
# DefaultResponse @auth(requires: ["manage:system", "write:assets"])
renameAsset(
@ -55,6 +55,11 @@ createFolder(
id: Int!
): DefaultResponse @auth(requires: ["manage:system", "manage:assets"])
deleteFolder(
id: Int!
): DefaultResponse @auth(requires: ["manage:system", "manage:assets"])
flushTempUploads: DefaultResponse @auth(requires: ["manage:system"])
}
@ -89,7 +94,7 @@ enum AssetKind {
ALL
}
type FolderCreationResponse {
type FolderCreationResponse {
folderId: Int
response: DefaultResponse
parentId: Int

Loading…
Cancel
Save