From 60ad52f7aedb08b4294c243d5dae8d0341747984 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Mon, 15 Feb 2021 22:14:19 +0800 Subject: [PATCH] Add User.isGlobalAdmin --- object/init.go | 29 ++++++++++---------- object/user.go | 21 ++++++++------- web/src/App.js | 59 ++++++++++++++++++++++------------------- web/src/Setting.js | 2 +- web/src/UserEditPage.js | 36 ++++++++++++++++++------- web/src/UserListPage.js | 12 +++++++++ 6 files changed, 96 insertions(+), 63 deletions(-) diff --git a/object/init.go b/object/init.go index b679cadf..9d190047 100644 --- a/object/init.go +++ b/object/init.go @@ -31,20 +31,21 @@ func initBuiltInUser() { } user = &User{ - Owner: "built-in", - Name: "admin", - CreatedTime: util.GetCurrentTime(), - Id: util.GenerateId(), - Password: "123", - PasswordType: "plain", - DisplayName: "Admin", - Avatar: "https://casbin.org/img/casbin.svg", - Email: "admin@example.com", - Phone: "1-12345678", - Affiliation: "Example Inc.", - Tag: "staff", - IsAdmin: true, - Github: "", + Owner: "built-in", + Name: "admin", + CreatedTime: util.GetCurrentTime(), + Id: util.GenerateId(), + Password: "123", + PasswordType: "plain", + DisplayName: "Admin", + Avatar: "https://casbin.org/img/casbin.svg", + Email: "admin@example.com", + Phone: "1-12345678", + Affiliation: "Example Inc.", + Tag: "staff", + IsAdmin: true, + IsGlobalAdmin: true, + Github: "", } AddUser(user) } diff --git a/object/user.go b/object/user.go index ec78eed5..743d392f 100644 --- a/object/user.go +++ b/object/user.go @@ -24,16 +24,17 @@ type User struct { Name string `xorm:"varchar(100) notnull pk" json:"name"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"` - Id string `xorm:"varchar(100)" json:"id"` - Password string `xorm:"varchar(100)" json:"password"` - PasswordType string `xorm:"varchar(100)" json:"passwordType"` - DisplayName string `xorm:"varchar(100)" json:"displayName"` - Avatar string `xorm:"varchar(100)" json:"avatar"` - Email string `xorm:"varchar(100)" json:"email"` - Phone string `xorm:"varchar(100)" json:"phone"` - Affiliation string `xorm:"varchar(100)" json:"affiliation"` - Tag string `xorm:"varchar(100)" json:"tag"` - IsAdmin bool `json:"isAdmin"` + Id string `xorm:"varchar(100)" json:"id"` + Password string `xorm:"varchar(100)" json:"password"` + PasswordType string `xorm:"varchar(100)" json:"passwordType"` + DisplayName string `xorm:"varchar(100)" json:"displayName"` + Avatar string `xorm:"varchar(100)" json:"avatar"` + Email string `xorm:"varchar(100)" json:"email"` + Phone string `xorm:"varchar(100)" json:"phone"` + Affiliation string `xorm:"varchar(100)" json:"affiliation"` + Tag string `xorm:"varchar(100)" json:"tag"` + IsAdmin bool `json:"isAdmin"` + IsGlobalAdmin bool `json:"isGlobalAdmin"` Github string `xorm:"varchar(100)" json:"github"` } diff --git a/web/src/App.js b/web/src/App.js index 197a857b..2f84d9e5 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -194,34 +194,37 @@ class App extends Component { ); - res.push( - - - Organizations - - - ); - res.push( - - - Users - - - ); - res.push( - - - Providers - - - ); - res.push( - - - Applications - - - ); + + if (Setting.isAdminUser(this.state.account)) { + res.push( + + + Organizations + + + ); + res.push( + + + Users + + + ); + res.push( + + + Providers + + + ); + res.push( + + + Applications + + + ); + } return res; } diff --git a/web/src/Setting.js b/web/src/Setting.js index e1508ae1..bcda65c6 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -59,7 +59,7 @@ export function showMessage(type, text) { } export function isAdminUser(account) { - return account.owner === "built-in"; + return account.owner === "built-in" || account.isGlobalAdmin === true; } export function deepCopy(obj) { diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 918d7798..0d39cd19 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -216,16 +216,32 @@ class UserEditPage extends React.Component { - - - Is Admin: - - - { - this.updateUserField('isAdmin', checked); - }} /> - - + { + !Setting.isAdminUser(this.props.account) ? null : ( + + + + Is Admin: + + + { + this.updateUserField('isAdmin', checked); + }} /> + + + + + Is Global Admin: + + + { + this.updateUserField('isGlobalAdmin', checked); + }} /> + + + + ) + } ) } diff --git a/web/src/UserListPage.js b/web/src/UserListPage.js index bfe94fdc..f39b660d 100644 --- a/web/src/UserListPage.js +++ b/web/src/UserListPage.js @@ -208,6 +208,18 @@ class UserListPage extends React.Component { ) } }, + { + title: 'Is Global Admin', + dataIndex: 'isGlobalAdmin', + key: 'isGlobalAdmin', + width: '120px', + sorter: (a, b) => a.isGlobalAdmin.localeCompare(b.isGlobalAdmin), + render: (text, record, index) => { + return ( + + ) + } + }, { title: 'Action', dataIndex: '',