2023-04-25 07:02:29 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2023-05-11 09:23:40 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-25 07:02:29 +00:00
|
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
|
2023-05-11 09:23:40 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
2023-04-25 07:02:29 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
2023-05-05 15:34:53 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/query"
|
2023-09-13 12:43:01 +00:00
|
|
|
object "github.com/zitadel/zitadel/pkg/grpc/object/v2beta"
|
2023-04-25 07:02:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func DomainToDetailsPb(objectDetail *domain.ObjectDetails) *object.Details {
|
|
|
|
details := &object.Details{
|
|
|
|
Sequence: objectDetail.Sequence,
|
|
|
|
ResourceOwner: objectDetail.ResourceOwner,
|
|
|
|
}
|
|
|
|
if !objectDetail.EventDate.IsZero() {
|
|
|
|
details.ChangeDate = timestamppb.New(objectDetail.EventDate)
|
|
|
|
}
|
|
|
|
return details
|
|
|
|
}
|
2023-05-05 15:34:53 +00:00
|
|
|
|
|
|
|
func ToListDetails(response query.SearchResponse) *object.ListDetails {
|
|
|
|
details := &object.ListDetails{
|
|
|
|
TotalResult: response.Count,
|
|
|
|
ProcessedSequence: response.Sequence,
|
2023-10-19 10:19:10 +00:00
|
|
|
Timestamp: timestamppb.New(response.EventCreatedAt),
|
2023-05-05 15:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return details
|
|
|
|
}
|
|
|
|
func ListQueryToQuery(query *object.ListQuery) (offset, limit uint64, asc bool) {
|
|
|
|
if query == nil {
|
|
|
|
return 0, 0, false
|
|
|
|
}
|
|
|
|
return query.Offset, uint64(query.Limit), query.Asc
|
|
|
|
}
|
2023-05-11 09:23:40 +00:00
|
|
|
|
|
|
|
func ResourceOwnerFromReq(ctx context.Context, req *object.RequestContext) string {
|
|
|
|
if req.GetInstance() {
|
|
|
|
return authz.GetInstance(ctx).InstanceID()
|
|
|
|
}
|
|
|
|
if req.GetOrgId() != "" {
|
|
|
|
return req.GetOrgId()
|
|
|
|
}
|
|
|
|
return authz.GetCtxData(ctx).OrgID
|
|
|
|
}
|
2024-01-17 09:00:10 +00:00
|
|
|
|
|
|
|
func TextMethodToQuery(method object.TextQueryMethod) query.TextComparison {
|
|
|
|
switch method {
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_EQUALS:
|
|
|
|
return query.TextEquals
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_EQUALS_IGNORE_CASE:
|
|
|
|
return query.TextEqualsIgnoreCase
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_STARTS_WITH:
|
|
|
|
return query.TextStartsWith
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_STARTS_WITH_IGNORE_CASE:
|
|
|
|
return query.TextStartsWithIgnoreCase
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_CONTAINS:
|
|
|
|
return query.TextContains
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_CONTAINS_IGNORE_CASE:
|
|
|
|
return query.TextContainsIgnoreCase
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_ENDS_WITH:
|
|
|
|
return query.TextEndsWith
|
|
|
|
case object.TextQueryMethod_TEXT_QUERY_METHOD_ENDS_WITH_IGNORE_CASE:
|
|
|
|
return query.TextEndsWithIgnoreCase
|
|
|
|
default:
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|