mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
a4763b1e4c
* features * features * features * fix json tags * add features handler to auth * mocks for tests * add setup step * fixes * add featurelist to auth api * grandfather state and typos * typo * merge new-eventstore * fix login policy tests * label policy in features * audit log retention
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package view
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
)
|
|
|
|
func OrgByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, error) {
|
|
if id == "" {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dke74", "id should be filled")
|
|
}
|
|
return OrgQuery(latestSequence).
|
|
AggregateIDFilter(id), nil
|
|
}
|
|
|
|
func OrgQuery(latestSequence uint64) *es_models.SearchQuery {
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgAggregate).
|
|
LatestSequenceFilter(latestSequence)
|
|
}
|
|
|
|
func OrgDomainUniqueQuery(domain string) *es_models.SearchQuery {
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgDomainAggregate).
|
|
AggregateIDFilter(domain).
|
|
OrderDesc().
|
|
SetLimit(1)
|
|
}
|
|
|
|
func OrgNameUniqueQuery(name string) *es_models.SearchQuery {
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgNameAggregate).
|
|
AggregateIDFilter(name).
|
|
OrderDesc().
|
|
SetLimit(1)
|
|
}
|
|
|
|
func ChangesQuery(orgID string, latestSequence, limit uint64, sortAscending bool, auditLogRetention time.Duration) *es_models.SearchQuery {
|
|
query := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.OrgAggregate)
|
|
|
|
if !sortAscending {
|
|
query.OrderDesc()
|
|
}
|
|
if auditLogRetention > 0 {
|
|
query.CreationDateNewerFilter(time.Now().Add(-auditLogRetention))
|
|
}
|
|
|
|
query.LatestSequenceFilter(latestSequence).
|
|
AggregateIDFilter(orgID).
|
|
SetLimit(limit)
|
|
return query
|
|
}
|