mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 13:20:19 +08:00
feat: get user api return roles and permissions (#929)
This commit is contained in:
@ -112,6 +112,11 @@ func (c *ApiController) GetUser() {
|
|||||||
user = object.GetUser(id)
|
user = object.GetUser(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roles := object.GetRolesByUser(fmt.Sprintf("%s/%s", user.Owner, user.Name))
|
||||||
|
user.Roles = roles
|
||||||
|
permissions := object.GetPermissionsByUser(fmt.Sprintf("%s/%s", user.Owner, user.Name))
|
||||||
|
user.Permissions = permissions
|
||||||
|
|
||||||
c.Data["json"] = object.GetMaskedUser(user)
|
c.Data["json"] = object.GetMaskedUser(user)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,8 @@ func initBuiltInOrganization() bool {
|
|||||||
{Name: "Bio", Visible: true, ViewRule: "Public", ModifyRule: "Self"},
|
{Name: "Bio", Visible: true, ViewRule: "Public", ModifyRule: "Self"},
|
||||||
{Name: "Tag", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Tag", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
|
{Name: "Roles", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
|
{Name: "Permissions", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
||||||
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
|
@ -89,6 +89,8 @@ func initDefinedOrganization(organization *Organization) {
|
|||||||
{Name: "Bio", Visible: true, ViewRule: "Public", ModifyRule: "Self"},
|
{Name: "Bio", Visible: true, ViewRule: "Public", ModifyRule: "Self"},
|
||||||
{Name: "Tag", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Tag", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
{Name: "Signup application", Visible: true, ViewRule: "Public", ModifyRule: "Admin"},
|
||||||
|
{Name: "Roles", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
|
{Name: "Permissions", Visible: true, ViewRule: "Public", ModifyRule: "Immutable"},
|
||||||
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
{Name: "3rd-party logins", Visible: true, ViewRule: "Self", ModifyRule: "Self"},
|
||||||
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Properties", Visible: false, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
{Name: "Is admin", Visible: true, ViewRule: "Admin", ModifyRule: "Admin"},
|
||||||
|
@ -229,3 +229,13 @@ func removePolicies(permission *Permission) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPermissionsByUser(userId string) []*Permission {
|
||||||
|
permissions := []*Permission{}
|
||||||
|
err := adapter.Engine.Where("users like ?", "%"+userId+"%").Find(&permissions)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return permissions
|
||||||
|
}
|
||||||
|
@ -121,3 +121,13 @@ func DeleteRole(role *Role) bool {
|
|||||||
func (role *Role) GetId() string {
|
func (role *Role) GetId() string {
|
||||||
return fmt.Sprintf("%s/%s", role.Owner, role.Name)
|
return fmt.Sprintf("%s/%s", role.Owner, role.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRolesByUser(userId string) []*Role {
|
||||||
|
roles := []*Role{}
|
||||||
|
err := adapter.Engine.Where("users like ?", "%"+userId+"%").Find(&roles)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return roles
|
||||||
|
}
|
||||||
|
@ -104,6 +104,9 @@ type User struct {
|
|||||||
|
|
||||||
Ldap string `xorm:"ldap varchar(100)" json:"ldap"`
|
Ldap string `xorm:"ldap varchar(100)" json:"ldap"`
|
||||||
Properties map[string]string `json:"properties"`
|
Properties map[string]string `json:"properties"`
|
||||||
|
|
||||||
|
Roles []*Role `json:"roles"`
|
||||||
|
Permissions []*Permission `json:"permissions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Userinfo struct {
|
type Userinfo struct {
|
||||||
|
@ -86,6 +86,8 @@ class AccountTable extends React.Component {
|
|||||||
{name: "Bio", displayName: i18next.t("user:Bio")},
|
{name: "Bio", displayName: i18next.t("user:Bio")},
|
||||||
{name: "Tag", displayName: i18next.t("user:Tag")},
|
{name: "Tag", displayName: i18next.t("user:Tag")},
|
||||||
{name: "Signup application", displayName: i18next.t("general:Signup application")},
|
{name: "Signup application", displayName: i18next.t("general:Signup application")},
|
||||||
|
{name: "Roles", displayName: i18next.t("general:Roles")},
|
||||||
|
{name: "Permissions", displayName: i18next.t("general:Permissions")},
|
||||||
{name: "3rd-party logins", displayName: i18next.t("user:3rd-party logins")},
|
{name: "3rd-party logins", displayName: i18next.t("user:3rd-party logins")},
|
||||||
{name: "Properties", displayName: i18next.t("user:Properties")},
|
{name: "Properties", displayName: i18next.t("user:Properties")},
|
||||||
{name: "Is admin", displayName: i18next.t("user:Is admin")},
|
{name: "Is admin", displayName: i18next.t("user:Is admin")},
|
||||||
|
@ -57,6 +57,8 @@ class OrganizationListPage extends BaseListPage {
|
|||||||
{name: "Bio", visible: true, viewRule: "Public", modifyRule: "Self"},
|
{name: "Bio", visible: true, viewRule: "Public", modifyRule: "Self"},
|
||||||
{name: "Tag", visible: true, viewRule: "Public", modifyRule: "Admin"},
|
{name: "Tag", visible: true, viewRule: "Public", modifyRule: "Admin"},
|
||||||
{name: "Signup application", visible: true, viewRule: "Public", modifyRule: "Admin"},
|
{name: "Signup application", visible: true, viewRule: "Public", modifyRule: "Admin"},
|
||||||
|
{name: "Roles", visible: true, viewRule: "Public", modifyRule: "Immutable"},
|
||||||
|
{name: "Permissions", visible: true, viewRule: "Public", modifyRule: "Immutable"},
|
||||||
{name: "3rd-party logins", visible: true, viewRule: "Self", modifyRule: "Self"},
|
{name: "3rd-party logins", visible: true, viewRule: "Self", modifyRule: "Self"},
|
||||||
{name: "Properties", visible: false, viewRule: "Admin", modifyRule: "Admin"},
|
{name: "Properties", visible: false, viewRule: "Admin", modifyRule: "Admin"},
|
||||||
{name: "Is admin", visible: true, viewRule: "Admin", modifyRule: "Admin"},
|
{name: "Is admin", visible: true, viewRule: "Admin", modifyRule: "Admin"},
|
||||||
|
@ -427,6 +427,32 @@ class UserEditPage extends React.Component {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
} else if (accountItem.name === "Roles") {
|
||||||
|
return (
|
||||||
|
<Row style={{marginTop: "20px", alignItems: "center"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(i18next.t("general:Roles"), i18next.t("general:Roles - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
{
|
||||||
|
Setting.getTags(this.state.user.roles.map(role => role.name))
|
||||||
|
}
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
|
} else if (accountItem.name === "Permissions") {
|
||||||
|
return (
|
||||||
|
<Row style={{marginTop: "20px", alignItems: "center"}} >
|
||||||
|
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
|
||||||
|
{Setting.getLabel(i18next.t("general:Permissions"), i18next.t("general:Permissions - Tooltip"))} :
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
{
|
||||||
|
Setting.getTags(this.state.user.permissions.map(permission => permission.name))
|
||||||
|
}
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
);
|
||||||
} else if (accountItem.name === "3rd-party logins") {
|
} else if (accountItem.name === "3rd-party logins") {
|
||||||
return (
|
return (
|
||||||
!this.isSelfOrAdmin() ? null : (
|
!this.isSelfOrAdmin() ? null : (
|
||||||
|
Reference in New Issue
Block a user