From 5779d57960e7a08c18f77c42cca591b1a3439950 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Thu, 29 Apr 2021 19:51:03 +0800 Subject: [PATCH] Set org's document title and favicon. --- controllers/account.go | 4 +++- util/string.go | 5 +++++ web/package.json | 1 + web/public/index.html | 2 +- web/src/App.js | 39 +++++++++++++++++++++++++++++++-- web/src/OrganizationListPage.js | 2 +- web/yarn.lock | 20 +++++++++++++++++ 7 files changed, 68 insertions(+), 5 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index a5d1efbf..edb39ac4 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -53,6 +53,7 @@ type Response struct { Status string `json:"status"` Msg string `json:"msg"` Data interface{} `json:"data"` + Data2 interface{} `json:"data2"` } // @Title Signup @@ -145,7 +146,8 @@ func (c *ApiController) GetAccount() { username := c.GetSessionUser() user := object.GetUser(username) - resp = Response{Status: "ok", Msg: "", Data: user} + organization := object.GetOrganization(util.GetId(user.Owner)) + resp = Response{Status: "ok", Msg: "", Data: user, Data2: organization} c.Data["json"] = resp c.ServeJSON() diff --git a/util/string.go b/util/string.go index 955d1ad3..bec52fa9 100644 --- a/util/string.go +++ b/util/string.go @@ -16,6 +16,7 @@ package util import ( "errors" + "fmt" "strings" "github.com/google/uuid" @@ -33,3 +34,7 @@ func GetOwnerAndNameFromId(id string) (string, string) { func GenerateId() string { return uuid.NewString() } + +func GetId(name string) string { + return fmt.Sprintf("admin/%s", name) +} diff --git a/web/package.json b/web/package.json index d7d6a419..7b694dd3 100644 --- a/web/package.json +++ b/web/package.json @@ -18,6 +18,7 @@ "react-device-detect": "^1.14.0", "react-dom": "^17.0.2", "react-github-corner": "^2.5.0", + "react-helmet": "^6.1.0", "react-i18next": "^11.8.7", "react-router-dom": "^5.2.0", "react-scripts": "4.0.3", diff --git a/web/public/index.html b/web/public/index.html index 00b1292a..dc710d18 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -2,7 +2,7 @@ - + { + let account = null; + if (res.status === "ok") { + account = res.data; + account.organization = res.data2; + } + this.setState({ - account: res.status === "ok" ? res.data : null, + account: account, }); }); } @@ -389,7 +396,7 @@ class App extends Component { return window.location.pathname.startsWith("/login/oauth/authorize"); } - render() { + renderPage() { if (this.isDoorPages()) { return ( @@ -413,6 +420,34 @@ class App extends Component { ); } + + render() { + if (this.state.account === undefined || this.state.account === null) { + return ( + + + + + { + this.renderPage() + } + + ) + } + + const organization = this.state.account.organization; + return ( + + + {organization.displayName} + + + { + this.renderPage() + } + + ) + } } export default withRouter(App); diff --git a/web/src/OrganizationListPage.js b/web/src/OrganizationListPage.js index d0ac7711..bc617f21 100644 --- a/web/src/OrganizationListPage.js +++ b/web/src/OrganizationListPage.js @@ -48,7 +48,7 @@ class OrganizationListPage extends React.Component { name: `organization_${this.state.organizations.length}`, createdTime: moment().format(), displayName: `New Organization - ${this.state.organizations.length}`, - websiteUrl: "https://example.com", + websiteUrl: "https://cdn.casbin.com/static/favicon.ico", } } diff --git a/web/yarn.lock b/web/yarn.lock index f6d70782..5875f0e8 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -9790,11 +9790,26 @@ react-error-overlay@^6.0.9: resolved "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a" integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew== +react-fast-compare@^3.1.1: + version "3.2.0" + resolved "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.0.tgz#641a9da81b6a6320f270e89724fb45a0b39e43bb" + integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA== + react-github-corner@^2.5.0: version "2.5.0" resolved "https://registry.npmjs.org/react-github-corner/-/react-github-corner-2.5.0.tgz#e350d0c69f69c075bc0f1d2a6f1df6ee91da31f2" integrity sha512-ofds9l6n61LJc6ML+jSE6W9ZSQvATcMR9evnHPXua1oDYj289HKODnVqFUB/g2a4ieBjDHw416iHP3MjqnU76Q== +react-helmet@^6.1.0: + version "6.1.0" + resolved "https://registry.npmjs.org/react-helmet/-/react-helmet-6.1.0.tgz#a750d5165cb13cf213e44747502652e794468726" + integrity sha512-4uMzEY9nlDlgxr61NL3XbKRy1hEkXmKNXhjbAIOVw5vcFrsdYbH2FEwcNyWvWinl103nXgzYNlns9ca+8kFiWw== + dependencies: + object-assign "^4.1.1" + prop-types "^15.7.2" + react-fast-compare "^3.1.1" + react-side-effect "^2.1.0" + react-i18next@^11.8.7: version "11.8.12" resolved "https://registry.npmjs.org/react-i18next/-/react-i18next-11.8.12.tgz#6a9f57277062fb6a6129cad4db5e6198d5c60b58" @@ -9913,6 +9928,11 @@ react-scripts@4.0.3: optionalDependencies: fsevents "^2.1.3" +react-side-effect@^2.1.0: + version "2.1.1" + resolved "https://registry.npmjs.org/react-side-effect/-/react-side-effect-2.1.1.tgz#66c5701c3e7560ab4822a4ee2742dee215d72eb3" + integrity sha512-2FoTQzRNTncBVtnzxFOk2mCpcfxQpenBMbk5kSVBg5UcPqV9fRbgY2zhb7GTWWOlpFmAxhClBDlIq8Rsubz1yQ== + react-social-login-buttons@^3.4.0: version "3.4.0" resolved "https://registry.npmjs.org/react-social-login-buttons/-/react-social-login-buttons-3.4.0.tgz#7b3f249c661624435e01881cf163ef4c4a960409"