Skip to content

Commit

Permalink
fix: vfolder share button has disappeared (#2646)
Browse files Browse the repository at this point in the history
### TL;DR

After #2529, vFodler share button has disappeared.
- restore functionality to retrieve and process allowed vFolder hosts for the current user.
- Removed folder explorer event listener which event are not used.

### What changed?

- Removed `openFolderExplorer` method and its associated event listeners from `BackendAIData` class.
- Restore methods in `BackendAiStorageList` class:
  - `_getCurrentKeypairResourcePolicy`: Fetches the current keypair's resource policy.
  - `_getAllowedVFolderHostsByCurrentUserInfo`: Retrieves and processes allowed vFolder hosts for the current user, considering domain, group, and resource policy permissions.
- Restore `_viewStateChanged` and `connectedCallback` methods to call `_getAllowedVFolderHostsByCurrentUserInfo`.

### How to test?

1. Navigate to the data view in the Backend.AI interface.
2. Verify that folder explorer functionality still works as expected, despite the removal of the explicit event listener.
3. Create a vfolder
4. Verify that the share button in control column is displayed and works as expected.

### Why make this change?

This change improves the efficiency of handling folder explorer actions and provides a more comprehensive way to determine allowed vFolder hosts for the current user. By considering domain, group, and resource policy permissions, the system can now present a more accurate and personalized view of available storage options to each user.
  • Loading branch information
yomybaby committed Aug 20, 2024
1 parent 5758880 commit 2f0ebc8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/components/backend-ai-data-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,38 +825,13 @@ export default class BackendAIData extends BackendAIPage {
});
}

openFolderExplorer = (e) => {
if (e?.detail?.vFolder) {
const activeStorageList =
this._activeTab === 'general'
? this.generalFolderStorageListElement
: this._activeTab === 'model'
? this.modelFolderStorageListElement
: this._activeTab === 'automount'
? this.automountFolderStorageListElement
: this._activeTab === 'data'
? this.dataFolderStorageListElement
: this._activeTab === 'trash-bin'
? this.trashBinFolderStorageListElement
: null;
activeStorageList?._folderExplorer({
item: e?.detail?.vFolder,
});
}
};

connectedCallback(): void {
super.connectedCallback();
document.addEventListener('folderExplorer:open', this.openFolderExplorer);
document.dispatchEvent(new CustomEvent('backend-ai-data-view:connected'));
}

disconnectedCallback(): void {
super.disconnectedCallback();
document.removeEventListener(
'folderExplorer:open',
this.openFolderExplorer,
);
document.dispatchEvent(
new CustomEvent('backend-ai-data-view:disconnected'),
);
Expand Down
50 changes: 50 additions & 0 deletions src/components/backend-ai-storage-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,54 @@ export default class BackendAiStorageList extends BackendAIPage {
);
}

private async _getCurrentKeypairResourcePolicy() {
const accessKey = globalThis.backendaiclient._config.accessKey;
const res = await globalThis.backendaiclient.keypair.info(accessKey, [
'resource_policy',
]);
return res.keypair.resource_policy;
}

async _getAllowedVFolderHostsByCurrentUserInfo() {
const [vhostInfo, currentKeypairResourcePolicy] = await Promise.all([
globalThis.backendaiclient.vfolder.list_hosts(),
this._getCurrentKeypairResourcePolicy(),
]);
const currentDomain = globalThis.backendaiclient._config.domainName;
const currentGroupId = globalThis.backendaiclient.current_group_id();
const mergedData =
await globalThis.backendaiclient.storageproxy.getAllowedVFolderHostsByCurrentUserInfo(
currentDomain,
currentGroupId,
currentKeypairResourcePolicy,
);

const allowedPermissionForDomainsByVolume = JSON.parse(
mergedData?.domain?.allowed_vfolder_hosts || '{}',
);
const allowedPermissionForGroupsByVolume = JSON.parse(
mergedData?.group?.allowed_vfolder_hosts || '{}',
);
const allowedPermissionForResourcePolicyByVolume = JSON.parse(
mergedData?.keypair_resource_policy.allowed_vfolder_hosts || '{}',
);

const _mergeDedupe = (arr) => [...new Set([].concat(...arr))];
this._unionedAllowedPermissionByVolume = Object.assign(
{},
...vhostInfo.allowed.map((volume) => {
return {
[volume]: _mergeDedupe([
allowedPermissionForDomainsByVolume[volume],
allowedPermissionForGroupsByVolume[volume],
allowedPermissionForResourcePolicyByVolume[volume],
]),
};
}),
);
this.folderListGrid.clearCache();
}

_checkFolderSupportDirectoryBasedUsage(host: string) {
if (
!host ||
Expand Down Expand Up @@ -1874,6 +1922,7 @@ export default class BackendAiStorageList extends BackendAIPage {
!globalThis.backendaiclient.supports(
'deprecated-max-quota-scope-in-keypair-resource-policy',
);
this._getAllowedVFolderHostsByCurrentUserInfo();
this._refreshFolderList(false, 'viewStatechanged');
},
true,
Expand All @@ -1892,6 +1941,7 @@ export default class BackendAiStorageList extends BackendAIPage {
!globalThis.backendaiclient.supports(
'deprecated-max-quota-scope-in-keypair-resource-policy',
);
this._getAllowedVFolderHostsByCurrentUserInfo();
this._refreshFolderList(false, 'viewStatechanged');
}
}
Expand Down

0 comments on commit 2f0ebc8

Please sign in to comment.