2021-01-04 14:52:13 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-12-14 08:19:02 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/query/projection"
|
2021-01-04 14:52:13 +01:00
|
|
|
"github.com/caos/zitadel/internal/telemetry/tracing"
|
2021-12-16 14:25:38 +01:00
|
|
|
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
2021-01-04 14:52:13 +01:00
|
|
|
)
|
|
|
|
|
2021-12-14 08:19:02 +01:00
|
|
|
type MembersQuery struct {
|
|
|
|
SearchRequest
|
|
|
|
Queries []SearchQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *MembersQuery) toQuery(query sq.SelectBuilder) sq.SelectBuilder {
|
|
|
|
query = q.SearchRequest.toQuery(query)
|
|
|
|
for _, q := range q.Queries {
|
|
|
|
query = q.toQuery(query)
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberEmailSearchQuery(method TextComparison, value string) (SearchQuery, error) {
|
|
|
|
return NewTextQuery(HumanEmailCol, value, method)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberFirstNameSearchQuery(method TextComparison, value string) (SearchQuery, error) {
|
|
|
|
return NewTextQuery(HumanFirstNameCol, value, method)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberLastNameSearchQuery(method TextComparison, value string) (SearchQuery, error) {
|
|
|
|
return NewTextQuery(HumanLastNameCol, value, method)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemberUserIDSearchQuery(value string) (SearchQuery, error) {
|
|
|
|
return NewTextQuery(memberUserID, value, TextEquals)
|
|
|
|
}
|
|
|
|
func NewMemberResourceOwnerSearchQuery(value string) (SearchQuery, error) {
|
|
|
|
return NewTextQuery(memberResourceOwner, value, TextEquals)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Members struct {
|
|
|
|
SearchResponse
|
|
|
|
Members []*Member
|
|
|
|
}
|
|
|
|
|
|
|
|
type Member struct {
|
|
|
|
CreationDate time.Time
|
|
|
|
ChangeDate time.Time
|
|
|
|
Sequence uint64
|
|
|
|
ResourceOwner string
|
|
|
|
|
|
|
|
UserID string
|
|
|
|
Roles []string
|
|
|
|
PreferredLoginName string
|
|
|
|
Email string
|
|
|
|
FirstName string
|
|
|
|
LastName string
|
|
|
|
DisplayName string
|
|
|
|
AvatarURL string
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func (r *Queries) IAMMemberByID(ctx context.Context, iamID, userID string) (member *IAMMemberReadModel, err error) {
|
2021-01-04 14:52:13 +01:00
|
|
|
ctx, span := tracing.NewSpan(ctx)
|
|
|
|
defer func() { span.EndWithError(err) }()
|
|
|
|
|
|
|
|
member = NewIAMMemberReadModel(iamID, userID)
|
|
|
|
err = r.eventstore.FilterToQueryReducer(ctx, member)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return member, nil
|
|
|
|
}
|
2021-12-14 08:19:02 +01:00
|
|
|
|
|
|
|
var (
|
|
|
|
memberTableAlias = table{
|
|
|
|
name: "members",
|
|
|
|
alias: "members",
|
|
|
|
}
|
|
|
|
memberUserID = Column{
|
|
|
|
name: projection.MemberUserIDCol,
|
|
|
|
table: memberTableAlias,
|
|
|
|
}
|
|
|
|
memberResourceOwner = Column{
|
|
|
|
name: projection.MemberResourceOwner,
|
|
|
|
table: memberTableAlias,
|
|
|
|
}
|
|
|
|
)
|