refactor: cleanup unused code (#7130)

* refactor: drop unused code

* refactor: drop unused code
This commit is contained in:
Silvan
2024-01-02 15:26:31 +01:00
committed by GitHub
parent 4e3936b5bf
commit 9892fd92b6
109 changed files with 0 additions and 6282 deletions

View File

@@ -1,15 +1,8 @@
package model
import (
"fmt"
"strings"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/crypto"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/zerrors"
)
type APIConfig struct {
@@ -27,35 +20,3 @@ const (
APIAuthMethodTypeBasic APIAuthMethodType = iota
APIAuthMethodTypePrivateKeyJWT
)
func (c *APIConfig) IsValid() bool {
return true
}
// ClientID random_number@projectname (eg. 495894098234@zitadel)
func (c *APIConfig) GenerateNewClientID(idGenerator id.Generator, project *Project) error {
rndID, err := idGenerator.Next()
if err != nil {
return err
}
c.ClientID = fmt.Sprintf("%v@%v", rndID, strings.ReplaceAll(strings.ToLower(project.Name), " ", "_"))
return nil
}
func (c *APIConfig) GenerateClientSecretIfNeeded(generator crypto.Generator) (string, error) {
if c.AuthMethodType == APIAuthMethodTypeBasic {
return c.GenerateNewClientSecret(generator)
}
return "", nil
}
func (c *APIConfig) GenerateNewClientSecret(generator crypto.Generator) (string, error) {
cryptoValue, stringSecret, err := crypto.NewCode(generator)
if err != nil {
logging.Log("MODEL-ADvd2").OnError(err).Error("unable to create client secret")
return "", zerrors.ThrowInternal(err, "MODEL-dsvr43", "Errors.Project.CouldNotGenerateClientSecret")
}
c.ClientSecret = cryptoValue
return stringSecret, nil
}

View File

@@ -32,22 +32,3 @@ const (
AppTypeSAML
AppTypeAPI
)
func (a *Application) IsValid(includeConfig bool) bool {
if a.Name == "" || a.AggregateID == "" {
return false
}
if !includeConfig {
return true
}
if a.Type == AppTypeOIDC && !a.OIDCConfig.IsValid() {
return false
}
if a.Type == AppTypeAPI && !a.APIConfig.IsValid() {
return false
}
if a.Type == AppTypeSAML && !a.SAMLConfig.IsValid() {
return false
}
return true
}

View File

@@ -1,171 +0,0 @@
package model
import (
"testing"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
)
func TestApplicationValid(t *testing.T) {
type args struct {
app *Application
}
tests := []struct {
name string
args args
result bool
}{
{
name: "valid oidc application: responsetype code",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode},
},
},
},
result: true,
},
{
name: "invalid oidc application: responsetype code",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode},
GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit},
},
},
},
result: false,
},
{
name: "valid oidc application: responsetype id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit},
},
},
},
result: true,
},
{
name: "invalid oidc application: responsetype id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode},
},
},
},
result: false,
},
{
name: "valid oidc application: responsetype token_id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDTokenToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeImplicit},
},
},
},
result: true,
},
{
name: "invalid oidc application: responsetype token_id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeIDTokenToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode},
},
},
},
result: false,
},
{
name: "valid oidc application: responsetype code & id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeIDToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit},
},
},
},
result: true,
},
{
name: "valid oidc application: responsetype code & token_id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeIDTokenToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit},
},
},
},
result: true,
},
{
name: "valid oidc application: responsetype code & id_token & token_id_token",
args: args{
app: &Application{
ObjectRoot: models.ObjectRoot{AggregateID: "AggregateID"},
AppID: "AppID",
Name: "Name",
Type: AppTypeOIDC,
OIDCConfig: &OIDCConfig{
ResponseTypes: []OIDCResponseType{OIDCResponseTypeCode, OIDCResponseTypeIDToken, OIDCResponseTypeIDTokenToken},
GrantTypes: []OIDCGrantType{OIDCGrantTypeAuthorizationCode, OIDCGrantTypeImplicit},
},
},
},
result: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.args.app.IsValid(true)
if result != tt.result {
t.Errorf("got wrong result: expected: %v, actual: %v ", tt.result, result)
}
})
}
}

View File

@@ -1,17 +1,11 @@
package model
import (
"fmt"
"strings"
"time"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/domain"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/id"
"github.com/zitadel/zitadel/internal/zerrors"
)
type OIDCConfig struct {
@@ -97,49 +91,6 @@ type Token struct {
Scopes []string
}
func (c *OIDCConfig) IsValid() bool {
grantTypes := c.getRequiredGrantTypes()
for _, grantType := range grantTypes {
ok := containsOIDCGrantType(c.GrantTypes, grantType)
if !ok {
return false
}
}
return true
}
// ClientID random_number@projectname (eg. 495894098234@zitadel)
func (c *OIDCConfig) GenerateNewClientID(idGenerator id.Generator, project *Project) error {
rndID, err := idGenerator.Next()
if err != nil {
return err
}
c.ClientID = fmt.Sprintf("%v@%v", rndID, strings.ReplaceAll(strings.ToLower(project.Name), " ", "_"))
return nil
}
func (c *OIDCConfig) GenerateClientSecretIfNeeded(generator crypto.Generator) (string, error) {
if c.AuthMethodType == OIDCAuthMethodTypeBasic || c.AuthMethodType == OIDCAuthMethodTypePost {
return c.GenerateNewClientSecret(generator)
}
return "", nil
}
func (c *OIDCConfig) GenerateNewClientSecret(generator crypto.Generator) (string, error) {
cryptoValue, stringSecret, err := crypto.NewCode(generator)
if err != nil {
logging.Log("MODEL-UpnTI").OnError(err).Error("unable to create client secret")
return "", zerrors.ThrowInternal(err, "MODEL-gH2Wl", "Errors.Project.CouldNotGenerateClientSecret")
}
c.ClientSecret = cryptoValue
return stringSecret, nil
}
func (c *OIDCConfig) FillCompliance() {
c.Compliance = GetOIDCCompliance(c.OIDCVersion, c.ApplicationType, c.GrantTypes, c.ResponseTypes, c.AuthMethodType, c.RedirectUris)
}
func GetOIDCCompliance(version OIDCVersion, appType OIDCApplicationType, grantTypes []OIDCGrantType, responseTypes []OIDCResponseType, authMethod OIDCAuthMethodType, redirectUris []string) *Compliance {
switch version {
case OIDCVersionV1:
@@ -155,29 +106,3 @@ func GetOIDCCompliance(version OIDCVersion, appType OIDCApplicationType, grantTy
}
return nil
}
func (c *OIDCConfig) getRequiredGrantTypes() []OIDCGrantType {
grantTypes := make([]OIDCGrantType, 0)
implicit := false
for _, r := range c.ResponseTypes {
switch r {
case OIDCResponseTypeCode:
grantTypes = append(grantTypes, OIDCGrantTypeAuthorizationCode)
case OIDCResponseTypeIDToken, OIDCResponseTypeIDTokenToken:
if !implicit {
implicit = true
grantTypes = append(grantTypes, OIDCGrantTypeImplicit)
}
}
}
return grantTypes
}
func containsOIDCGrantType(grantTypes []OIDCGrantType, grantType OIDCGrantType) bool {
for _, gt := range grantTypes {
if gt == grantType {
return true
}
}
return false
}

View File

@@ -1,55 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
"time"
)
type OrgProjectMapping struct {
OrgID string
ProjectID string
}
type OrgProjectMappingViewSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn OrgProjectMappingViewSearchKey
Asc bool
Queries []*OrgProjectMappingViewSearchQuery
}
type OrgProjectMappingViewSearchKey int32
const (
OrgProjectMappingSearchKeyUnspecified OrgProjectMappingViewSearchKey = iota
OrgProjectMappingSearchKeyProjectID
OrgProjectMappingSearchKeyOrgID
OrgProjectMappingSearchKeyProjectGrantID
OrgProjectMappingSearchKeyInstanceID
OrgProjectMappingSearchKeyOwnerRemoved
)
type OrgProjectMappingViewSearchQuery struct {
Key OrgProjectMappingViewSearchKey
Method domain.SearchMethod
Value interface{}
}
type OrgProjectMappingViewSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*OrgProjectMapping
Sequence uint64
Timestamp time.Time
}
func (r *OrgProjectMappingViewSearchRequest) GetSearchQuery(key OrgProjectMappingViewSearchKey) (int, *OrgProjectMappingViewSearchQuery) {
for i, q := range r.Queries {
if q.Key == key {
return i, q
}
}
return -1, nil
}

View File

@@ -27,68 +27,3 @@ const (
ProjectStateInactive
ProjectStateRemoved
)
func (p *Project) IsActive() bool {
return p.State == ProjectStateActive
}
func (p *Project) IsValid() bool {
return p.Name != ""
}
func (p *Project) ContainsRole(role *ProjectRole) bool {
for _, r := range p.Roles {
if r.Key == role.Key {
return true
}
}
return false
}
func (p *Project) GetApp(appID string) (int, *Application) {
for i, a := range p.Applications {
if a.AppID == appID {
return i, a
}
}
return -1, nil
}
func (p *Project) GetGrant(grantID string) (int, *ProjectGrant) {
for i, g := range p.Grants {
if g.GrantID == grantID {
return i, g
}
}
return -1, nil
}
func (p *Project) ContainsGrantForOrg(orgID string) bool {
for _, g := range p.Grants {
if g.GrantedOrgID == orgID {
return true
}
}
return false
}
func (p *Project) ContainsRoles(roleKeys []string) bool {
for _, r := range roleKeys {
if !p.ContainsRole(&ProjectRole{Key: r}) {
return false
}
}
return true
}
func (p *Project) ContainsGrantMember(member *ProjectGrantMember) bool {
for _, g := range p.Grants {
if g.GrantID != member.GrantID {
continue
}
if _, m := g.GetMember(member.UserID); m != nil {
return true
}
}
return false
}

View File

@@ -14,54 +14,9 @@ type ProjectGrant struct {
Members []*ProjectGrantMember
}
type ProjectGrantIDs struct {
ProjectID string
GrantID string
}
type ProjectGrantState int32
const (
ProjectGrantStateActive ProjectGrantState = iota
ProjectGrantStateInactive
)
func NewProjectGrant(projectID, grantID string) *ProjectGrant {
return &ProjectGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, GrantID: grantID, State: ProjectGrantStateActive}
}
func (p *ProjectGrant) IsActive() bool {
return p.State == ProjectGrantStateActive
}
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
}

View File

@@ -8,11 +8,3 @@ type ProjectGrantMember struct {
UserID string
Roles []string
}
func NewProjectGrantMember(projectID, grantID, userID string) *ProjectGrantMember {
return &ProjectGrantMember{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, GrantID: grantID, UserID: userID}
}
func (p *ProjectGrantMember) IsValid() bool {
return p.AggregateID != "" && p.UserID != "" && len(p.Roles) != 0
}

View File

@@ -1,72 +0,0 @@
package model
import (
"time"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/zerrors"
)
type ProjectGrantMemberView struct {
UserID string
GrantID string
ProjectID string
UserName string
Email string
FirstName string
LastName string
DisplayName string
PreferredLoginName string
AvatarURL string
UserResourceOwner string
Roles []string
CreationDate time.Time
ChangeDate time.Time
Sequence uint64
}
type ProjectGrantMemberSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn ProjectGrantMemberSearchKey
Asc bool
Queries []*ProjectGrantMemberSearchQuery
}
type ProjectGrantMemberSearchKey int32
const (
ProjectGrantMemberSearchKeyUnspecified ProjectGrantMemberSearchKey = iota
ProjectGrantMemberSearchKeyUserName
ProjectGrantMemberSearchKeyEmail
ProjectGrantMemberSearchKeyFirstName
ProjectGrantMemberSearchKeyLastName
ProjectGrantMemberSearchKeyGrantID
ProjectGrantMemberSearchKeyUserID
ProjectGrantMemberSearchKeyProjectID
)
type ProjectGrantMemberSearchQuery struct {
Key ProjectGrantMemberSearchKey
Method domain.SearchMethod
Value interface{}
}
type ProjectGrantMemberSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*ProjectGrantMemberView
Sequence uint64
Timestamp time.Time
}
func (r *ProjectGrantMemberSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return zerrors.ThrowInvalidArgument(nil, "SEARCH-ZT8df", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}

View File

@@ -1,90 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/zerrors"
"time"
)
type ProjectGrantView struct {
ProjectID string
Name string
CreationDate time.Time
ChangeDate time.Time
State ProjectState
ResourceOwner string
ResourceOwnerName string
OrgID string
OrgName string
OrgDomain string
Sequence uint64
GrantID string
GrantedRoleKeys []string
}
type ProjectGrantViewSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn ProjectGrantViewSearchKey
Asc bool
Queries []*ProjectGrantViewSearchQuery
}
type ProjectGrantViewSearchKey int32
const (
GrantedProjectSearchKeyUnspecified ProjectGrantViewSearchKey = iota
GrantedProjectSearchKeyName
GrantedProjectSearchKeyProjectID
GrantedProjectSearchKeyGrantID
GrantedProjectSearchKeyOrgID
GrantedProjectSearchKeyResourceOwner
GrantedProjectSearchKeyRoleKeys
)
type ProjectGrantViewSearchQuery struct {
Key ProjectGrantViewSearchKey
Method domain.SearchMethod
Value interface{}
}
type ProjectGrantViewSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*ProjectGrantView
Sequence uint64
Timestamp time.Time
}
func (r *ProjectGrantViewSearchRequest) GetSearchQuery(key ProjectGrantViewSearchKey) (int, *ProjectGrantViewSearchQuery) {
for i, q := range r.Queries {
if q.Key == key {
return i, q
}
}
return -1, nil
}
func (r *ProjectGrantViewSearchRequest) AppendMyOrgQuery(orgID string) {
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: orgID})
}
func (r *ProjectGrantViewSearchRequest) AppendNotMyOrgQuery(orgID string) {
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodNotEquals, Value: orgID})
}
func (r *ProjectGrantViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) {
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID})
}
func (r *ProjectGrantViewSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return zerrors.ThrowInvalidArgument(nil, "SEARCH-0fj3s", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}

View File

@@ -8,11 +8,3 @@ type ProjectMember struct {
UserID string
Roles []string
}
func NewProjectMember(projectID, userID string) *ProjectMember {
return &ProjectMember{ObjectRoot: es_models.ObjectRoot{AggregateID: projectID}, UserID: userID}
}
func (p *ProjectMember) IsValid() bool {
return p.AggregateID != "" && p.UserID != "" && len(p.Roles) != 0
}

View File

@@ -1,73 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/zerrors"
"time"
)
type ProjectMemberView struct {
UserID string
ProjectID string
UserName string
Email string
FirstName string
LastName string
DisplayName string
PreferredLoginName string
AvatarURL string
UserResourceOwner string
Roles []string
CreationDate time.Time
ChangeDate time.Time
Sequence uint64
}
type ProjectMemberSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn ProjectMemberSearchKey
Asc bool
Queries []*ProjectMemberSearchQuery
}
type ProjectMemberSearchKey int32
const (
ProjectMemberSearchKeyUnspecified ProjectMemberSearchKey = iota
ProjectMemberSearchKeyUserName
ProjectMemberSearchKeyEmail
ProjectMemberSearchKeyFirstName
ProjectMemberSearchKeyLastName
ProjectMemberSearchKeyProjectID
ProjectMemberSearchKeyUserID
)
type ProjectMemberSearchQuery struct {
Key ProjectMemberSearchKey
Method domain.SearchMethod
Value interface{}
}
type ProjectMemberSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*ProjectMemberView
Sequence uint64
Timestamp time.Time
}
func (r *ProjectMemberSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return zerrors.ThrowInvalidArgument(nil, "SEARCH-389Nd", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}
func (r *ProjectMemberSearchRequest) AppendProjectQuery(projectID string) {
r.Queries = append(r.Queries, &ProjectMemberSearchQuery{Key: ProjectMemberSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID})
}

View File

@@ -9,7 +9,3 @@ type ProjectRole struct {
DisplayName string
Group string
}
func (p *ProjectRole) IsValid() bool {
return p.AggregateID != "" && p.Key != ""
}

View File

@@ -1,75 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/zerrors"
"time"
)
type ProjectRoleView struct {
ResourceOwner string
OrgID string
ProjectID string
Key string
DisplayName string
Group string
CreationDate time.Time
ChangeDate time.Time
Sequence uint64
}
type ProjectRoleSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn ProjectRoleSearchKey
Asc bool
Queries []*ProjectRoleSearchQuery
}
type ProjectRoleSearchKey int32
const (
ProjectRoleSearchKeyUnspecified ProjectRoleSearchKey = iota
ProjectRoleSearchKeyKey
ProjectRoleSearchKeyProjectID
ProjectRoleSearchKeyOrgID
ProjectRoleSearchKeyResourceOwner
ProjectRoleSearchKeyDisplayName
)
type ProjectRoleSearchQuery struct {
Key ProjectRoleSearchKey
Method domain.SearchMethod
Value interface{}
}
type ProjectRoleSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*ProjectRoleView
Sequence uint64
Timestamp time.Time
}
func (r *ProjectRoleSearchRequest) AppendMyOrgQuery(orgID string) {
r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: orgID})
}
func (r *ProjectRoleSearchRequest) AppendProjectQuery(projectID string) {
r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyProjectID, Method: domain.SearchMethodEquals, Value: projectID})
}
func (r *ProjectRoleSearchRequest) AppendRoleKeysQuery(keys []string) {
r.Queries = append(r.Queries, &ProjectRoleSearchQuery{Key: ProjectRoleSearchKeyKey, Method: domain.SearchMethodIsOneOf, Value: keys})
}
func (r *ProjectRoleSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return zerrors.ThrowInvalidArgument(nil, "SEARCH-92hNf", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}

View File

@@ -1,77 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/zerrors"
"time"
)
type ProjectView struct {
ProjectID string
Name string
CreationDate time.Time
ChangeDate time.Time
State ProjectState
ResourceOwner string
ProjectRoleAssertion bool
ProjectRoleCheck bool
HasProjectCheck bool
PrivateLabelingSetting domain.PrivateLabelingSetting
Sequence uint64
}
type ProjectViewSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn ProjectViewSearchKey
Asc bool
Queries []*ProjectViewSearchQuery
}
type ProjectViewSearchKey int32
const (
ProjectViewSearchKeyUnspecified ProjectViewSearchKey = iota
ProjectViewSearchKeyName
ProjectViewSearchKeyProjectID
ProjectViewSearchKeyResourceOwner
)
type ProjectViewSearchQuery struct {
Key ProjectViewSearchKey
Method domain.SearchMethod
Value interface{}
}
type ProjectViewSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*ProjectView
Sequence uint64
Timestamp time.Time
}
func (r *ProjectViewSearchRequest) GetSearchQuery(key ProjectViewSearchKey) (int, *ProjectViewSearchQuery) {
for i, q := range r.Queries {
if q.Key == key {
return i, q
}
}
return -1, nil
}
func (r *ProjectViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) {
r.Queries = append(r.Queries, &ProjectViewSearchQuery{Key: ProjectViewSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID})
}
func (r *ProjectViewSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return zerrors.ThrowInvalidArgument(nil, "SEARCH-2M0ds", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}

View File

@@ -10,7 +10,3 @@ type SAMLConfig struct {
Metadata []byte
MetadataURL string
}
func (c *SAMLConfig) IsValid() bool {
return !(c.Metadata == nil && c.MetadataURL == "")
}

View File

@@ -1,231 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/zitadel/logging"
http_util "github.com/zitadel/zitadel/internal/api/http"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
ApplicationKeyID = "id"
ApplicationKeyProjectID = "project_id"
ApplicationKeyResourceOwner = "resource_owner"
ApplicationKeyOIDCClientID = "oidc_client_id"
ApplicationKeyName = "app_name"
)
type ApplicationView struct {
ID string `json:"appId" gorm:"column:id;primary_key"`
ProjectID string `json:"-" gorm:"column:project_id"`
Name string `json:"name" gorm:"column:app_name"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
State int32 `json:"-" gorm:"column:app_state"`
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
ProjectRoleAssertion bool `json:"projectRoleAssertion" gorm:"column:project_role_assertion"`
ProjectRoleCheck bool `json:"projectRoleCheck" gorm:"column:project_role_check"`
HasProjectCheck bool `json:"hasProjectCheck" gorm:"column:has_project_check"`
PrivateLabelingSetting domain.PrivateLabelingSetting `json:"privateLabelingSetting" gorm:"column:private_labeling_setting"`
IsOIDC bool `json:"-" gorm:"column:is_oidc"`
OIDCVersion int32 `json:"oidcVersion" gorm:"column:oidc_version"`
OIDCClientID string `json:"clientId" gorm:"column:oidc_client_id"`
OIDCRedirectUris database.TextArray[string] `json:"redirectUris" gorm:"column:oidc_redirect_uris"`
OIDCResponseTypes database.Array[domain.OIDCResponseType] `json:"responseTypes" gorm:"column:oidc_response_types"`
OIDCGrantTypes database.Array[domain.OIDCGrantType] `json:"grantTypes" gorm:"column:oidc_grant_types"`
OIDCApplicationType int32 `json:"applicationType" gorm:"column:oidc_application_type"`
OIDCAuthMethodType int32 `json:"authMethodType" gorm:"column:oidc_auth_method_type"`
OIDCPostLogoutRedirectUris database.TextArray[string] `json:"postLogoutRedirectUris" gorm:"column:oidc_post_logout_redirect_uris"`
NoneCompliant bool `json:"-" gorm:"column:none_compliant"`
ComplianceProblems database.TextArray[string] `json:"-" gorm:"column:compliance_problems"`
DevMode bool `json:"devMode" gorm:"column:dev_mode"`
OriginAllowList database.TextArray[string] `json:"-" gorm:"column:origin_allow_list"`
AdditionalOrigins database.TextArray[string] `json:"additionalOrigins" gorm:"column:additional_origins"`
AccessTokenType int32 `json:"accessTokenType" gorm:"column:access_token_type"`
AccessTokenRoleAssertion bool `json:"accessTokenRoleAssertion" gorm:"column:access_token_role_assertion"`
IDTokenRoleAssertion bool `json:"idTokenRoleAssertion" gorm:"column:id_token_role_assertion"`
IDTokenUserinfoAssertion bool `json:"idTokenUserinfoAssertion" gorm:"column:id_token_userinfo_assertion"`
ClockSkew time.Duration `json:"clockSkew" gorm:"column:clock_skew"`
IsSAML bool `json:"-" gorm:"column:is_saml"`
Metadata []byte `json:"metadata" gorm:"column:metadata"`
MetadataURL string `json:"metadata_url" gorm:"column:metadata_url"`
Sequence uint64 `json:"-" gorm:"sequence"`
}
func OIDCResponseTypesToModel(oidctypes []domain.OIDCResponseType) []model.OIDCResponseType {
result := make([]model.OIDCResponseType, len(oidctypes))
for i, t := range oidctypes {
result[i] = model.OIDCResponseType(t)
}
return result
}
func OIDCGrantTypesToModel(granttypes []domain.OIDCGrantType) []model.OIDCGrantType {
result := make([]model.OIDCGrantType, len(granttypes))
for i, t := range granttypes {
result[i] = model.OIDCGrantType(t)
}
return result
}
func (a *ApplicationView) AppendEventIfMyApp(event *models.Event) (err error) {
view := new(ApplicationView)
switch event.Type() {
case project.ApplicationAddedType:
err = view.SetData(event)
if err != nil {
return err
}
case project.ApplicationChangedType,
project.OIDCConfigAddedType,
project.OIDCConfigChangedType,
project.APIConfigAddedType,
project.APIConfigChangedType,
project.ApplicationDeactivatedType,
project.ApplicationReactivatedType,
project.SAMLConfigAddedType,
project.SAMLConfigChangedType:
err = view.SetData(event)
if err != nil {
return err
}
case project.ApplicationRemovedType:
err = view.SetData(event)
if err != nil {
return err
}
case project.ProjectChangedType:
return a.AppendEvent(event)
case project.ProjectRemovedType:
return a.AppendEvent(event)
default:
return nil
}
if view.ID == a.ID {
return a.AppendEvent(event)
}
return nil
}
func (a *ApplicationView) AppendEvent(event *models.Event) (err error) {
a.Sequence = event.Seq
a.ChangeDate = event.CreationDate
switch event.Type() {
case project.ApplicationAddedType:
a.setRootData(event)
a.CreationDate = event.CreationDate
a.ResourceOwner = event.ResourceOwner
err = a.SetData(event)
case project.OIDCConfigAddedType:
a.IsOIDC = true
err = a.SetData(event)
if err != nil {
return err
}
a.setCompliance()
return a.setOriginAllowList()
case project.SAMLConfigAddedType:
a.IsSAML = true
return a.SetData(event)
case project.APIConfigAddedType:
a.IsOIDC = false
return a.SetData(event)
case project.ApplicationChangedType:
return a.SetData(event)
case project.OIDCConfigChangedType:
err = a.SetData(event)
if err != nil {
return err
}
a.setCompliance()
return a.setOriginAllowList()
case project.SAMLConfigChangedType:
return a.SetData(event)
case project.APIConfigChangedType:
return a.SetData(event)
case project.ProjectChangedType:
return a.setProjectChanges(event)
case project.ApplicationDeactivatedType:
a.State = int32(model.AppStateInactive)
case project.ApplicationReactivatedType:
a.State = int32(model.AppStateActive)
case project.ApplicationRemovedType, project.ProjectRemovedType:
a.State = int32(model.AppStateRemoved)
}
return err
}
func (a *ApplicationView) setRootData(event *models.Event) {
a.ProjectID = event.AggregateID
}
func (a *ApplicationView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, a); err != nil {
logging.Log("EVEN-lo9ds").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-8suie", "Could not unmarshal data")
}
return nil
}
func (a *ApplicationView) setOriginAllowList() error {
allowList := make(database.TextArray[string], 0)
for _, redirect := range a.OIDCRedirectUris {
origin, err := http_util.GetOriginFromURLString(redirect)
if err != nil {
return err
}
if !http_util.IsOriginAllowed(allowList, origin) {
allowList = append(allowList, origin)
}
}
for _, origin := range a.AdditionalOrigins {
if !http_util.IsOriginAllowed(allowList, origin) {
allowList = append(allowList, origin)
}
}
a.OriginAllowList = allowList
return nil
}
func (a *ApplicationView) setCompliance() {
compliance := model.GetOIDCCompliance(model.OIDCVersion(a.OIDCVersion), model.OIDCApplicationType(a.OIDCApplicationType), OIDCGrantTypesToModel(a.OIDCGrantTypes), OIDCResponseTypesToModel(a.OIDCResponseTypes), model.OIDCAuthMethodType(a.OIDCAuthMethodType), a.OIDCRedirectUris)
a.NoneCompliant = compliance.NoneCompliant
a.ComplianceProblems = compliance.Problems
}
func (a *ApplicationView) setProjectChanges(event *models.Event) error {
changes := struct {
ProjectRoleAssertion *bool `json:"projectRoleAssertion,omitempty"`
ProjectRoleCheck *bool `json:"projectRoleCheck,omitempty"`
HasProjectCheck *bool `json:"hasProjectCheck,omitempty"`
PrivateLabelingSetting *domain.PrivateLabelingSetting `json:"privateLabelingSetting,omitempty"`
}{}
if err := json.Unmarshal(event.Data, &changes); err != nil {
logging.Log("EVEN-DFbfg").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-Bw221", "Could not unmarshal data")
}
if changes.ProjectRoleAssertion != nil {
a.ProjectRoleAssertion = *changes.ProjectRoleAssertion
}
if changes.ProjectRoleCheck != nil {
a.ProjectRoleCheck = *changes.ProjectRoleCheck
}
if changes.HasProjectCheck != nil {
a.HasProjectCheck = *changes.HasProjectCheck
}
if changes.PrivateLabelingSetting != nil {
a.PrivateLabelingSetting = *changes.PrivateLabelingSetting
}
return nil
}

View File

@@ -1,102 +0,0 @@
package model
import (
"encoding/json"
"testing"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func mockAppData(app *es_model.Application) []byte {
data, _ := json.Marshal(app)
return data
}
func mockOIDCConfigData(config *es_model.OIDCConfig) []byte {
data, _ := json.Marshal(config)
return data
}
func TestApplicationAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
app *ApplicationView
}
tests := []struct {
name string
args args
result *ApplicationView
}{
{
name: "append added app event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationAddedType, Data: mockAppData(&es_model.Application{Name: "AppName"})},
app: &ApplicationView{},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
},
{
name: "append changed app event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationChangedType, Data: mockAppData(&es_model.Application{Name: "AppNameChanged"})},
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppNameChanged", State: int32(model.AppStateActive)},
},
{
name: "append deactivate app event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationDeactivatedType},
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)},
},
{
name: "append reactivate app event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ApplicationReactivatedType},
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateInactive)},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
},
{
name: "append added oidc config event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientID"})},
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", State: int32(model.AppStateActive)},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientID", State: int32(model.AppStateActive)},
},
{
name: "append changed oidc config event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.OIDCConfigAddedType, Data: mockOIDCConfigData(&es_model.OIDCConfig{ClientID: "clientIDChanged"})},
app: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", OIDCClientID: "clientID", State: int32(model.AppStateActive)},
},
result: &ApplicationView{ProjectID: "AggregateID", Name: "AppName", IsOIDC: true, OIDCClientID: "clientIDChanged", State: int32(model.AppStateActive)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.app.AppendEvent(tt.args.event)
if tt.args.app.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.app.ProjectID)
}
if tt.args.app.Name != tt.result.Name {
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, tt.args.app.Name)
}
if tt.args.app.State != tt.result.State {
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.State, tt.args.app.State)
}
if tt.args.app.IsOIDC != tt.result.IsOIDC {
t.Errorf("got wrong result IsOIDC: expected: %v, actual: %v ", tt.result.IsOIDC, tt.args.app.IsOIDC)
}
if tt.args.app.OIDCClientID != tt.result.OIDCClientID {
t.Errorf("got wrong result OIDCClientID: expected: %v, actual: %v ", tt.result.OIDCClientID, tt.args.app.OIDCClientID)
}
})
}
}

View File

@@ -1,16 +0,0 @@
package model
const (
OrgProjectMappingKeyProjectID = "project_id"
OrgProjectMappingKeyOrgID = "org_id"
OrgProjectMappingKeyProjectGrantID = "project_grant_id"
OrgProjectMappingKeyInstanceID = "instance_id"
OrgProjectMappingOwnerRemoved = "owner_removed"
)
type OrgProjectMapping struct {
ProjectID string `json:"-" gorm:"column:project_id;primary_key"`
OrgID string `json:"-" gorm:"column:org_id;primary_key"`
ProjectGrantID string `json:"-" gorm:"column:project_grant_id"`
InstanceID string `json:"instanceID" gorm:"column:instance_id"`
}

View File

@@ -1,67 +0,0 @@
package model
import (
"github.com/zitadel/zitadel/internal/domain"
proj_model "github.com/zitadel/zitadel/internal/project/model"
"github.com/zitadel/zitadel/internal/view/repository"
)
type OrgProjectMappingSearchRequest proj_model.OrgProjectMappingViewSearchRequest
type OrgProjectMappingSearchQuery proj_model.OrgProjectMappingViewSearchQuery
type OrgProjectMappingSearchKey proj_model.OrgProjectMappingViewSearchKey
func (req OrgProjectMappingSearchRequest) GetLimit() uint64 {
return req.Limit
}
func (req OrgProjectMappingSearchRequest) GetOffset() uint64 {
return req.Offset
}
func (req OrgProjectMappingSearchRequest) GetSortingColumn() repository.ColumnKey {
if req.SortingColumn == proj_model.OrgProjectMappingSearchKeyUnspecified {
return nil
}
return OrgProjectMappingSearchKey(req.SortingColumn)
}
func (req OrgProjectMappingSearchRequest) GetAsc() bool {
return req.Asc
}
func (req OrgProjectMappingSearchRequest) GetQueries() []repository.SearchQuery {
result := make([]repository.SearchQuery, len(req.Queries))
for i, q := range req.Queries {
result[i] = OrgProjectMappingSearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
}
return result
}
func (req OrgProjectMappingSearchQuery) GetKey() repository.ColumnKey {
return OrgProjectMappingSearchKey(req.Key)
}
func (req OrgProjectMappingSearchQuery) GetMethod() domain.SearchMethod {
return req.Method
}
func (req OrgProjectMappingSearchQuery) GetValue() interface{} {
return req.Value
}
func (key OrgProjectMappingSearchKey) ToColumnName() string {
switch proj_model.OrgProjectMappingViewSearchKey(key) {
case proj_model.OrgProjectMappingSearchKeyOrgID:
return OrgProjectMappingKeyOrgID
case proj_model.OrgProjectMappingSearchKeyProjectID:
return OrgProjectMappingKeyProjectID
case proj_model.OrgProjectMappingSearchKeyProjectGrantID:
return OrgProjectMappingKeyProjectGrantID
case proj_model.OrgProjectMappingSearchKeyInstanceID:
return OrgProjectMappingKeyInstanceID
case proj_model.OrgProjectMappingSearchKeyOwnerRemoved:
return OrgProjectMappingOwnerRemoved
default:
return ""
}
}

View File

@@ -1,81 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
ProjectKeyProjectID = "project_id"
ProjectKeyResourceOwner = "resource_owner"
ProjectKeyName = "project_name"
)
type ProjectView struct {
ProjectID string `json:"-" gorm:"column:project_id;primary_key"`
Name string `json:"name" gorm:"column:project_name"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
State int32 `json:"-" gorm:"column:project_state"`
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
ProjectRoleAssertion bool `json:"projectRoleAssertion" gorm:"column:project_role_assertion"`
ProjectRoleCheck bool `json:"projectRoleCheck" gorm:"column:project_role_check"`
HasProjectCheck bool `json:"hasProjectCheck" gorm:"column:has_project_check"`
PrivateLabelingSetting domain.PrivateLabelingSetting `json:"privateLabelingSetting" gorm:"column:private_labeling_setting"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
}
func (p *ProjectView) AppendEvent(event *models.Event) (err error) {
p.ChangeDate = event.CreationDate
p.Sequence = event.Seq
switch event.Type() {
case project.ProjectAddedType:
p.State = int32(model.ProjectStateActive)
p.CreationDate = event.CreationDate
p.setRootData(event)
err = p.setData(event)
case project.ProjectChangedType:
err = p.setData(event)
case project.ProjectDeactivatedType:
p.State = int32(model.ProjectStateInactive)
case project.ProjectReactivatedType:
p.State = int32(model.ProjectStateActive)
case project.ProjectRemovedType:
p.State = int32(model.ProjectStateRemoved)
}
return err
}
func (p *ProjectView) setRootData(event *models.Event) {
p.ProjectID = event.AggregateID
p.ResourceOwner = event.ResourceOwner
}
func (p *ProjectView) setData(event *models.Event) error {
if err := json.Unmarshal(event.Data, p); err != nil {
logging.Log("EVEN-dlo92").WithError(err).Error("could not unmarshal event data")
return err
}
return nil
}
func (p *ProjectView) setProjectData(event *models.Event) error {
project := new(ProjectView)
return project.SetData(event)
}
func (p *ProjectView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, p); err != nil {
logging.Log("EVEN-sk9Sj").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-s9ols", "Could not unmarshal data")
}
return nil
}

View File

@@ -1,99 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
ProjectGrantKeyProjectID = "project_id"
ProjectGrantKeyGrantID = "grant_id"
ProjectGrantKeyOrgID = "org_id"
ProjectGrantKeyResourceOwner = "resource_owner"
ProjectGrantKeyName = "project_name"
ProjectGrantKeyRoleKeys = "granted_role_keys"
)
type ProjectGrantView struct {
GrantID string `json:"-" gorm:"column:grant_id;primary_key"`
ProjectID string `json:"-" gorm:"column:project_id"`
OrgID string `json:"-" gorm:"column:org_id"`
Name string `json:"name" gorm:"column:project_name"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
State int32 `json:"-" gorm:"column:project_state"`
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
ResourceOwnerName string `json:"-" gorm:"column:resource_owner_name"`
OrgName string `json:"-" gorm:"column:org_name"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
GrantedRoleKeys database.TextArray[string] `json:"-" gorm:"column:granted_role_keys"`
}
type ProjectGrant struct {
GrantID string `json:"grantId"`
GrantedOrgID string `json:"grantedOrgId"`
RoleKeys []string `json:"roleKeys"`
InstanceID string `json:"instanceID"`
}
func (p *ProjectGrantView) AppendEvent(event *models.Event) (err error) {
p.ChangeDate = event.CreationDate
p.Sequence = event.Seq
switch event.Type() {
case project.GrantAddedType:
p.State = int32(model.ProjectStateActive)
p.CreationDate = event.CreationDate
p.setRootData(event)
err = p.setProjectGrantData(event)
case project.GrantChangedType, project.GrantCascadeChangedType:
err = p.setProjectGrantData(event)
case project.GrantDeactivatedType:
p.State = int32(model.ProjectStateInactive)
case project.GrantReactivatedType:
p.State = int32(model.ProjectStateActive)
}
return err
}
func (p *ProjectGrantView) setRootData(event *models.Event) {
p.ProjectID = event.AggregateID
p.ResourceOwner = event.ResourceOwner
}
func (p *ProjectGrantView) setData(event *models.Event) error {
if err := json.Unmarshal(event.Data, p); err != nil {
logging.Log("EVEN-dlo92").WithError(err).Error("could not unmarshal event data")
return err
}
return nil
}
func (p *ProjectGrantView) setProjectGrantData(event *models.Event) error {
grant := new(ProjectGrant)
err := grant.SetData(event)
if err != nil {
return err
}
if grant.GrantedOrgID != "" {
p.OrgID = grant.GrantedOrgID
}
p.GrantID = grant.GrantID
p.GrantedRoleKeys = grant.RoleKeys
return nil
}
func (p *ProjectGrant) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, p); err != nil {
logging.Log("EVEN-dlo92").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-s9ols", "Could not unmarshal data")
}
return nil
}

View File

@@ -1,68 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
ProjectGrantMemberKeyUserID = "user_id"
ProjectGrantMemberKeyGrantID = "grant_id"
ProjectGrantMemberKeyProjectID = "project_id"
ProjectGrantMemberKeyUserName = "user_name"
ProjectGrantMemberKeyEmail = "email"
ProjectGrantMemberKeyFirstName = "first_name"
ProjectGrantMemberKeyLastName = "last_name"
)
type ProjectGrantMemberView struct {
UserID string `json:"userId" gorm:"column:user_id;primary_key"`
GrantID string `json:"grantId" gorm:"column:grant_id;primary_key"`
ProjectID string `json:"-" gorm:"column:project_id"`
UserName string `json:"-" gorm:"column:user_name"`
Email string `json:"-" gorm:"column:email_address"`
FirstName string `json:"-" gorm:"column:first_name"`
LastName string `json:"-" gorm:"column:last_name"`
DisplayName string `json:"-" gorm:"column:display_name"`
Roles database.TextArray[string] `json:"roles" gorm:"column:roles"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
PreferredLoginName string `json:"-" gorm:"column:preferred_login_name"`
AvatarKey string `json:"-" gorm:"column:avatar_key"`
UserResourceOwner string `json:"-" gorm:"column:user_resource_owner"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
}
func (r *ProjectGrantMemberView) AppendEvent(event *models.Event) (err error) {
r.Sequence = event.Seq
r.ChangeDate = event.CreationDate
switch event.Type() {
case project.GrantMemberAddedType:
r.setRootData(event)
r.CreationDate = event.CreationDate
err = r.SetData(event)
case project.GrantMemberChangedType:
err = r.SetData(event)
}
return err
}
func (r *ProjectGrantMemberView) setRootData(event *models.Event) {
r.ProjectID = event.AggregateID
}
func (r *ProjectGrantMemberView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-slo9s").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-0plew", "Could not unmarshal data")
}
return nil
}

View File

@@ -1,62 +0,0 @@
package model
import (
"encoding/json"
"reflect"
"testing"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func mockProjectGrantMemberData(member *es_model.ProjectGrantMember) []byte {
data, _ := json.Marshal(member)
return data
}
func TestGrantedProjectMemberAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
member *ProjectGrantMemberView
}
tests := []struct {
name string
args args
result *ProjectGrantMemberView
}{
{
name: "append added member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantMemberAddedType, ResourceOwner: "OrgID", Data: mockProjectGrantMemberData(&es_model.ProjectGrantMember{GrantID: "ProjectGrantID", UserID: "UserID", Roles: []string{"Role"}})},
member: &ProjectGrantMemberView{},
},
result: &ProjectGrantMemberView{ProjectID: "AggregateID", UserID: "UserID", GrantID: "ProjectGrantID", Roles: []string{"Role"}},
},
{
name: "append changed member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantMemberAddedType, ResourceOwner: "OrgID", Data: mockProjectGrantMemberData(&es_model.ProjectGrantMember{GrantID: "ProjectGrantID", Roles: []string{"RoleChanged"}})},
member: &ProjectGrantMemberView{ProjectID: "AggregateID", UserID: "UserID", GrantID: "ProjectGrantID", Roles: []string{"Role"}},
},
result: &ProjectGrantMemberView{ProjectID: "AggregateID", UserID: "UserID", GrantID: "ProjectGrantID", Roles: []string{"RoleChanged"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.member.AppendEvent(tt.args.event)
if tt.args.member.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.member.ProjectID)
}
if tt.args.member.UserID != tt.result.UserID {
t.Errorf("got wrong result userID: expected: %v, actual: %v ", tt.result.UserID, tt.args.member.UserID)
}
if tt.args.member.GrantID != tt.result.GrantID {
t.Errorf("got wrong result ProjectGrantID: expected: %v, actual: %v ", tt.result.GrantID, tt.args.member.GrantID)
}
if !reflect.DeepEqual(tt.args.member.Roles, tt.result.Roles) {
t.Errorf("got wrong result Roles: expected: %v, actual: %v ", tt.result.Roles, tt.args.member.Roles)
}
})
}
}

View File

@@ -1,90 +0,0 @@
package model
import (
"encoding/json"
"reflect"
"testing"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func mockProjectData(project *es_model.Project) []byte {
data, _ := json.Marshal(project)
return data
}
func mockProjectGrantData(grant *es_model.ProjectGrant) []byte {
data, _ := json.Marshal(grant)
return data
}
func TestProjectGrantAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
project *ProjectGrantView
}
tests := []struct {
name string
args args
result *ProjectGrantView
}{
{
name: "append added project grant event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantAddedType, ResourceOwner: "GrantedOrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "ProjectGrantID", GrantedOrgID: "GrantedOrgID", RoleKeys: []string{"Role"}})},
project: &ProjectGrantView{},
},
result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: []string{"Role"}},
},
{
name: "append change project grant event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantChangedType, ResourceOwner: "GrantedOrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "ProjectGrantID", RoleKeys: []string{"RoleChanged"}})},
project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: []string{"Role"}},
},
result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: []string{"RoleChanged"}},
},
{
name: "append deactivate project grant event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantDeactivatedType, ResourceOwner: "GrantedOrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "ProjectGrantID"})},
project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: []string{"Role"}},
},
result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateInactive), GrantedRoleKeys: []string{"Role"}},
},
{
name: "append reactivate project grant event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.GrantReactivatedType, ResourceOwner: "GrantedOrgID", Data: mockProjectGrantData(&es_model.ProjectGrant{GrantID: "ProjectGrantID"})},
project: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateInactive), GrantedRoleKeys: []string{"Role"}},
},
result: &ProjectGrantView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", OrgID: "GrantedOrgID", State: int32(model.ProjectStateActive), GrantedRoleKeys: []string{"Role"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.project.AppendEvent(tt.args.event)
if tt.args.project.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.project.ProjectID)
}
if tt.args.project.OrgID != tt.result.OrgID {
t.Errorf("got wrong result orgID: expected: %v, actual: %v ", tt.result.OrgID, tt.args.project.OrgID)
}
if tt.args.project.ResourceOwner != tt.result.ResourceOwner {
t.Errorf("got wrong result ResourceOwner: expected: %v, actual: %v ", tt.result.ResourceOwner, tt.args.project.ResourceOwner)
}
if tt.args.project.Name != tt.result.Name {
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, tt.args.project.Name)
}
if tt.args.project.State != tt.result.State {
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.State, tt.args.project.State)
}
if !reflect.DeepEqual(tt.args.project.GrantedRoleKeys, tt.result.GrantedRoleKeys) {
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.GrantedRoleKeys, tt.args.project.GrantedRoleKeys)
}
})
}
}

View File

@@ -1,66 +0,0 @@
package model
import (
"encoding/json"
"time"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/zerrors"
)
const (
ProjectMemberKeyUserID = "user_id"
ProjectMemberKeyProjectID = "project_id"
ProjectMemberKeyUserName = "user_name"
ProjectMemberKeyEmail = "email"
ProjectMemberKeyFirstName = "first_name"
ProjectMemberKeyLastName = "last_name"
)
type ProjectMemberView struct {
UserID string `json:"userId" gorm:"column:user_id;primary_key"`
ProjectID string `json:"-" gorm:"column:project_id;primary_key"`
UserName string `json:"-" gorm:"column:user_name"`
Email string `json:"-" gorm:"column:email_address"`
FirstName string `json:"-" gorm:"column:first_name"`
LastName string `json:"-" gorm:"column:last_name"`
DisplayName string `json:"-" gorm:"column:display_name"`
Roles database.TextArray[string] `json:"roles" gorm:"column:roles"`
Sequence uint64 `json:"-" gorm:"column:sequence"`
PreferredLoginName string `json:"-" gorm:"column:preferred_login_name"`
AvatarKey string `json:"-" gorm:"column:avatar_key"`
UserResourceOwner string `json:"-" gorm:"column:user_resource_owner"`
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
}
func (r *ProjectMemberView) AppendEvent(event *models.Event) (err error) {
r.Sequence = event.Seq
r.ChangeDate = event.CreationDate
switch event.Type() {
case project.MemberAddedType:
r.setRootData(event)
r.CreationDate = event.CreationDate
err = r.SetData(event)
case project.MemberChangedType:
err = r.SetData(event)
}
return err
}
func (r *ProjectMemberView) setRootData(event *models.Event) {
r.ProjectID = event.AggregateID
}
func (r *ProjectMemberView) SetData(event *models.Event) error {
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-slo9s").WithError(err).Error("could not unmarshal event data")
return zerrors.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
}
return nil
}

View File

@@ -1,59 +0,0 @@
package model
import (
"encoding/json"
"reflect"
"testing"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func mockProjectMemberData(member *es_model.ProjectMember) []byte {
data, _ := json.Marshal(member)
return data
}
func TestProjectMemberAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
member *ProjectMemberView
}
tests := []struct {
name string
args args
result *ProjectMemberView
}{
{
name: "append added member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.MemberAddedType, ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: []string{"Role"}})},
member: &ProjectMemberView{},
},
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"Role"}},
},
{
name: "append changed member event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.MemberAddedType, ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: []string{"RoleChanged"}})},
member: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"Role"}},
},
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"RoleChanged"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.member.AppendEvent(tt.args.event)
if tt.args.member.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.member.ProjectID)
}
if tt.args.member.UserID != tt.result.UserID {
t.Errorf("got wrong result userID: expected: %v, actual: %v ", tt.result.UserID, tt.args.member.UserID)
}
if !reflect.DeepEqual(tt.args.member.Roles, tt.result.Roles) {
t.Errorf("got wrong result Roles: expected: %v, actual: %v ", tt.result.Roles, tt.args.member.Roles)
}
})
}
}

View File

@@ -1,72 +0,0 @@
package model
import (
"testing"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
"github.com/zitadel/zitadel/internal/project/model"
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
"github.com/zitadel/zitadel/internal/repository/project"
)
func TestProjectAppendEvent(t *testing.T) {
type args struct {
event *es_models.Event
project *ProjectView
}
tests := []struct {
name string
args args
result *ProjectView
}{
{
name: "append added project event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ProjectAddedType, ResourceOwner: "GrantedOrgID", Data: mockProjectData(&es_model.Project{Name: "ProjectName"})},
project: &ProjectView{},
},
result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)},
},
{
name: "append change project event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ProjectChangedType, ResourceOwner: "GrantedOrgID", Data: mockProjectData(&es_model.Project{Name: "ProjectNameChanged"})},
project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)},
},
result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectNameChanged", State: int32(model.ProjectStateActive)},
},
{
name: "append project deactivate event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ProjectDeactivatedType, ResourceOwner: "GrantedOrgID"},
project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)},
},
result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateInactive)},
},
{
name: "append project reactivate event",
args: args{
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.ProjectReactivatedType, ResourceOwner: "GrantedOrgID"},
project: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateInactive)},
},
result: &ProjectView{ProjectID: "AggregateID", ResourceOwner: "GrantedOrgID", Name: "ProjectName", State: int32(model.ProjectStateActive)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.args.project.AppendEvent(tt.args.event)
if tt.args.project.ProjectID != tt.result.ProjectID {
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.project.ProjectID)
}
if tt.args.project.ResourceOwner != tt.result.ResourceOwner {
t.Errorf("got wrong result ResourceOwner: expected: %v, actual: %v ", tt.result.ResourceOwner, tt.args.project.ResourceOwner)
}
if tt.args.project.Name != tt.result.Name {
t.Errorf("got wrong result name: expected: %v, actual: %v ", tt.result.Name, tt.args.project.Name)
}
if tt.args.project.State != tt.result.State {
t.Errorf("got wrong result state: expected: %v, actual: %v ", tt.result.State, tt.args.project.State)
}
})
}
}

View File

@@ -1,70 +0,0 @@
package view
import (
"github.com/jinzhu/gorm"
"github.com/zitadel/zitadel/internal/domain"
proj_model "github.com/zitadel/zitadel/internal/project/model"
"github.com/zitadel/zitadel/internal/project/repository/view/model"
"github.com/zitadel/zitadel/internal/view/repository"
"github.com/zitadel/zitadel/internal/zerrors"
)
func OrgProjectMappingByIDs(db *gorm.DB, table, orgID, projectID, instanceID string) (*model.OrgProjectMapping, error) {
orgProjectMapping := new(model.OrgProjectMapping)
projectIDQuery := model.OrgProjectMappingSearchQuery{Key: proj_model.OrgProjectMappingSearchKeyProjectID, Value: projectID, Method: domain.SearchMethodEquals}
orgIDQuery := model.OrgProjectMappingSearchQuery{Key: proj_model.OrgProjectMappingSearchKeyOrgID, Value: orgID, Method: domain.SearchMethodEquals}
instanceIDQuery := model.OrgProjectMappingSearchQuery{Key: proj_model.OrgProjectMappingSearchKeyInstanceID, Value: instanceID, Method: domain.SearchMethodEquals}
ownerRemovedQuery := model.OrgProjectMappingSearchQuery{Key: proj_model.OrgProjectMappingSearchKeyOwnerRemoved, Value: false, Method: domain.SearchMethodEquals}
query := repository.PrepareGetByQuery(table, projectIDQuery, orgIDQuery, instanceIDQuery, ownerRemovedQuery)
err := query(db, orgProjectMapping)
if zerrors.IsNotFound(err) {
return nil, zerrors.ThrowNotFound(nil, "VIEW-fn9fs", "Errors.OrgProjectMapping.NotExisting")
}
return orgProjectMapping, err
}
func PutOrgProjectMapping(db *gorm.DB, table string, grant *model.OrgProjectMapping) error {
save := repository.PrepareSave(table)
return save(db, grant)
}
func DeleteOrgProjectMapping(db *gorm.DB, table, orgID, projectID, instanceID string) error {
projectIDSearch := repository.Key{Key: model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyProjectID), Value: projectID}
orgIDSearch := repository.Key{Key: model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyOrgID), Value: orgID}
instanceIDSearch := repository.Key{Key: model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyInstanceID), Value: instanceID}
delete := repository.PrepareDeleteByKeys(table, projectIDSearch, orgIDSearch, instanceIDSearch)
return delete(db)
}
func DeleteInstanceOrgProjectMappings(db *gorm.DB, table, instanceID string) error {
delete := repository.PrepareDeleteByKey(table, model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyInstanceID), instanceID)
return delete(db)
}
func UpdateOwnerRemovedOrgProjectMappings(db *gorm.DB, table, instanceID, orgID string) error {
update := repository.PrepareUpdateByKeys(table,
model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyOwnerRemoved),
true,
repository.Key{Key: model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyInstanceID), Value: instanceID},
repository.Key{Key: model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyOrgID), Value: orgID},
)
return update(db)
}
func DeleteOrgProjectMappingsByProjectID(db *gorm.DB, table, projectID, instanceID string) error {
delete := repository.PrepareDeleteByKeys(table,
repository.Key{model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyProjectID), projectID},
repository.Key{model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyInstanceID), instanceID},
)
return delete(db)
}
func DeleteOrgProjectMappingsByProjectGrantID(db *gorm.DB, table, projectGrantID, instanceID string) error {
delete := repository.PrepareDeleteByKeys(table,
repository.Key{model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyProjectGrantID), projectGrantID},
repository.Key{model.OrgProjectMappingSearchKey(proj_model.OrgProjectMappingSearchKeyInstanceID), instanceID},
)
return delete(db)
}