mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
19d9b8ad41
* fix: reduce eventual consistency * fix tests * fix linting
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/auth/repository/eventsourcing/view"
|
|
"github.com/zitadel/zitadel/internal/config/systemdefaults"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
|
|
)
|
|
|
|
type UserRepo struct {
|
|
SearchLimit uint64
|
|
Eventstore *eventstore.Eventstore
|
|
View *view.View
|
|
Query *query.Queries
|
|
SystemDefaults systemdefaults.SystemDefaults
|
|
}
|
|
|
|
func (repo *UserRepo) Health(ctx context.Context) error {
|
|
return repo.Eventstore.Health(ctx)
|
|
}
|
|
|
|
func (repo *UserRepo) UserSessionUserIDsByAgentID(ctx context.Context, agentID string) ([]string, error) {
|
|
userSessions, err := repo.View.UserSessionsByAgentID(agentID, authz.GetInstance(ctx).InstanceID())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
userIDs := make([]string, 0, len(userSessions))
|
|
for _, session := range userSessions {
|
|
if session.State == int32(domain.UserSessionStateActive) {
|
|
userIDs = append(userIDs, session.UserID)
|
|
}
|
|
}
|
|
return userIDs, nil
|
|
}
|
|
|
|
func (repo *UserRepo) UserEventsByID(ctx context.Context, id string, changeDate time.Time, eventTypes []eventstore.EventType) ([]eventstore.Event, error) {
|
|
query, err := usr_view.UserByIDQuery(id, authz.GetInstance(ctx).InstanceID(), changeDate, eventTypes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return repo.Eventstore.Filter(ctx, query) //nolint:staticcheck
|
|
}
|