mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
0b012f2fa2
* update and delete project grants * fix: user grant id (#421) * fix: verboser logging on sql err (#412) * fix(eventstore): improve insert statement * fix: verbose logging on error * fix: simplify insertEvents * fix: project grant delete (#417) * fix: add grant id to user grant if needed * fix: add grant id to user grant if needed Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix user grant context * lint * role validators * fix: usergrantid (#424) * fix: verboser logging on sql err (#412) * fix(eventstore): improve insert statement * fix: verbose logging on error * fix: simplify insertEvents * fix: project grant delete (#417) * fix: add grant id to user grant if needed * fix: add grant id to user grant if needed * fix: add bulk remove * fix: merge Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package model
|
|
|
|
import es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
type UserGrant struct {
|
|
es_models.ObjectRoot
|
|
|
|
State UserGrantState
|
|
UserID string
|
|
ProjectID string
|
|
GrantID string
|
|
RoleKeys []string
|
|
}
|
|
|
|
type UserGrantState int32
|
|
|
|
const (
|
|
UserGrantStateActive UserGrantState = iota
|
|
UserGrantStateInactive
|
|
UserGrantStateRemoved
|
|
)
|
|
|
|
func (u *UserGrant) IsValid() bool {
|
|
return u.ProjectID != "" && u.UserID != ""
|
|
}
|
|
|
|
func (u *UserGrant) IsActive() bool {
|
|
return u.State == UserGrantStateActive
|
|
}
|
|
|
|
func (u *UserGrant) IsInactive() bool {
|
|
return u.State == UserGrantStateInactive
|
|
}
|
|
|
|
func (u *UserGrant) RemoveRoleKeyIfExisting(key string) bool {
|
|
for i, role := range u.RoleKeys {
|
|
if role == key {
|
|
u.RoleKeys[i] = u.RoleKeys[len(u.RoleKeys)-1]
|
|
u.RoleKeys[len(u.RoleKeys)-1] = ""
|
|
u.RoleKeys = u.RoleKeys[:len(u.RoleKeys)-1]
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (u *UserGrant) RemoveRoleKeysIfExisting(keys []string) bool {
|
|
exists := false
|
|
for _, key := range keys {
|
|
keyExists := u.RemoveRoleKeyIfExisting(key)
|
|
if keyExists {
|
|
exists = true
|
|
}
|
|
}
|
|
return exists
|
|
}
|