zitadel/internal/user/model/user_membership_view.go
Livio Amstutz 56b916a2b0
feat: projections auto create their tables (#3324)
* begin init checks for projections

* first projection checks

* debug notification providers with query fixes

* more projections and first index

* more projections

* more projections

* finish projections

* fix tests (remove db name)

* create tables in setup

* fix logging / error handling

* add tenant to views

* rename tenant to instance_id

* add instance_id to all projections

* add instance_id to all queries

* correct instance_id on projections

* add instance_id to failed_events

* use separate context for instance

* implement features projection

* implement features projection

* remove unique constraint from setup when migration failed

* add error to failed setup event

* add instance_id to primary keys

* fix IAM projection

* remove old migrations folder

* fix keysFromYAML test
2022-03-23 09:02:39 +01:00

97 lines
2.4 KiB
Go

package model
import (
"github.com/caos/zitadel/internal/domain"
caos_errors "github.com/caos/zitadel/internal/errors"
"time"
)
type UserMembershipView struct {
UserID string
MemberType MemberType
AggregateID string
//ObjectID differs from aggregate id if obejct is sub of an aggregate
ObjectID string
Roles []string
DisplayName string
CreationDate time.Time
ChangeDate time.Time
ResourceOwner string
ResourceOwnerName string
Sequence uint64
}
type MemberType int32
const (
MemberTypeUnspecified MemberType = iota
MemberTypeOrganisation
MemberTypeProject
MemberTypeProjectGrant
MemberTypeIam
)
type UserMembershipSearchRequest struct {
Offset uint64
Limit uint64
SortingColumn UserMembershipSearchKey
Asc bool
Queries []*UserMembershipSearchQuery
}
type UserMembershipSearchKey int32
const (
UserMembershipSearchKeyUnspecified UserMembershipSearchKey = iota
UserMembershipSearchKeyUserID
UserMembershipSearchKeyMemberType
UserMembershipSearchKeyAggregateID
UserMembershipSearchKeyObjectID
UserMembershipSearchKeyResourceOwner
UserMembershipSearchKeyInstanceID
)
type UserMembershipSearchQuery struct {
Key UserMembershipSearchKey
Method domain.SearchMethod
Value interface{}
}
type UserMembershipSearchResponse struct {
Offset uint64
Limit uint64
TotalResult uint64
Result []*UserMembershipView
Sequence uint64
Timestamp time.Time
}
func (r *UserMembershipSearchRequest) EnsureLimit(limit uint64) error {
if r.Limit > limit {
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-288fJ", "Errors.Limit.ExceedsDefault")
}
if r.Limit == 0 {
r.Limit = limit
}
return nil
}
func (r *UserMembershipSearchRequest) GetSearchQuery(key UserMembershipSearchKey) (int, *UserMembershipSearchQuery) {
for i, q := range r.Queries {
if q.Key == key {
return i, q
}
}
return -1, nil
}
func (r *UserMembershipSearchRequest) AppendResourceOwnerAndIamQuery(orgID, iamID string) {
r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyResourceOwner, Method: domain.SearchMethodIsOneOf, Value: []string{orgID, iamID}})
}
func (r *UserMembershipSearchRequest) AppendUserIDQuery(userID string) {
r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyUserID, Method: domain.SearchMethodEquals, Value: userID})
}