diff --git a/src/pages/share/containers/Share/Detail/AccessRule/actions/Create.jsx b/src/pages/share/containers/Share/Detail/AccessRule/actions/Create.jsx index 8f41c431..70014b83 100644 --- a/src/pages/share/containers/Share/Detail/AccessRule/actions/Create.jsx +++ b/src/pages/share/containers/Share/Detail/AccessRule/actions/Create.jsx @@ -17,7 +17,8 @@ import { ModalAction } from 'containers/Action'; import globalShareAccessRuleStore from 'stores/manila/share-access-rule'; import { keyValueValidator } from 'pages/share/containers/ShareType/actions/Create'; import KeyValueInput from 'components/FormItem/KeyValueInput'; -import { updateAddSelectValueToObj } from 'utils/index'; +import { updateAddSelectValueToObj, getOptions } from 'utils/index'; +import { shareAccessLevel, shareAccessType } from 'resources/manila/share'; export const metadataFormItem = { name: 'metadata', @@ -55,37 +56,11 @@ export class Create extends ModalAction { static allowed = () => Promise.resolve(true); get typeOptions() { - return [ - { - value: 'ip', - label: t('IP'), - }, - { - value: 'cert', - label: t('Cert'), - }, - { - value: 'user', - label: t('User'), - }, - { - value: 'cephx', - label: t('Cephx'), - }, - ]; + return getOptions(shareAccessType); } get levelOptions() { - return [ - { - value: 'rw', - label: t('Read and write'), - }, - { - value: 'ro', - label: t('Read only'), - }, - ]; + return getOptions(shareAccessLevel); } get defaultValue() { diff --git a/src/pages/share/containers/Share/Detail/AccessRule/index.jsx b/src/pages/share/containers/Share/Detail/AccessRule/index.jsx index a448fe73..72a0753f 100644 --- a/src/pages/share/containers/Share/Detail/AccessRule/index.jsx +++ b/src/pages/share/containers/Share/Detail/AccessRule/index.jsx @@ -15,7 +15,8 @@ import { observer, inject } from 'mobx-react'; import Base from 'containers/List'; import globalShareAccessRuleStore from 'stores/manila/share-access-rule'; -import { shareAccessRuleState } from 'resources/manila/share'; +import { shareAccessRuleState, shareAccessLevel } from 'resources/manila/share'; +import { emptyActionConfig } from 'utils/constants'; import actionConfigs from './actions'; export class ShareAccessRule extends Base { @@ -32,9 +33,14 @@ export class ShareAccessRule extends Base { } get actionConfigs() { - return this.isAdminPage - ? actionConfigs.actionConfigsAdmin - : actionConfigs.actionConfigs; + if (this.isAdminPage) { + return actionConfigs.actionConfigsAdmin; + } + const { detail: { isMine } = {} } = this.props; + if (isMine) { + return actionConfigs.actionConfigs; + } + return emptyActionConfig; } getColumns = () => [ @@ -53,6 +59,7 @@ export class ShareAccessRule extends Base { { title: t('Access Level'), dataIndex: 'access_level', + render: (value) => shareAccessLevel[value] || value, }, { title: t('State'), diff --git a/src/pages/share/containers/Share/Detail/Metadata/index.jsx b/src/pages/share/containers/Share/Detail/Metadata/index.jsx index 1f874e77..92a4a507 100644 --- a/src/pages/share/containers/Share/Detail/Metadata/index.jsx +++ b/src/pages/share/containers/Share/Detail/Metadata/index.jsx @@ -15,6 +15,7 @@ import { observer, inject } from 'mobx-react'; import Base from 'containers/List'; import { ShareMetadataStore } from 'stores/manila/share-metadata'; +import { emptyActionConfig } from 'utils/constants'; import actionConfigs from './actions'; export class Metadata extends Base { @@ -42,9 +43,14 @@ export class Metadata extends Base { ]; get actionConfigs() { - return this.isAdminPage - ? actionConfigs.actionConfigsAdmin - : actionConfigs.actionConfigs; + if (this.isAdminPage) { + return actionConfigs.actionConfigsAdmin; + } + const { detail: { isMine } = {} } = this.props; + if (isMine) { + return actionConfigs.actionConfigs; + } + return emptyActionConfig; } get searchFilters() { diff --git a/src/pages/share/containers/Share/Detail/index.jsx b/src/pages/share/containers/Share/Detail/index.jsx index cb22cc54..727c4c64 100644 --- a/src/pages/share/containers/Share/Detail/index.jsx +++ b/src/pages/share/containers/Share/Detail/index.jsx @@ -60,11 +60,6 @@ export class Detail extends Base { dataIndex: 'created_at', valueRender: 'toLocalTime', }, - { - title: t('Updated'), - dataIndex: 'updated_at', - valueRender: 'toLocalTime', - }, ]; } diff --git a/src/pages/share/containers/Share/actions/Create.jsx b/src/pages/share/containers/Share/actions/Create.jsx index ebe22a80..9a856f79 100644 --- a/src/pages/share/containers/Share/actions/Create.jsx +++ b/src/pages/share/containers/Share/actions/Create.jsx @@ -38,6 +38,7 @@ import { cloneDeep } from 'lodash'; import { idNameColumn } from 'utils/table'; import { extraFormItem } from 'pages/share/containers/ShareType/actions/Create'; import { updateAddSelectValueToObj, getOptions } from 'utils/index'; +import { checkPolicyRule } from 'resources/skyline/policy'; export class Create extends FormAction { static id = 'create'; @@ -135,6 +136,14 @@ export class Create extends FormAction { return [idNameColumn, ...rest]; } + get shareProtocolOptions() { + return getOptions(shareProtocol); + } + + checkShowPublic() { + return checkPolicyRule('manila:share:create_public_share'); + } + get formItems() { const { showNetworks = false, shareGroups = [] } = this.state; const minSize = 1; @@ -175,7 +184,7 @@ export class Create extends FormAction { label: t('Share Protocol'), type: 'select', required: true, - options: getOptions(shareProtocol), + options: this.shareProtocolOptions, }, { name: 'size', @@ -183,7 +192,7 @@ export class Create extends FormAction { type: 'slider-input', max: this.maxSize, min: minSize, - description: `${minSize}GB-${this.maxSize}GB`, + description: `${minSize}GiB-${this.maxSize}GiB`, required: this.quotaIsLimit, display: this.quotaIsLimit, }, @@ -201,6 +210,7 @@ export class Create extends FormAction { type: 'check', content: t('Public'), tip: t('If set then all tenants will be able to see this share.'), + display: this.checkShowPublic(), }, { name: 'shareType', @@ -246,14 +256,24 @@ export class Create extends FormAction { } onSubmit = (values) => { - const { shareType, shareNetwork, shareGroup, project, metadata, ...rest } = - values; + const { + shareType, + shareNetwork, + shareGroup, + project, + metadata, + is_public, + ...rest + } = values; const { showNetworks = false } = this.state; const body = { ...rest, share_type: shareType.selectedRowKeys[0], metadata: updateAddSelectValueToObj(metadata), }; + if (this.checkShowPublic() && is_public) { + body.is_public = is_public; + } const { selectedRowKeys: networkKeys = [] } = shareNetwork || {}; const { selectedRowKeys: groupKeys = [] } = shareGroup || {}; if (showNetworks && networkKeys.length) { diff --git a/src/pages/share/containers/Share/actions/Delete.jsx b/src/pages/share/containers/Share/actions/Delete.jsx index 7e9376d4..f40fafca 100644 --- a/src/pages/share/containers/Share/actions/Delete.jsx +++ b/src/pages/share/containers/Share/actions/Delete.jsx @@ -38,5 +38,9 @@ export default class Delete extends ConfirmAction { policy = 'manila:share:delete'; + allowedCheckFunc = (item) => { + return this.isAdminPage || item.isMine; + }; + onSubmit = (data) => globalShareStore.delete(data); } diff --git a/src/pages/share/containers/Share/actions/Edit.jsx b/src/pages/share/containers/Share/actions/Edit.jsx index 94206ff7..1b081131 100644 --- a/src/pages/share/containers/Share/actions/Edit.jsx +++ b/src/pages/share/containers/Share/actions/Edit.jsx @@ -15,6 +15,7 @@ import { inject, observer } from 'mobx-react'; import { ModalAction } from 'containers/Action'; import globalShareStore from 'stores/manila/share'; +import { checkPolicyRule } from 'resources/skyline/policy'; export class Edit extends ModalAction { static id = 'edit'; @@ -33,7 +34,11 @@ export class Edit extends ModalAction { static policy = 'manila:share:update'; - static allowed = () => Promise.resolve(true); + static allowed = (item) => Promise.resolve(item.isMine); + + checkShowPublic() { + return checkPolicyRule('manila:share:set_public_share'); + } get formItems() { return [ @@ -54,6 +59,7 @@ export class Edit extends ModalAction { type: 'check', content: t('Public'), tip: t('If set then all tenants will be able to see this share.'), + display: this.checkShowPublic(), }, ]; } @@ -64,7 +70,14 @@ export class Edit extends ModalAction { onSubmit = (values) => { const { id } = this.item; - return this.store.update(id, values); + const { is_public, ...rest } = values; + const body = { + ...rest, + }; + if (this.checkShowPublic()) { + body.is_public = is_public; + } + return this.store.update(id, body); }; } diff --git a/src/pages/share/containers/Share/actions/Extend.jsx b/src/pages/share/containers/Share/actions/Extend.jsx index a0061d5f..bd93fd21 100644 --- a/src/pages/share/containers/Share/actions/Extend.jsx +++ b/src/pages/share/containers/Share/actions/Extend.jsx @@ -36,7 +36,7 @@ export class ExtendShare extends ModalAction { static policy = 'manila:share:extend'; - static allowed = () => Promise.resolve(true); + static allowed = (item) => Promise.resolve(item.isMine); get tips() { return t('After the share is expanded, the share cannot be reduced.'); diff --git a/src/pages/share/containers/Share/actions/ManageAccessRule.jsx b/src/pages/share/containers/Share/actions/ManageAccessRule.jsx index dd97b452..3b1681f3 100644 --- a/src/pages/share/containers/Share/actions/ManageAccessRule.jsx +++ b/src/pages/share/containers/Share/actions/ManageAccessRule.jsx @@ -38,7 +38,7 @@ export class ManageAccessRule extends FormAction { static policy = 'manila:share_access_rule:index'; - static allowed = () => Promise.resolve(true); + static allowed = (item) => Promise.resolve(item.isMine); } export default inject('rootStore')(observer(ManageAccessRule)); diff --git a/src/pages/share/containers/Share/actions/ManageMetadata.jsx b/src/pages/share/containers/Share/actions/ManageMetadata.jsx index 75633ae5..bd5f82e7 100644 --- a/src/pages/share/containers/Share/actions/ManageMetadata.jsx +++ b/src/pages/share/containers/Share/actions/ManageMetadata.jsx @@ -38,7 +38,7 @@ export class ManageMetadata extends FormAction { static policy = 'manila:share:update_share_metadata'; - static allowed = () => Promise.resolve(true); + static allowed = (item) => Promise.resolve(item.isMine); } export default inject('rootStore')(observer(ManageMetadata)); diff --git a/src/pages/share/containers/Share/index.jsx b/src/pages/share/containers/Share/index.jsx index e2137de7..7e4d43a1 100644 --- a/src/pages/share/containers/Share/index.jsx +++ b/src/pages/share/containers/Share/index.jsx @@ -20,7 +20,7 @@ import actionConfigs from './actions'; export class Share extends Base { init() { - this.store = globalShareStore; + this.store = this.inDetailPage ? new ShareStore() : globalShareStore; this.downloadStore = new ShareStore(); } @@ -56,6 +56,14 @@ export class Share extends Base { return this.inDetailPage && pathname.includes('share-server'); } + get isSortByBackend() { + return true; + } + + get defaultSortKey() { + return 'created_at'; + } + updateFetchParamsByPage = (params) => { const { id, ...rest } = params; const newParams = { ...rest }; @@ -92,20 +100,24 @@ export class Share extends Base { dataIndex: 'project_name', isHideable: true, hidden: !this.isAdminPage, + sortKey: 'project_id', }, { title: t('Description'), dataIndex: 'description', isHideable: true, + sorter: false, }, { title: t('Availability Zone'), dataIndex: 'availability_zone', + sorter: false, }, { title: t('Share Type'), dataIndex: 'share_type_name', render: (value, record) => value || record.share_type, + sortKey: 'share_type_id', }, { title: t('Size'), @@ -122,6 +134,7 @@ export class Share extends Base { dataIndex: 'is_public', isHideable: true, valueRender: 'yesNo', + sorter: false, }, { title: t('Status'), @@ -155,6 +168,7 @@ export class Share extends Base { }); return link; }, + // sorter: false, }, { title: t('Created At'), diff --git a/src/pages/share/containers/ShareGroup/Detail/index.jsx b/src/pages/share/containers/ShareGroup/Detail/index.jsx index 1f8cb2ac..d10780f8 100644 --- a/src/pages/share/containers/ShareGroup/Detail/index.jsx +++ b/src/pages/share/containers/ShareGroup/Detail/index.jsx @@ -59,11 +59,6 @@ export class Detail extends Base { dataIndex: 'created_at', valueRender: 'toLocalTime', }, - { - title: t('Updated'), - dataIndex: 'updated_at', - valueRender: 'toLocalTime', - }, ]; } diff --git a/src/pages/share/containers/ShareGroup/index.jsx b/src/pages/share/containers/ShareGroup/index.jsx index 398234d3..869da756 100644 --- a/src/pages/share/containers/ShareGroup/index.jsx +++ b/src/pages/share/containers/ShareGroup/index.jsx @@ -41,6 +41,14 @@ export class ShareGroup extends Base { return true; } + get isSortByBackend() { + return true; + } + + get defaultSortKey() { + return 'created_at'; + } + get actionConfigs() { return this.isAdminPage ? actionConfigs.actionConfigsAdmin diff --git a/src/resources/manila/share-group.js b/src/resources/manila/share-group.js index 529a6eb2..d5ba601c 100644 --- a/src/resources/manila/share-group.js +++ b/src/resources/manila/share-group.js @@ -17,15 +17,18 @@ export const getShareGroupColumns = (self) => { dataIndex: 'project_name', isHideable: true, hidden: !self.isAdminPage, + sortKey: 'project_id', }, { title: t('Description'), dataIndex: 'description', isHideable: true, + sorter: false, }, { title: t('Availability Zone'), dataIndex: 'availability_zone', + sorter: false, }, { title: t('Share Network'), diff --git a/src/resources/manila/share.js b/src/resources/manila/share.js index 9a8b4b2f..bce1f73d 100644 --- a/src/resources/manila/share.js +++ b/src/resources/manila/share.js @@ -60,3 +60,15 @@ export const shareAccessRuleState = { denying: t('Denying'), applying: t('Applying'), }; + +export const shareAccessLevel = { + rw: t('Read and write'), + ro: t('Read only'), +}; + +export const shareAccessType = { + ip: t('IP'), + cert: t('Cert'), + user: t('User'), + cephx: t('Cephx'), +}; diff --git a/src/stores/manila/share-group.js b/src/stores/manila/share-group.js index 946b1153..518a45aa 100644 --- a/src/stores/manila/share-group.js +++ b/src/stores/manila/share-group.js @@ -37,6 +37,13 @@ export class ShareGroupStore extends Base { }; } + updateParamsSortPage = (params, sortKey, sortOrder) => { + if (sortKey && sortOrder) { + params.sort_key = sortKey; + params.sort_dir = sortOrder === 'descend' ? 'desc' : 'asc'; + } + }; + async detailDidFetch(item, all_projects) { const { share_network_id, share_group_type_id, share_types } = item; const shareGroupType = await new ShareGroupTypeStore().fetchDetail({ diff --git a/src/stores/manila/share.js b/src/stores/manila/share.js index 93b29917..76bc41d6 100644 --- a/src/stores/manila/share.js +++ b/src/stores/manila/share.js @@ -73,10 +73,28 @@ export class ShareStore extends Base { all_tenants: all_projects ? 1 : 0, offset: marker, limit, + is_public: true, }; }; } + get mapper() { + return (data) => { + const { project_id } = data; + return { + ...data, + isMine: project_id === this.currentProjectId, + }; + }; + } + + updateParamsSortPage = (params, sortKey, sortOrder) => { + if (sortKey && sortOrder) { + params.sort_key = sortKey; + params.sort_dir = sortOrder === 'descend' ? 'desc' : 'asc'; + } + }; + @action async fetchAvailableZones() { const { availability_zones: zones = [] } = await this.zoneClient.list();