Skip to content

Commit

Permalink
perm check in api
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Feb 7, 2022
1 parent 7af35b1 commit f129283
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Api {
this.videoExtensions = options.videoExtensions;
this.documentExtensions = options.documentExtensions;
this.mediaVersion = (new Date().getTime()).toString();
this.canCreate = options.canCreate || false;
this.canEdit = options.canEdit || false;
this.canDelete = options.canDelete || false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const toggleBrowserItemSelect = (context, payload) => {
* @param payload object with the new folder name and its parent directory
*/
export const createDirectory = (context, payload) => {
if (!api.canCreate) {
return;
}
context.commit(types.SET_IS_LOADING, true);
api.createDirectory(payload.name, payload.parent)
.then((folder) => {
Expand All @@ -150,6 +153,9 @@ export const createDirectory = (context, payload) => {
* @param payload object with the new folder name and its parent directory
*/
export const uploadFile = (context, payload) => {
if (!api.canEdit) {
return;
}
context.commit(types.SET_IS_LOADING, true);
api.upload(payload.name, payload.parent, payload.content, payload.override || false)
.then((file) => {
Expand All @@ -175,6 +181,9 @@ export const uploadFile = (context, payload) => {
* @param payload object: the old and the new path
*/
export const renameItem = (context, payload) => {
if (!api.canEdit) {
return;
}
context.commit(types.SET_IS_LOADING, true);
api.rename(payload.path, payload.newPath)
.then((item) => {
Expand All @@ -199,11 +208,17 @@ export const renameItem = (context, payload) => {
* @param context
*/
export const deleteSelectedItems = (context) => {
if (!api.canDelete) {
return;
}
context.commit(types.SET_IS_LOADING, true);
// Get the selected items from the store
const { selectedItems } = context.state;
if (selectedItems.length > 0) {
selectedItems.forEach((item) => {
if (typeof item.canDelete !== 'undefined' && item.canDelete === false) {
return;
}
api.delete(item.path)
.then(() => {
context.commit(types.DELETE_SUCCESS, item);
Expand Down

0 comments on commit f129283

Please sign in to comment.