mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 03:24:26 +00:00
a7cc57822b
* fix: remove unused code * fix: remove unused code * fix: remove unused code * fix: remove unused code
80 lines
2.6 KiB
Go
80 lines
2.6 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
"github.com/caos/zitadel/internal/telemetry/tracing"
|
|
|
|
"github.com/caos/logging"
|
|
admin_view "github.com/caos/zitadel/internal/admin/repository/eventsourcing/view"
|
|
"github.com/caos/zitadel/internal/config/systemdefaults"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
iam_es_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
org_model "github.com/caos/zitadel/internal/org/model"
|
|
org_es "github.com/caos/zitadel/internal/org/repository/eventsourcing"
|
|
"github.com/caos/zitadel/internal/org/repository/view/model"
|
|
usr_es "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
|
)
|
|
|
|
type OrgRepo struct {
|
|
Eventstore eventstore.Eventstore
|
|
OrgEventstore *org_es.OrgEventstore
|
|
UserEventstore *usr_es.UserEventstore
|
|
|
|
View *admin_view.View
|
|
|
|
SearchLimit uint64
|
|
SystemDefaults systemdefaults.SystemDefaults
|
|
}
|
|
|
|
func (repo *OrgRepo) OrgByID(ctx context.Context, id string) (*org_model.Org, error) {
|
|
return repo.OrgEventstore.OrgByID(ctx, org_model.NewOrg(id))
|
|
}
|
|
|
|
func (repo *OrgRepo) SearchOrgs(ctx context.Context, query *org_model.OrgSearchRequest) (*org_model.OrgSearchResult, error) {
|
|
query.EnsureLimit(repo.SearchLimit)
|
|
sequence, err := repo.View.GetLatestOrgSequence()
|
|
logging.Log("EVENT-LXo9w").OnError(err).WithField("traceID", tracing.TraceIDFromCtx(ctx)).Warn("could not read latest iam sequence")
|
|
orgs, count, err := repo.View.SearchOrgs(query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := &org_model.OrgSearchResult{
|
|
Offset: query.Offset,
|
|
Limit: query.Limit,
|
|
TotalResult: count,
|
|
Result: model.OrgsToModel(orgs),
|
|
}
|
|
if err == nil {
|
|
result.Sequence = sequence.CurrentSequence
|
|
result.Timestamp = sequence.LastSuccessfulSpoolerRun
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (repo *OrgRepo) IsOrgUnique(ctx context.Context, name, domain string) (isUnique bool, err error) {
|
|
return repo.OrgEventstore.IsOrgUnique(ctx, name, domain)
|
|
}
|
|
|
|
func (repo *OrgRepo) GetOrgIAMPolicyByID(ctx context.Context, id string) (*iam_model.OrgIAMPolicyView, error) {
|
|
policy, err := repo.View.OrgIAMPolicyByAggregateID(id)
|
|
if errors.IsNotFound(err) {
|
|
return repo.GetDefaultOrgIAMPolicy(ctx)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return iam_es_model.OrgIAMViewToModel(policy), err
|
|
}
|
|
|
|
func (repo *OrgRepo) GetDefaultOrgIAMPolicy(ctx context.Context) (*iam_model.OrgIAMPolicyView, error) {
|
|
policy, err := repo.View.OrgIAMPolicyByAggregateID(repo.SystemDefaults.IamID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
policy.Default = true
|
|
return iam_es_model.OrgIAMViewToModel(policy), err
|
|
}
|