mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-27 09:42:16 +00:00
* feat: project role remove * feat: search queries * feat: search queries * feat: cascade remove/change project role * fix: comment in project grant * fix: remove projecr grant * fix: only search usergrants of my org * fix: delete usergrants * fix: delete usergrants * fix: check if role exists on project grant * feat: bulk add project role * fix: tests * fix: update user grants on project update * fix: return roles * feat: add resourceowner name on project grants * fix: migration number * fix: tests * fix: generate protos * fix: some unnecessary code
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
)
|
|
|
|
type ProjectGrant struct {
|
|
es_models.ObjectRoot
|
|
|
|
GrantID string
|
|
GrantedOrgID string
|
|
State ProjectGrantState
|
|
RoleKeys []string
|
|
Members []*ProjectGrantMember
|
|
}
|
|
|
|
type ProjectGrantIDs struct {
|
|
ProjectID string
|
|
GrantID string
|
|
}
|
|
|
|
type ProjectGrantState int32
|
|
|
|
const (
|
|
PROJECTGRANTSTATE_ACTIVE ProjectGrantState = iota
|
|
PROJECTGRANTSTATE_INACTIVE
|
|
)
|
|
|
|
func NewProjectGrant(projectID, grantID string) *ProjectGrant {
|
|
return &ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, GrantID: grantID, State: PROJECTGRANTSTATE_ACTIVE}
|
|
}
|
|
|
|
func (p *ProjectGrant) IsActive() bool {
|
|
return p.State == PROJECTGRANTSTATE_ACTIVE
|
|
}
|
|
|
|
func (p *ProjectGrant) IsValid() bool {
|
|
return p.GrantedOrgID != ""
|
|
}
|
|
|
|
func (p *ProjectGrant) GetMember(userID string) (int, *ProjectGrantMember) {
|
|
for i, m := range p.Members {
|
|
if m.UserID == userID {
|
|
return i, m
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func (p *ProjectGrant) GetRemovedRoles(roleKeys []string) []string {
|
|
removed := make([]string, 0)
|
|
for _, role := range p.RoleKeys {
|
|
if !containsKey(roleKeys, role) {
|
|
removed = append(removed, role)
|
|
}
|
|
}
|
|
return removed
|
|
}
|
|
|
|
func containsKey(roles []string, key string) bool {
|
|
for _, role := range roles {
|
|
if role == key {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|