mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +00:00
refactor: cleanup unused code (#7130)
* refactor: drop unused code * refactor: drop unused code
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
@@ -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})
|
||||
}
|
@@ -9,7 +9,3 @@ type ProjectRole struct {
|
||||
DisplayName string
|
||||
Group string
|
||||
}
|
||||
|
||||
func (p *ProjectRole) IsValid() bool {
|
||||
return p.AggregateID != "" && p.Key != ""
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
@@ -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
|
||||
}
|
@@ -10,7 +10,3 @@ type SAMLConfig struct {
|
||||
Metadata []byte
|
||||
MetadataURL string
|
||||
}
|
||||
|
||||
func (c *SAMLConfig) IsValid() bool {
|
||||
return !(c.Metadata == nil && c.MetadataURL == "")
|
||||
}
|
||||
|
Reference in New Issue
Block a user