mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
d3e403f645
* fix: events query user * fix: events query user * user events query * fix tests * fix query * cleanup --------- Co-authored-by: Fabienne <fabienne.gerschwiler@gmail.com>
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
v1 "github.com/zitadel/zitadel/internal/eventstore/v1"
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
"github.com/zitadel/zitadel/internal/query"
|
|
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
|
|
)
|
|
|
|
type UserRepo struct {
|
|
SearchLimit uint64
|
|
Eventstore v1.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, sequence uint64, eventTypes []models.EventType) ([]*models.Event, error) {
|
|
return repo.getUserEvents(ctx, id, sequence, eventTypes)
|
|
}
|
|
|
|
func (r *UserRepo) getUserEvents(ctx context.Context, userID string, sequence uint64, eventTypes []models.EventType) ([]*models.Event, error) {
|
|
query, err := usr_view.UserByIDQuery(userID, authz.GetInstance(ctx).InstanceID(), sequence, eventTypes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return r.Eventstore.FilterEvents(ctx, query)
|
|
}
|