修复管理员分组版本校验和受限保存
修复管理员用户列表成员版本缺失导致的多分组保存失败,并保留管理员不可管理分组的成员关系,补充回归测试。
This commit is contained in:
1 parent
87b834e9b2
commit
0f083ccf61
4 files changed
+103
-9
No files matched your search
@@ -125,14 +125,27 @@ func SetAccountGroupMembership(ctx *context.Context, w http.ResponseWriter, req
|
||||
writeAccountGroupError(w, accountgroup.ErrConflict)
|
||||
return
|
||||
}
|
||||
if err := accountgroup.SetMembership(
|
||||
db.Instance,
|
||||
user,
|
||||
input.GroupIDs,
|
||||
guards := []accountgroup.WriteGuard{
|
||||
accountWriteGuard(ctx, user),
|
||||
accountgroup.MembershipScopeGuard(ctx.UserID, ctx.EffectiveRole(), input.GroupIDs),
|
||||
); err != nil {
|
||||
writeAccountGroupError(w, err)
|
||||
}
|
||||
var setErr error
|
||||
if ctx.EffectiveRole() == access.RoleAdmin {
|
||||
visibleGroups, visibleErr := accountgroup.VisibleGroups(db.Instance, ctx.UserID, ctx.EffectiveRole())
|
||||
if visibleErr != nil {
|
||||
writeAccountGroupError(w, visibleErr)
|
||||
return
|
||||
}
|
||||
editableGroupIDs := make([]int, 0, len(visibleGroups))
|
||||
for _, group := range visibleGroups {
|
||||
editableGroupIDs = append(editableGroupIDs, group.ID)
|
||||
}
|
||||
setErr = accountgroup.SetScopedMembership(db.Instance, user, input.GroupIDs, editableGroupIDs, guards...)
|
||||
} else {
|
||||
setErr = accountgroup.SetMembership(db.Instance, user, input.GroupIDs, guards...)
|
||||
}
|
||||
if setErr != nil {
|
||||
writeAccountGroupError(w, setErr)
|
||||
return
|
||||
}
|
||||
InvalidateSecurityRuntimeUser(user.ID, user.Account)
|
||||
|
||||
@@ -273,7 +273,9 @@ func UserList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
items := make([]userListItem, 0, len(users))
|
||||
memberships := map[int][]int{}
|
||||
if ctx.EffectiveRole() == access.RoleSuperAdmin {
|
||||
groupManager := ctx.EffectiveRole() == access.RoleSuperAdmin || ctx.EffectiveRole() == access.RoleAdmin
|
||||
visibleMemberships := map[int]struct{}{}
|
||||
if groupManager {
|
||||
ids := make([]int, 0, len(users))
|
||||
for _, user := range users {
|
||||
ids = append(ids, user.ID)
|
||||
@@ -283,10 +285,30 @@ func UserList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
writeAccountGroupError(w, err)
|
||||
return
|
||||
}
|
||||
if ctx.EffectiveRole() == access.RoleAdmin {
|
||||
visibleGroups, visibleErr := accountgroup.VisibleGroups(db.Instance, ctx.UserID, ctx.EffectiveRole())
|
||||
if visibleErr != nil {
|
||||
writeAccountGroupError(w, visibleErr)
|
||||
return
|
||||
}
|
||||
for _, group := range visibleGroups {
|
||||
visibleMemberships[group.ID] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, user := range users {
|
||||
groupIDs := memberships[user.ID]
|
||||
if ctx.EffectiveRole() == access.RoleAdmin {
|
||||
filtered := make([]int, 0, len(groupIDs))
|
||||
for _, groupID := range groupIDs {
|
||||
if _, ok := visibleMemberships[groupID]; ok {
|
||||
filtered = append(filtered, groupID)
|
||||
}
|
||||
}
|
||||
groupIDs = filtered
|
||||
}
|
||||
items = append(items, userListItem{
|
||||
GroupIDs: memberships[user.ID],
|
||||
GroupIDs: groupIDs,
|
||||
ID: user.ID,
|
||||
Account: user.Account,
|
||||
Name: user.Name,
|
||||
@@ -298,7 +320,7 @@ func UserList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
ExternalEmailEnabled: user.ExternalEmailEnabled == 1,
|
||||
ExternalEmailConfigured: externalEmailConfigured[user.ID],
|
||||
})
|
||||
if ctx.EffectiveRole() == access.RoleSuperAdmin {
|
||||
if groupManager {
|
||||
items[len(items)-1].MembershipVersion = user.SecurityVersion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user