[#580] Fix user removal in astOperation

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-07-06 16:01:47 +03:00 committed by Alex Vanin
parent edc6aa2f88
commit 36029ca864
2 changed files with 7 additions and 9 deletions

View file

@ -751,14 +751,13 @@ func addUsers(resource *astResource, astO *astOperation, users []string) {
func removeUsers(resource *astResource, astOperation *astOperation, users []string) {
for _, astOp := range resource.Operations {
if astOp.Role == astOperation.Role && astOp.Op == astOperation.Op && astOp.Action == astOperation.Action {
ind := 0
filteredUsers := astOp.Users[:0] // new slice without allocation
for _, user := range astOp.Users {
if containsStr(users, user) {
astOp.Users = append(astOp.Users[:ind], astOp.Users[ind+1:]...)
} else {
ind++
if !containsStr(users, user) {
filteredUsers = append(filteredUsers, user)
}
}
astOp.Users = filteredUsers
return
}
}