2020-07-30 14:37:55 +02:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-12-21 18:42:34 +01:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2020-12-18 16:47:45 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
2020-07-30 14:37:55 +02:00
|
|
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
|
|
|
"github.com/caos/zitadel/internal/user/repository/view"
|
|
|
|
"github.com/caos/zitadel/internal/user/repository/view/model"
|
|
|
|
"github.com/caos/zitadel/internal/view/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
userMembershipTable = "management.user_memberships"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *View) UserMembershipByIDs(userID, aggregateID, objectID string, memberType usr_model.MemberType) (*model.UserMembershipView, error) {
|
|
|
|
return view.UserMembershipByIDs(v.Db, userMembershipTable, userID, aggregateID, objectID, memberType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UserMembershipsByAggregateID(aggregateID string) ([]*model.UserMembershipView, error) {
|
|
|
|
return view.UserMembershipsByAggregateID(v.Db, userMembershipTable, aggregateID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) SearchUserMemberships(request *usr_model.UserMembershipSearchRequest) ([]*model.UserMembershipView, uint64, error) {
|
|
|
|
return view.SearchUserMemberships(v.Db, userMembershipTable, request)
|
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) PutUserMembership(membership *model.UserMembershipView, event *models.Event) error {
|
2020-07-30 14:37:55 +02:00
|
|
|
err := view.PutUserMembership(v.Db, userMembershipTable, membership)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) BulkPutUserMemberships(memberships []*model.UserMembershipView, event *models.Event) error {
|
2020-10-16 07:49:38 +02:00
|
|
|
err := view.PutUserMemberships(v.Db, userMembershipTable, memberships...)
|
2020-07-30 14:37:55 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteUserMembership(userID, aggregateID, objectID string, memberType usr_model.MemberType, event *models.Event) error {
|
2020-07-30 14:37:55 +02:00
|
|
|
err := view.DeleteUserMembership(v.Db, userMembershipTable, userID, aggregateID, objectID, memberType)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteUserMembershipsByUserID(userID string, event *models.Event) error {
|
2020-10-07 08:16:42 +02:00
|
|
|
err := view.DeleteUserMembershipsByUserID(v.Db, userMembershipTable, userID)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-10-07 08:16:42 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-10-07 08:16:42 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteUserMembershipsByAggregateID(aggregateID string, event *models.Event) error {
|
2020-10-13 07:46:44 +02:00
|
|
|
err := view.DeleteUserMembershipsByAggregateID(v.Db, userMembershipTable, aggregateID)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-10-13 07:46:44 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-10-13 07:46:44 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) DeleteUserMembershipsByAggregateIDAndObjectID(aggregateID, objectID string, event *models.Event) error {
|
2020-10-13 07:46:44 +02:00
|
|
|
err := view.DeleteUserMembershipsByAggregateIDAndObjectID(v.Db, userMembershipTable, aggregateID, objectID)
|
2020-12-21 18:42:34 +01:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-10-13 07:46:44 +02:00
|
|
|
}
|
2020-12-18 16:47:45 +01:00
|
|
|
return v.ProcessedUserMembershipSequence(event)
|
2020-10-13 07:46:44 +02:00
|
|
|
}
|
|
|
|
|
2021-01-27 10:35:01 +01:00
|
|
|
func (v *View) GetLatestUserMembershipSequence() (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(userMembershipTable)
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:47:45 +01:00
|
|
|
func (v *View) ProcessedUserMembershipSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(userMembershipTable, event)
|
2020-12-02 08:50:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateUserMembershipSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(userMembershipTable)
|
2020-07-30 14:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) GetLatestUserMembershipFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
|
|
|
|
return v.latestFailedEvent(userMembershipTable, sequence)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProcessedUserMembershipFailedEvent(failedEvent *repository.FailedEvent) error {
|
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|