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