2020-07-30 14:37:55 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2024-04-03 13:43:43 +03:00
|
|
|
"time"
|
|
|
|
|
2022-04-27 01:01:45 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-12-08 16:30:55 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
2020-07-30 14:37:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type UserMembershipView struct {
|
|
|
|
UserID string
|
|
|
|
MemberType MemberType
|
|
|
|
AggregateID string
|
|
|
|
//ObjectID differs from aggregate id if obejct is sub of an aggregate
|
|
|
|
ObjectID string
|
|
|
|
|
2020-09-04 15:20:39 +02:00
|
|
|
Roles []string
|
|
|
|
DisplayName string
|
|
|
|
CreationDate time.Time
|
|
|
|
ChangeDate time.Time
|
|
|
|
ResourceOwner string
|
|
|
|
ResourceOwnerName string
|
|
|
|
Sequence uint64
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type MemberType int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
MemberTypeUnspecified MemberType = iota
|
|
|
|
MemberTypeOrganisation
|
|
|
|
MemberTypeProject
|
|
|
|
MemberTypeProjectGrant
|
2020-08-25 16:08:51 +02:00
|
|
|
MemberTypeIam
|
2020-07-30 14:37:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2022-03-23 09:02:39 +01:00
|
|
|
UserMembershipSearchKeyInstanceID
|
2020-07-30 14:37:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type UserMembershipSearchQuery struct {
|
|
|
|
Key UserMembershipSearchKey
|
2021-03-01 08:48:50 +01:00
|
|
|
Method domain.SearchMethod
|
2020-07-30 14:37:55 +02:00
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserMembershipSearchResponse struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
TotalResult uint64
|
|
|
|
Result []*UserMembershipView
|
|
|
|
Sequence uint64
|
|
|
|
Timestamp time.Time
|
|
|
|
}
|
|
|
|
|
2021-04-06 16:03:07 +02:00
|
|
|
func (r *UserMembershipSearchRequest) EnsureLimit(limit uint64) error {
|
|
|
|
if r.Limit > limit {
|
2023-12-08 16:30:55 +02:00
|
|
|
return zerrors.ThrowInvalidArgument(nil, "SEARCH-288fJ", "Errors.Limit.ExceedsDefault")
|
2021-04-06 16:03:07 +02:00
|
|
|
}
|
|
|
|
if r.Limit == 0 {
|
2020-07-30 14:37:55 +02:00
|
|
|
r.Limit = limit
|
|
|
|
}
|
2021-04-06 16:03:07 +02:00
|
|
|
return nil
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *UserMembershipSearchRequest) GetSearchQuery(key UserMembershipSearchKey) (int, *UserMembershipSearchQuery) {
|
|
|
|
for i, q := range r.Queries {
|
|
|
|
if q.Key == key {
|
|
|
|
return i, q
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:08:51 +02:00
|
|
|
func (r *UserMembershipSearchRequest) AppendResourceOwnerAndIamQuery(orgID, iamID string) {
|
2021-03-01 08:48:50 +01:00
|
|
|
r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyResourceOwner, Method: domain.SearchMethodIsOneOf, Value: []string{orgID, iamID}})
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *UserMembershipSearchRequest) AppendUserIDQuery(userID string) {
|
2021-03-01 08:48:50 +01:00
|
|
|
r.Queries = append(r.Queries, &UserMembershipSearchQuery{Key: UserMembershipSearchKeyUserID, Method: domain.SearchMethodEquals, Value: userID})
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|