|
|
@ -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()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |