diff --git a/src/layouts/Base/index.jsx b/src/layouts/Base/index.jsx index ac4dd4c3..4ce195fb 100644 --- a/src/layouts/Base/index.jsx +++ b/src/layouts/Base/index.jsx @@ -95,7 +95,7 @@ export class BaseLayout extends Component { get menu() { const menu = this.filterMenuByHidden(this.originMenu); - const newMenu = this.getMenuByLicense(menu); + const newMenu = this.getMenuAllowed(menu); const filteredMenu = newMenu.filter((it) => { const { hasChildren = true, children } = it; return !hasChildren || (hasChildren && children.length); @@ -105,7 +105,7 @@ export class BaseLayout extends Component { get menuAll() { // include hide menu - return this.getMenuByLicense(this.originMenu); + return this.getMenuAllowed(this.originMenu); } getRouteName(routeName) { @@ -128,34 +128,9 @@ export class BaseLayout extends Component { return newMenu; }; - checkLicenseKey = (key) => this.rootStore.checkLicense(key); - checkItemEndpoints = (key) => this.rootStore.checkEndpoint(key); - updateMenuItemByAllowed = (menuItem) => { - const { licenseKey, policy, endpoints, children = [], ...rest } = menuItem; - if (licenseKey && !this.checkLicenseKey(licenseKey)) { - return null; - } - if (policy && !checkItemPolicy({ policy })) { - return null; - } - if (endpoints && !this.checkItemEndpoints(endpoints)) { - return null; - } - if (children.length === 0) { - return menuItem; - } - const newChildren = children - .map((it) => this.updateMenuItemByAllowed(it)) - .filter((it) => !!it); - return { - ...rest, - children: newChildren, - }; - }; - - getMenuByLicense = (menu) => { + getMenuAllowed = (menu) => { // update menu according to license addons const newMenu = []; menu.forEach((it) => { @@ -225,6 +200,26 @@ export class BaseLayout extends Component { this.rootStore.clearNoticeCount(); }; + updateMenuItemByAllowed(menuItem) { + const { policy, endpoints, children = [], ...rest } = menuItem; + if (policy && !checkItemPolicy({ policy })) { + return null; + } + if (endpoints && !this.checkItemEndpoints(endpoints)) { + return null; + } + if (children.length === 0) { + return menuItem; + } + const newChildren = children + .map((it) => this.updateMenuItemByAllowed(it)) + .filter((it) => !!it); + return { + ...rest, + children: newChildren, + }; + } + init() { if (this.isAdminPage && !this.hasAdminPageRole) { window.location.href = '/base/overview'; diff --git a/src/stores/root.js b/src/stores/root.js index 6d8062c2..158a2c5a 100644 --- a/src/stores/root.js +++ b/src/stores/root.js @@ -57,9 +57,6 @@ export class RootStore { @observable oldPassword = {}; - @observable - license = null; - @observable info = {}; @@ -149,30 +146,17 @@ export class RootStore { this.policies = policies; const { endpoints = {}, - license = {}, version = '', project: { id: projectId, name: projectName } = {}, } = user || {}; this.projectId = projectId; this.projectName = projectName; - this.license = license || {}; this.version = version; this.endpoints = endpoints; this.updateUserRoles(user); this.setKeystoneToken(user); } - checkLicense(key) { - if (!key) { - return true; - } - const { features = [] } = this.license || {}; - const addonItem = features.find((it) => !!it.addons) || {}; - const { addons: addonStr = '' } = addonItem || {}; - const addons = addonStr.split(';'); - return addons.indexOf(key) >= 0; - } - checkEndpoint(key) { if (!key) { return true; @@ -209,7 +193,6 @@ export class RootStore { this.roles = []; this.hasAdminRole = false; this.hasAdminPageRole = false; - this.license = null; this.version = ''; this.noticeCount = 0; this.goToLoginPage();