diff --git a/web/src/App.js b/web/src/App.js index 1967ebb8..de43f784 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -17,62 +17,9 @@ import "./App.less"; import {Helmet} from "react-helmet"; import * as Setting from "./Setting"; import {StyleProvider, legacyLogicalPropertiesTransformer} from "@ant-design/cssinjs"; -import {AppstoreTwoTone, BarsOutlined, DeploymentUnitOutlined, DollarTwoTone, DownOutlined, GithubOutlined, HomeTwoTone, InfoCircleFilled, LockTwoTone, LogoutOutlined, SafetyCertificateTwoTone, SettingOutlined, SettingTwoTone, ShareAltOutlined, WalletTwoTone} from "@ant-design/icons"; -import {Alert, Avatar, Button, Card, ConfigProvider, Drawer, Dropdown, FloatButton, Layout, Menu, Result, Tooltip} from "antd"; -import {Link, Redirect, Route, Switch, withRouter} from "react-router-dom"; -import AccountPage from "./account/AccountPage"; -import Dashboard from "./basic/Dashboard"; -import ShortcutsPage from "./basic/ShortcutsPage"; -import AppListPage from "./basic/AppListPage"; -import OrganizationListPage from "./OrganizationListPage"; -import OrganizationEditPage from "./OrganizationEditPage"; -import GroupEditPage from "./GroupEdit"; -import GroupListPage from "./GroupList"; -import GroupTreePage from "./GroupTreePage"; -import UserListPage from "./UserListPage"; -import UserEditPage from "./UserEditPage"; -import InvitationListPage from "./InvitationListPage"; -import InvitationEditPage from "./InvitationEditPage"; -import ApplicationListPage from "./ApplicationListPage"; -import ApplicationEditPage from "./ApplicationEditPage"; -import ProviderListPage from "./ProviderListPage"; -import ProviderEditPage from "./ProviderEditPage"; -import ResourceListPage from "./ResourceListPage"; -import CertListPage from "./CertListPage"; -import CertEditPage from "./CertEditPage"; -import RoleListPage from "./RoleListPage"; -import RoleEditPage from "./RoleEditPage"; -import PermissionListPage from "./PermissionListPage"; -import PermissionEditPage from "./PermissionEditPage"; -import ModelListPage from "./ModelListPage"; -import ModelEditPage from "./ModelEditPage"; -import AdapterListPage from "./AdapterListPage"; -import AdapterEditPage from "./AdapterEditPage"; -import EnforcerEditPage from "./EnforcerEditPage"; -import EnforcerListPage from "./EnforcerListPage"; -import SessionListPage from "./SessionListPage"; -import TokenListPage from "./TokenListPage"; -import TokenEditPage from "./TokenEditPage"; -import ProductListPage from "./ProductListPage"; -import ProductEditPage from "./ProductEditPage"; -import ProductBuyPage from "./ProductBuyPage"; -import PaymentListPage from "./PaymentListPage"; -import PaymentEditPage from "./PaymentEditPage"; -import PaymentResultPage from "./PaymentResultPage"; -import PricingListPage from "./PricingListPage"; -import PricingEditPage from "./PricingEditPage"; -import PlanListPage from "./PlanListPage"; -import PlanEditPage from "./PlanEditPage"; -import SubscriptionListPage from "./SubscriptionListPage"; -import SubscriptionEditPage from "./SubscriptionEditPage"; -import SystemInfo from "./SystemInfo"; -import SyncerListPage from "./SyncerListPage"; -import SyncerEditPage from "./SyncerEditPage"; -import WebhookListPage from "./WebhookListPage"; -import WebhookEditPage from "./WebhookEditPage"; -import LdapEditPage from "./LdapEditPage"; -import LdapSyncPage from "./LdapSyncPage"; -import MfaSetupPage from "./auth/MfaSetupPage"; +import {GithubOutlined, InfoCircleFilled, ShareAltOutlined} from "@ant-design/icons"; +import {Alert, Button, ConfigProvider, Drawer, FloatButton, Layout, Result, Tooltip} from "antd"; +import {Route, Switch, withRouter} from "react-router-dom"; import CustomGithubCorner from "./common/CustomGithubCorner"; import * as Conf from "./Conf"; @@ -80,22 +27,13 @@ import * as Auth from "./auth/Auth"; import EntryPage from "./EntryPage"; import * as AuthBackend from "./auth/AuthBackend"; import AuthCallback from "./auth/AuthCallback"; -import OdicDiscoveryPage from "./auth/OidcDiscoveryPage"; import SamlCallback from "./auth/SamlCallback"; import i18next from "i18next"; import {withTranslation} from "react-i18next"; -import EnableMfaNotification from "./common/notifaction/EnableMfaNotification"; -import LanguageSelect from "./common/select/LanguageSelect"; -import ThemeSelect from "./common/select/ThemeSelect"; -import OrganizationSelect from "./common/select/OrganizationSelect"; -import {clearWeb3AuthToken} from "./auth/Web3Auth"; -import AccountAvatar from "./account/AccountAvatar"; -import OpenTour from "./common/OpenTour"; - -const {Header, Footer, Content} = Layout; +import ManagementPage from "./ManagementPage"; +const {Footer, Content} = Layout; import {setTwoToneColor} from "@ant-design/icons"; -import RecordListPage from "./RecordListPage"; setTwoToneColor("rgb(87,52,211)"); @@ -113,7 +51,6 @@ class App extends Component { selectedMenuKey: 0, account: undefined, uri: null, - menuVisible: false, themeAlgorithm: storageThemeAlgorithm, themeData: Conf.ThemeDefault, logo: this.getLogo(storageThemeAlgorithm), @@ -292,391 +229,12 @@ class App extends Component { }); } - logout() { - this.setState({ - expired: false, - submitted: false, - }); - - AuthBackend.logout() - .then((res) => { - if (res.status === "ok") { - const owner = this.state.account.owner; - this.setState({ - account: null, - themeAlgorithm: ["default"], - }); - clearWeb3AuthToken(); - Setting.showMessage("success", i18next.t("application:Logged out successfully")); - const redirectUri = res.data2; - if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { - Setting.goToLink(redirectUri); - } else if (owner !== "built-in") { - Setting.goToLink(`${window.location.origin}/login/${owner}`); - } else { - Setting.goToLinkSoft(this, "/"); - } - } else { - Setting.showMessage("error", `Failed to log out: ${res.msg}`); - } - }); - } - onUpdateAccount(account) { this.setState({ account: account, }); } - renderAvatar() { - if (this.state.account.avatar === "") { - return ( - - {Setting.getShortName(this.state.account.name)} - - ); - } else { - return ( - } - > - {Setting.getShortName(this.state.account.name)} - - ); - } - } - - renderRightDropdown() { - const items = []; - if (this.state.requiredEnableMfa === false) { - items.push(Setting.getItem(<>  {i18next.t("account:My Account")}, - "/account" - )); - } - items.push(Setting.getItem(<>  {i18next.t("account:Logout")}, - "/logout")); - - const onClick = (e) => { - if (e.key === "/account") { - this.props.history.push("/account"); - } else if (e.key === "/subscription") { - this.props.history.push("/subscription"); - } else if (e.key === "/logout") { - this.logout(); - } - }; - - return ( - -
- { - this.renderAvatar() - } -   -   - {Setting.isMobile() ? null : Setting.getShortText(Setting.getNameAtLeast(this.state.account.displayName), 30)}   -   -   -   -
-
- ); - } - - renderAccountMenu() { - if (this.state.account === undefined) { - return null; - } else if (this.state.account === null) { - return ( - - - - ); - } else { - return ( - - {this.renderRightDropdown()} - { - this.setState({ - themeAlgorithm: nextThemeAlgorithm, - logo: this.getLogo(nextThemeAlgorithm), - }); - localStorage.setItem("themeAlgorithm", JSON.stringify(nextThemeAlgorithm)); - }} /> - - -
{ - this.setState({ - isAiAssistantOpen: true, - }); - }}> - -
-
- - {Setting.isAdminUser(this.state.account) && !Setting.isMobile() && (this.state.uri.indexOf("/trees") === -1) && - { - Setting.setOrganization(value); - }} - className="select-box" - /> - } -
- ); - } - } - - getMenuItems() { - const res = []; - - if (this.state.account === null || this.state.account === undefined) { - return []; - } - - const textColor = this.state.themeAlgorithm.includes("dark") ? "white" : "black"; - const twoToneColor = this.state.themeData.colorPrimary; - - res.push(Setting.getItem({i18next.t("general:Home")}, "/home", , [ - Setting.getItem({i18next.t("general:Dashboard")}, "/"), - Setting.getItem({i18next.t("general:Shortcuts")}, "/shortcuts"), - Setting.getItem({i18next.t("general:Apps")}, "/apps"), - ].filter(item => { - return Setting.isLocalAdminUser(this.state.account); - }))); - - if (Setting.isLocalAdminUser(this.state.account)) { - if (Conf.ShowGithubCorner) { - res.push(Setting.getItem( - - 🚀 SaaS Hosting 🔥 - - , "#")); - } - - res.push(Setting.getItem({i18next.t("general:User Management")}, "/orgs", , [ - Setting.getItem({i18next.t("general:Organizations")}, "/organizations"), - Setting.getItem({i18next.t("general:Groups")}, "/groups"), - Setting.getItem({i18next.t("general:Users")}, "/users"), - Setting.getItem({i18next.t("general:Invitations")}, "/invitations"), - ])); - - res.push(Setting.getItem({i18next.t("general:Identity")}, "/identity", , [ - Setting.getItem({i18next.t("general:Applications")}, "/applications"), - Setting.getItem({i18next.t("general:Providers")}, "/providers"), - Setting.getItem({i18next.t("general:Resources")}, "/resources"), - Setting.getItem({i18next.t("general:Certs")}, "/certs"), - ])); - - res.push(Setting.getItem({i18next.t("general:Authorization")}, "/auth", , [ - Setting.getItem({i18next.t("general:Roles")}, "/roles"), - Setting.getItem({i18next.t("general:Permissions")}, "/permissions"), - Setting.getItem({i18next.t("general:Models")}, "/models"), - Setting.getItem({i18next.t("general:Adapters")}, "/adapters"), - Setting.getItem({i18next.t("general:Enforcers")}, "/enforcers"), - ].filter(item => { - if (!Setting.isLocalAdminUser(this.state.account) && ["/models", "/adapters", "/enforcers"].includes(item.key)) { - return false; - } else { - return true; - } - }))); - - res.push(Setting.getItem({i18next.t("general:Logging & Auditing")}, "/logs", , [ - Setting.getItem({i18next.t("general:Sessions")}, "/sessions"), - Conf.CasvisorUrl ? Setting.getItem({i18next.t("general:Records")}, "/records") - : Setting.getItem({i18next.t("general:Records")}, "/records"), - Setting.getItem({i18next.t("general:Tokens")}, "/tokens"), - ])); - - res.push(Setting.getItem({i18next.t("general:Business & Payments")}, "/business", , [ - Setting.getItem({i18next.t("general:Products")}, "/products"), - Setting.getItem({i18next.t("general:Payments")}, "/payments"), - Setting.getItem({i18next.t("general:Plans")}, "/plans"), - Setting.getItem({i18next.t("general:Pricings")}, "/pricings"), - Setting.getItem({i18next.t("general:Subscriptions")}, "/subscriptions"), - ])); - - if (Setting.isAdminUser(this.state.account)) { - res.push(Setting.getItem({i18next.t("general:Admin")}, "/admin", , [ - Setting.getItem({i18next.t("general:System Info")}, "/sysinfo"), - Setting.getItem({i18next.t("general:Syncers")}, "/syncers"), - Setting.getItem({i18next.t("general:Webhooks")}, "/webhooks"), - Setting.getItem({i18next.t("general:Swagger")}, "/swagger")])); - } else { - res.push(Setting.getItem({i18next.t("general:Admin")}, "/admin", , [ - Setting.getItem({i18next.t("general:Syncers")}, "/syncers"), - Setting.getItem({i18next.t("general:Webhooks")}, "/webhooks")])); - } - } - - return res; - } - - renderLoginIfNotLoggedIn(component) { - if (this.state.account === null) { - sessionStorage.setItem("from", window.location.pathname); - return ; - } else if (this.state.account === undefined) { - return null; - } else { - return component; - } - } - - renderRouter() { - return ( - - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - } /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn( this.setState({requiredEnableMfa: false})} {...props} />)} /> - } /> - } />} /> - - ); - } - - onClose = () => { - this.setState({ - menuVisible: false, - }); - }; - - showMenu = () => { - this.setState({ - menuVisible: true, - }); - }; - - isWithoutCard() { - return Setting.isMobile() || window.location.pathname.startsWith("/trees"); - } - - renderContent() { - const onClick = ({key}) => { - if (key !== "/swagger" && key !== "/records") { - if (this.state.requiredEnableMfa) { - Setting.showMessage("info", "Please enable MFA first!"); - } else { - this.props.history.push(key); - } - } - }; - const menuStyleRight = Setting.isAdminUser(this.state.account) && !Setting.isMobile() ? "calc(180px + 280px)" : "280px"; - return ( - - -
- {Setting.isMobile() ? null : ( - -
- - )} - {this.state.requiredEnableMfa || (Setting.isMobile() ? - - - - - - - : - - )} - { - this.renderAccountMenu() - } -
- - {this.isWithoutCard() ? - this.renderRouter() : - - {this.renderRouter()} - - } - - { - this.renderFooter() - } - { - this.renderAiAssistant() - } -
- ); - } - renderFooter() { return ( @@ -748,6 +306,16 @@ class App extends Component { window.location.pathname.startsWith("/qrcode") ; } + onClick = ({key}) => { + if (key !== "/swagger" && key !== "/records") { + if (this.state.requiredEnableMfa) { + Setting.showMessage("info", "Please enable MFA first!"); + } else { + this.props.history.push(key); + } + } + }; + renderPage() { if (this.isDoorPages()) { return ( @@ -790,7 +358,6 @@ class App extends Component { ); } - return ( {/* { */} @@ -799,7 +366,47 @@ class App extends Component { { - this.renderContent() + + { + this.setState({requiredEnableMfa: false}); + }} + openAiAssistant={() => { + this.setState({ + isAiAssistantOpen: true, + }); + }} + setLogoAndThemeAlgorithm={(nextThemeAlgorithm) => { + this.setState({ + themeAlgorithm: nextThemeAlgorithm, + logo: this.getLogo(nextThemeAlgorithm), + }); + localStorage.setItem("themeAlgorithm", JSON.stringify(nextThemeAlgorithm)); + }} + setLogoutState={() => { + this.setState({ + account: null, + themeAlgorithm: ["default"], + }); + }} + /> + { + this.renderFooter() + } + { + this.renderAiAssistant() + } + } ); diff --git a/web/src/ManagementPage.js b/web/src/ManagementPage.js new file mode 100644 index 00000000..86f936f3 --- /dev/null +++ b/web/src/ManagementPage.js @@ -0,0 +1,443 @@ +// Copyright 2024 The Casdoor Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import * as Setting from "./Setting"; +import {Avatar, Button, Card, Drawer, Dropdown, Menu, Result, Tooltip} from "antd"; +import EnableMfaNotification from "./common/notifaction/EnableMfaNotification"; +import {Link, Redirect, Route, Switch, withRouter} from "react-router-dom"; +import React, {useState} from "react"; +import i18next from "i18next"; +import { + AppstoreTwoTone, + BarsOutlined, DeploymentUnitOutlined, DollarTwoTone, DownOutlined, + HomeTwoTone, + LockTwoTone, LogoutOutlined, + SafetyCertificateTwoTone, SettingOutlined, SettingTwoTone, + WalletTwoTone +} from "@ant-design/icons"; +import Dashboard from "./basic/Dashboard"; +import AppListPage from "./basic/AppListPage"; +import ShortcutsPage from "./basic/ShortcutsPage"; +import AccountPage from "./account/AccountPage"; +import OrganizationListPage from "./OrganizationListPage"; +import OrganizationEditPage from "./OrganizationEditPage"; +import UserListPage from "./UserListPage"; +import GroupTreePage from "./GroupTreePage"; +import GroupListPage from "./GroupList"; +import GroupEditPage from "./GroupEdit"; +import UserEditPage from "./UserEditPage"; +import InvitationListPage from "./InvitationListPage"; +import InvitationEditPage from "./InvitationEditPage"; +import ApplicationListPage from "./ApplicationListPage"; +import ApplicationEditPage from "./ApplicationEditPage"; +import ProviderListPage from "./ProviderListPage"; +import ProviderEditPage from "./ProviderEditPage"; +import RecordListPage from "./RecordListPage"; +import ResourceListPage from "./ResourceListPage"; +import CertListPage from "./CertListPage"; +import CertEditPage from "./CertEditPage"; +import RoleListPage from "./RoleListPage"; +import RoleEditPage from "./RoleEditPage"; +import PermissionListPage from "./PermissionListPage"; +import PermissionEditPage from "./PermissionEditPage"; +import ModelListPage from "./ModelListPage"; +import ModelEditPage from "./ModelEditPage"; +import AdapterListPage from "./AdapterListPage"; +import AdapterEditPage from "./AdapterEditPage"; +import EnforcerListPage from "./EnforcerListPage"; +import EnforcerEditPage from "./EnforcerEditPage"; +import SessionListPage from "./SessionListPage"; +import TokenListPage from "./TokenListPage"; +import TokenEditPage from "./TokenEditPage"; +import ProductListPage from "./ProductListPage"; +import ProductEditPage from "./ProductEditPage"; +import ProductBuyPage from "./ProductBuyPage"; +import PaymentListPage from "./PaymentListPage"; +import PaymentEditPage from "./PaymentEditPage"; +import PaymentResultPage from "./PaymentResultPage"; +import PlanListPage from "./PlanListPage"; +import PlanEditPage from "./PlanEditPage"; +import PricingListPage from "./PricingListPage"; +import PricingEditPage from "./PricingEditPage"; +import SubscriptionListPage from "./SubscriptionListPage"; +import SubscriptionEditPage from "./SubscriptionEditPage"; +import SystemInfo from "./SystemInfo"; +import SyncerListPage from "./SyncerListPage"; +import SyncerEditPage from "./SyncerEditPage"; +import WebhookListPage from "./WebhookListPage"; +import WebhookEditPage from "./WebhookEditPage"; +import LdapEditPage from "./LdapEditPage"; +import LdapSyncPage from "./LdapSyncPage"; +import MfaSetupPage from "./auth/MfaSetupPage"; +import OdicDiscoveryPage from "./auth/OidcDiscoveryPage"; +import * as Conf from "./Conf"; +import LanguageSelect from "./common/select/LanguageSelect"; +import ThemeSelect from "./common/select/ThemeSelect"; +import OpenTour from "./common/OpenTour"; +import OrganizationSelect from "./common/select/OrganizationSelect"; +import AccountAvatar from "./account/AccountAvatar"; +import {Content, Header} from "antd/es/layout/layout"; +import * as AuthBackend from "./auth/AuthBackend"; +import {clearWeb3AuthToken} from "./auth/Web3Auth"; + +function ManagementPage(props) { + + const [menuVisible, setMenuVisible] = useState(false); + + function logout() { + AuthBackend.logout() + .then((res) => { + if (res.status === "ok") { + const owner = props.account.owner; + props.setLogoutState(); + clearWeb3AuthToken(); + Setting.showMessage("success", i18next.t("application:Logged out successfully")); + const redirectUri = res.data2; + if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { + Setting.goToLink(redirectUri); + } else if (owner !== "built-in") { + Setting.goToLink(`${window.location.origin}/login/${owner}`); + } else { + Setting.goToLinkSoft({props}, "/"); + } + } else { + Setting.showMessage("error", `Failed to log out: ${res.msg}`); + } + }); + } + + function renderAvatar() { + if (props.account.avatar === "") { + return ( + + {Setting.getShortName(props.account.name)} + + ); + } else { + return ( + } + > + {Setting.getShortName(props.account.name)} + + ); + } + } + + function renderRightDropdown() { + const items = []; + if (props.requiredEnableMfa === false) { + items.push(Setting.getItem(<>  {i18next.t("account:My Account")}, + "/account" + )); + } + items.push(Setting.getItem(<>  {i18next.t("account:Logout")}, + "/logout")); + + const onClick = (e) => { + if (e.key === "/account") { + props.history.push("/account"); + } else if (e.key === "/subscription") { + props.history.push("/subscription"); + } else if (e.key === "/logout") { + logout(); + } + }; + + return ( + +
+ { + renderAvatar() + } +   +   + {Setting.isMobile() ? null : Setting.getShortText(Setting.getNameAtLeast(props.account.displayName), 30)}   +   +   +   +
+
+ ); + } + + function renderAccountMenu() { + if (props.account === undefined) { + return null; + } else if (props.account === null) { + return ( + + + + ); + } else { + return ( + + {renderRightDropdown()} + + + +
+ +
+
+ + {Setting.isAdminUser(props.account) && !Setting.isMobile() && (props.uri.indexOf("/trees") === -1) && + { + Setting.setOrganization(value); + }} + className="select-box" + /> + } +
+ ); + } + } + + function getMenuItems() { + const res = []; + + if (props.account === null || props.account === undefined) { + return []; + } + + const textColor = props.themeAlgorithm.includes("dark") ? "white" : "black"; + const twoToneColor = props.themeData.colorPrimary; + + res.push(Setting.getItem({i18next.t("general:Home")}, "/home", , [ + Setting.getItem({i18next.t("general:Dashboard")}, "/"), + Setting.getItem({i18next.t("general:Shortcuts")}, "/shortcuts"), + Setting.getItem({i18next.t("general:Apps")}, "/apps"), + ].filter(item => { + return Setting.isLocalAdminUser(props.account); + }))); + + if (Setting.isLocalAdminUser(props.account)) { + if (Conf.ShowGithubCorner) { + res.push(Setting.getItem( + + 🚀 SaaS Hosting 🔥 + + , "#")); + } + + res.push(Setting.getItem({i18next.t("general:User Management")}, "/orgs", , [ + Setting.getItem({i18next.t("general:Organizations")}, "/organizations"), + Setting.getItem({i18next.t("general:Groups")}, "/groups"), + Setting.getItem({i18next.t("general:Users")}, "/users"), + Setting.getItem({i18next.t("general:Invitations")}, "/invitations"), + ])); + + res.push(Setting.getItem({i18next.t("general:Identity")}, "/identity", , [ + Setting.getItem({i18next.t("general:Applications")}, "/applications"), + Setting.getItem({i18next.t("general:Providers")}, "/providers"), + Setting.getItem({i18next.t("general:Resources")}, "/resources"), + Setting.getItem({i18next.t("general:Certs")}, "/certs"), + ])); + + res.push(Setting.getItem({i18next.t("general:Authorization")}, "/auth", , [ + Setting.getItem({i18next.t("general:Roles")}, "/roles"), + Setting.getItem({i18next.t("general:Permissions")}, "/permissions"), + Setting.getItem({i18next.t("general:Models")}, "/models"), + Setting.getItem({i18next.t("general:Adapters")}, "/adapters"), + Setting.getItem({i18next.t("general:Enforcers")}, "/enforcers"), + ].filter(item => { + if (!Setting.isLocalAdminUser(props.account) && ["/models", "/adapters", "/enforcers"].includes(item.key)) { + return false; + } else { + return true; + } + }))); + + res.push(Setting.getItem({i18next.t("general:Logging & Auditing")}, "/logs", , [ + Setting.getItem({i18next.t("general:Sessions")}, "/sessions"), + Conf.CasvisorUrl ? Setting.getItem({i18next.t("general:Records")}, "/records") + : Setting.getItem({i18next.t("general:Records")}, "/records"), + Setting.getItem({i18next.t("general:Tokens")}, "/tokens"), + ])); + + res.push(Setting.getItem({i18next.t("general:Business & Payments")}, "/business", , [ + Setting.getItem({i18next.t("general:Products")}, "/products"), + Setting.getItem({i18next.t("general:Payments")}, "/payments"), + Setting.getItem({i18next.t("general:Plans")}, "/plans"), + Setting.getItem({i18next.t("general:Pricings")}, "/pricings"), + Setting.getItem({i18next.t("general:Subscriptions")}, "/subscriptions"), + ])); + + if (Setting.isAdminUser(props.account)) { + res.push(Setting.getItem({i18next.t("general:Admin")}, "/admin", , [ + Setting.getItem({i18next.t("general:System Info")}, "/sysinfo"), + Setting.getItem({i18next.t("general:Syncers")}, "/syncers"), + Setting.getItem({i18next.t("general:Webhooks")}, "/webhooks"), + Setting.getItem({i18next.t("general:Swagger")}, "/swagger")])); + } else { + res.push(Setting.getItem({i18next.t("general:Admin")}, "/admin", , [ + Setting.getItem({i18next.t("general:Syncers")}, "/syncers"), + Setting.getItem({i18next.t("general:Webhooks")}, "/webhooks")])); + } + } + + return res; + } + + function renderLoginIfNotLoggedIn(component) { + if (props.account === null) { + sessionStorage.setItem("from", window.location.pathname); + return ; + } else if (props.account === undefined) { + return null; + } else { + return component; + } + } + + function renderRouter() { + const account = props.account; + const onChangeTheme = props.onChangeTheme; + const onfinish = props.onfinish; + return ( + + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + } /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + renderLoginIfNotLoggedIn()} /> + } /> + } />} /> + + ); + } + + function isWithoutCard() { + return Setting.isMobile() || window.location.pathname.startsWith("/trees"); + } + + const menuStyleRight = Setting.isAdminUser(props.account) && !Setting.isMobile() ? "calc(180px + 280px)" : "280px"; + + const onClose = () => { + setMenuVisible(false); + }; + + const showMenu = () => { + setMenuVisible(true); + }; + + return ( + + +
+ {Setting.isMobile() ? null : ( + +
+ + )} + {props.requiredEnableMfa || (Setting.isMobile() ? + + + + + + + : + + )} + { + renderAccountMenu() + } +
+ + {isWithoutCard() ? + renderRouter() : + + {renderRouter()} + + } + +
+ ); +} + +export default withRouter(ManagementPage);