When adding users to group drop duplicate users (#50)

This commit is contained in:
abin-rafay
2022-03-11 17:36:56 +05:30
committed by GitHub
parent 5429bf4493
commit bef3d9ed53
2 changed files with 14 additions and 1 deletions

View File

@@ -223,7 +223,7 @@ func (s *groupService) createGroupAccountRelations(ctx context.Context, groupId
// TODO: add transactions
var grpaccs []models.GroupAccount
var ugs []*authzv1.UserGroup
for _, account := range group.GetSpec().GetUsers() {
for _, account := range unique(group.GetSpec().GetUsers()) {
// FIXME: do combined lookup
entity, err := s.dao.GetIdByTraits(ctx, account, &models.KratosIdentities{})
if err != nil {

13
pkg/service/utils.go Normal file
View File

@@ -0,0 +1,13 @@
package service
func unique(items []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range items {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}