2020-06-15 14:50:39 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
2021-03-01 08:48:50 +01:00
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-04-06 16:03:07 +02:00
|
|
|
caos_errors "github.com/caos/zitadel/internal/errors"
|
|
|
|
|
2020-06-15 14:50:39 +02:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectGrantView struct {
|
2020-06-19 15:32:03 +02:00
|
|
|
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
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectGrantViewSearchRequest struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
SortingColumn ProjectGrantViewSearchKey
|
|
|
|
Asc bool
|
|
|
|
Queries []*ProjectGrantViewSearchQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectGrantViewSearchKey int32
|
|
|
|
|
|
|
|
const (
|
2020-06-23 14:47:47 +02:00
|
|
|
GrantedProjectSearchKeyUnspecified ProjectGrantViewSearchKey = iota
|
|
|
|
GrantedProjectSearchKeyName
|
|
|
|
GrantedProjectSearchKeyProjectID
|
|
|
|
GrantedProjectSearchKeyGrantID
|
|
|
|
GrantedProjectSearchKeyOrgID
|
|
|
|
GrantedProjectSearchKeyResourceOwner
|
|
|
|
GrantedProjectSearchKeyRoleKeys
|
2020-06-15 14:50:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectGrantViewSearchQuery struct {
|
|
|
|
Key ProjectGrantViewSearchKey
|
2021-03-01 08:48:50 +01:00
|
|
|
Method domain.SearchMethod
|
2020-06-15 14:50:39 +02:00
|
|
|
Value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectGrantViewSearchResponse struct {
|
|
|
|
Offset uint64
|
|
|
|
Limit uint64
|
|
|
|
TotalResult uint64
|
|
|
|
Result []*ProjectGrantView
|
2020-07-15 13:24:36 +02:00
|
|
|
Sequence uint64
|
|
|
|
Timestamp time.Time
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 14:00:29 +02:00
|
|
|
func (r *ProjectGrantViewSearchRequest) GetSearchQuery(key ProjectGrantViewSearchKey) (int, *ProjectGrantViewSearchQuery) {
|
|
|
|
for i, q := range r.Queries {
|
|
|
|
if q.Key == key {
|
|
|
|
return i, q
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:50:39 +02:00
|
|
|
func (r *ProjectGrantViewSearchRequest) AppendMyOrgQuery(orgID string) {
|
2021-03-01 08:48:50 +01:00
|
|
|
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodEquals, Value: orgID})
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ProjectGrantViewSearchRequest) AppendNotMyOrgQuery(orgID string) {
|
2021-03-01 08:48:50 +01:00
|
|
|
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyOrgID, Method: domain.SearchMethodNotEquals, Value: orgID})
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ProjectGrantViewSearchRequest) AppendMyResourceOwnerQuery(orgID string) {
|
2021-03-01 08:48:50 +01:00
|
|
|
r.Queries = append(r.Queries, &ProjectGrantViewSearchQuery{Key: GrantedProjectSearchKeyResourceOwner, Method: domain.SearchMethodEquals, Value: orgID})
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 16:03:07 +02:00
|
|
|
func (r *ProjectGrantViewSearchRequest) EnsureLimit(limit uint64) error {
|
|
|
|
if r.Limit > limit {
|
|
|
|
return caos_errors.ThrowInvalidArgument(nil, "SEARCH-2n8fS", "Errors.Limit.ExceedsDefault")
|
|
|
|
}
|
|
|
|
if r.Limit == 0 {
|
2020-06-15 14:50:39 +02:00
|
|
|
r.Limit = limit
|
|
|
|
}
|
2021-04-06 16:03:07 +02:00
|
|
|
return nil
|
2020-06-15 14:50:39 +02:00
|
|
|
}
|