Skip to content

Commit

Permalink
fix: revoke shared folder permission doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
agatha197 committed Aug 20, 2024
1 parent 2f0ebc8 commit 59d4070
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/components/backend-ai-storage-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1098,29 +1098,46 @@ export default class BackendAiStorageList extends BackendAIPage {
const selectNodeList = this.shadowRoot?.querySelectorAll(
'#modify-permission-dialog mwc-select',
);
const leaveList: Array<{
shared_user_uuid: string;
vfolder: string;
}> = [];
const inputList = Array.prototype.filter
.call(
selectNodeList,
(pulldown, idx) =>
pulldown.value !== (this.invitees as inviteeData[])[idx].perm,
)
.call(selectNodeList, (pulldown, idx) => {
if (pulldown.value === 'kickout') {
leaveList.push({
shared_user_uuid: this.invitees[idx].shared_to.uuid,
vfolder: this.invitees[idx].vfolder_name,
});
return false;
}
return pulldown.value !== (this.invitees as inviteeData[])[idx].perm;
})
.map((pulldown, idx) => ({
perm: pulldown.value === 'kickout' ? null : pulldown.value,
perm: pulldown.value,
user: this.invitees[idx].shared_to.uuid,
vfolder: this.invitees[idx].vfolder_id,
}));
const promiseArray = inputList.map((input) =>
globalThis.backendaiclient.vfolder.modify_invitee_permission(input),
);
Promise.all(promiseArray).then((response: any) => {
if (response.length === 0) {
this.notification.text = _text('data.permission.NoChanges');
} else {
this.notification.text = _text('data.permission.PermissionModified');
}
this.notification.show();
this.modifyPermissionDialog.hide();
});
const leavePromiseArray = leaveList.map((input) =>
globalThis.backendaiclient.vfolder.leave(
input?.shared_user_uuid,
input?.vfolder,
),
);
Promise.all([...promiseArray, ...leavePromiseArray]).then(
(response: any) => {
if (response.length === 0) {
this.notification.text = _text('data.permission.NoChanges');
} else {
this.notification.text = _text('data.permission.PermissionModified');
}
this.notification.show();
this.modifyPermissionDialog.hide();
},
);
}

_isUncontrollableStatus(status: VFolderOperationStatus) {
Expand Down
23 changes: 23 additions & 0 deletions src/lib/backend.ai-client-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,29 @@ class VFolder {
return this.client._wrapWithPromise(rqst);
}


/**
* Leave from shared VFolder.
* @param shared_user_uuid - shared user uuid to leave the shared vfolder
* @param name - Virtual folder name to leave. If no name is given, use name on this VFolder object.
*/
async leave(shared_user_uuid, name=null): Promise<any> {
let body = {};
if (shared_user_uuid) {
body['shared_user_uuid'] = shared_user_uuid;
}
if (name == null) {
name = this.name;
}
let rqst = this.client.newSignedRequest(
'POST',
`${this.urlPrefix}/${name}/leave`,
body,
);
return this.client._wrapWithPromise(rqst);
}


/**
* Get the size quota of a vfolder.
* Only available for some specific file system such as XFS.
Expand Down

0 comments on commit 59d4070

Please sign in to comment.