mirror of
https://github.com/requarks/wiki.git
synced 2025-02-25 18:55:30 -06:00
Merge e47316cfdc
into 403e98dced
This commit is contained in:
commit
f91abdc60f
@ -31,6 +31,13 @@ module.exports = {
|
||||
kind: a.kind.toUpperCase()
|
||||
}))
|
||||
},
|
||||
async allFolders(obj, args, context) {
|
||||
const results = await WIKI.models.assetFolders.query();
|
||||
return results.filter(folder => {
|
||||
const path = folder.slug;
|
||||
return WIKI.auth.checkAccess(context.req.user, ['read:assets'], { path });
|
||||
});
|
||||
},
|
||||
async folders(obj, args, context) {
|
||||
const results = await WIKI.models.assetFolders.query().where({
|
||||
parentId: args.parentFolderId === 0 ? null : args.parentFolderId
|
||||
@ -71,6 +78,37 @@ module.exports = {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
},
|
||||
// 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) {
|
||||
return {
|
||||
folderId: null,
|
||||
response: graphHelper.generateError(err)
|
||||
};
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Rename an Asset
|
||||
*/
|
||||
@ -201,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()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ type AssetQuery {
|
||||
folders(
|
||||
parentFolderId: Int!
|
||||
): [AssetFolder] @auth(requires: ["manage:system", "read:assets"])
|
||||
|
||||
allFolders: [AssetFolder] @auth(requires: ["manage:system", "read:assets"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@ -30,12 +32,20 @@ type AssetQuery {
|
||||
# -----------------------------------------------
|
||||
|
||||
type AssetMutation {
|
||||
createFolder(
|
||||
createFolder(
|
||||
parentFolderId: Int!
|
||||
slug: String!
|
||||
name: String
|
||||
): DefaultResponse @auth(requires: ["manage:system", "write:assets"])
|
||||
|
||||
createFolderWithId(
|
||||
parentFolderId: Int!
|
||||
slug: String!
|
||||
name: String
|
||||
): FolderCreationResponse @auth(requires: ["manage:system", "write:assets"])
|
||||
|
||||
# DefaultResponse @auth(requires: ["manage:system", "write:assets"])
|
||||
|
||||
renameAsset(
|
||||
id: Int!
|
||||
filename: String!
|
||||
@ -45,6 +55,11 @@ type AssetMutation {
|
||||
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"])
|
||||
}
|
||||
|
||||
@ -70,6 +85,7 @@ type AssetFolder {
|
||||
id: Int!
|
||||
slug: String!
|
||||
name: String
|
||||
parentId: Int
|
||||
}
|
||||
|
||||
enum AssetKind {
|
||||
@ -77,3 +93,9 @@ enum AssetKind {
|
||||
BINARY
|
||||
ALL
|
||||
}
|
||||
|
||||
type FolderCreationResponse {
|
||||
folderId: Int
|
||||
response: DefaultResponse
|
||||
parentId: Int
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user