2020-06-25 06:12:29 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2020-07-07 09:42:39 +00:00
|
|
|
"github.com/caos/zitadel/internal/errors"
|
2020-12-18 15:47:45 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
2020-06-25 06:12:29 +00:00
|
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
|
|
"github.com/caos/zitadel/internal/iam/repository/view"
|
|
|
|
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
|
|
global_view "github.com/caos/zitadel/internal/view/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-07-07 14:53:54 +00:00
|
|
|
iamMemberTable = "adminapi.iam_members"
|
2020-06-25 06:12:29 +00:00
|
|
|
)
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (v *View) IAMMemberByIDs(orgID, userID string) (*model.IAMMemberView, error) {
|
|
|
|
return view.IAMMemberByIDs(v.Db, iamMemberTable, orgID, userID)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (v *View) SearchIAMMembers(request *iam_model.IAMMemberSearchRequest) ([]*model.IAMMemberView, uint64, error) {
|
|
|
|
return view.SearchIAMMembers(v.Db, iamMemberTable, request)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (v *View) IAMMembersByUserID(userID string) ([]*model.IAMMemberView, error) {
|
|
|
|
return view.IAMMembersByUserID(v.Db, iamMemberTable, userID)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutIAMMember(org *model.IAMMemberView, event *models.Event) error {
|
2020-08-26 07:56:23 +00:00
|
|
|
err := view.PutIAMMember(v.Db, iamMemberTable, org)
|
2020-06-25 06:12:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedIAMMemberSequence(event)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) PutIAMMembers(members []*model.IAMMemberView, event *models.Event) error {
|
2020-08-26 11:01:37 +00:00
|
|
|
err := view.PutIAMMembers(v.Db, iamMemberTable, members...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedIAMMemberSequence(event)
|
2020-08-26 11:01:37 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) DeleteIAMMember(iamID, userID string, event *models.Event) error {
|
2020-08-26 07:56:23 +00:00
|
|
|
err := view.DeleteIAMMember(v.Db, iamMemberTable, iamID, userID)
|
2020-07-07 09:42:39 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedIAMMemberSequence(event)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) DeleteIAMMembersByUserID(userID string, event *models.Event) error {
|
2020-10-07 06:16:42 +00:00
|
|
|
err := view.DeleteIAMMembersByUserID(v.Db, iamMemberTable, userID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-12-18 15:47:45 +00:00
|
|
|
return v.ProcessedIAMMemberSequence(event)
|
2020-10-07 06:16:42 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) GetLatestIAMMemberSequence(aggregateType string) (*global_view.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(iamMemberTable, aggregateType)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 15:47:45 +00:00
|
|
|
func (v *View) ProcessedIAMMemberSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(iamMemberTable, event)
|
2020-12-02 07:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) UpdateIAMMemberSpoolerRunTimestamp() error {
|
|
|
|
return v.updateSpoolerRunSequence(iamMemberTable)
|
2020-06-25 06:12:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (v *View) GetLatestIAMMemberFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
2020-06-25 06:12:29 +00:00
|
|
|
return v.latestFailedEvent(iamMemberTable, sequence)
|
|
|
|
}
|
|
|
|
|
2020-08-26 07:56:23 +00:00
|
|
|
func (v *View) ProcessedIAMMemberFailedEvent(failedEvent *global_view.FailedEvent) error {
|
2020-06-25 06:12:29 +00:00
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|