mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 19:40:19 +08:00
feat: complete group tree (#1967)
* feat: complete group tree * feat: ui * fix: i18n * refactor code * fix: support remove user from group * fix: format code * Update organization.go * Update organization.go * Update user_group.go --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
@ -225,14 +225,7 @@ func GetUserCount(owner, field, value string, groupId string) (int64, error) {
|
||||
session := GetSession(owner, -1, -1, field, value, "", "")
|
||||
|
||||
if groupId != "" {
|
||||
group, err := GetGroup(groupId)
|
||||
if group == nil || err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// users count in group
|
||||
return adapter.Engine.Table("user_group_relation").Join("INNER", "user AS u", "user_group_relation.user_id = u.id").
|
||||
Where("user_group_relation.group_id = ?", group.Id).
|
||||
Count(&UserGroupRelation{})
|
||||
return GetGroupUserCount(groupId, field, value)
|
||||
}
|
||||
|
||||
return session.Count(&User{})
|
||||
@ -276,20 +269,7 @@ func GetPaginationUsers(owner string, offset, limit int, field, value, sortField
|
||||
users := []*User{}
|
||||
|
||||
if groupId != "" {
|
||||
group, err := GetGroup(groupId)
|
||||
if group == nil || err != nil {
|
||||
return []*User{}, err
|
||||
}
|
||||
|
||||
session := adapter.Engine.Prepare()
|
||||
if offset != -1 && limit != -1 {
|
||||
session.Limit(limit, offset)
|
||||
}
|
||||
|
||||
err = session.Table("user_group_relation").Join("INNER", "user AS u", "user_group_relation.user_id = u.id").
|
||||
Where("user_group_relation.group_id = ?", group.Id).
|
||||
Find(&users)
|
||||
return users, err
|
||||
return GetPaginationGroupUsers(groupId, offset, limit, field, value, sortField, sortOrder)
|
||||
}
|
||||
|
||||
session := GetSessionForUser(owner, offset, limit, field, value, sortField, sortOrder)
|
||||
@ -300,23 +280,6 @@ func GetPaginationUsers(owner string, offset, limit int, field, value, sortField
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func GetUsersByGroup(groupId string) ([]*User, error) {
|
||||
group, err := GetGroup(groupId)
|
||||
if group == nil || err != nil {
|
||||
return []*User{}, err
|
||||
}
|
||||
|
||||
users := []*User{}
|
||||
err = adapter.Engine.Table("user_group_relation").Join("INNER", "user AS u", "user_group_relation.user_id = u.id").
|
||||
Where("user_group_relation.group_id = ?", group.Id).
|
||||
Find(&users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func getUser(owner string, name string) (*User, error) {
|
||||
if owner == "" || name == "" {
|
||||
return nil, nil
|
||||
@ -574,7 +537,7 @@ func updateUser(oldUser, user *User, columns []string) (int64, error) {
|
||||
session.Begin()
|
||||
|
||||
if util.ContainsString(columns, "groups") {
|
||||
affected, err := updateGroupRelation(session, user)
|
||||
affected, err := updateUserGroupRelation(session, user)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
return affected, err
|
||||
@ -763,6 +726,11 @@ func DeleteUser(user *User) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
affected, err = deleteRelationByUser(user.Id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return affected != 0, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user