2021-06-07 05:20:47 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2022-01-13 07:58:14 +00:00
|
|
|
"github.com/caos/zitadel/internal/query"
|
2021-06-07 05:20:47 +00:00
|
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
|
|
|
"github.com/caos/zitadel/internal/repository/org"
|
|
|
|
"github.com/caos/zitadel/internal/repository/project"
|
|
|
|
)
|
|
|
|
|
2022-01-13 07:58:14 +00:00
|
|
|
func (c *Commands) removeUserMemberships(ctx context.Context, memberships []*query.Membership) (_ []eventstore.Command, err error) {
|
2022-01-03 08:19:07 +00:00
|
|
|
events := make([]eventstore.Command, 0)
|
2021-06-07 05:20:47 +00:00
|
|
|
for _, membership := range memberships {
|
2022-01-13 07:58:14 +00:00
|
|
|
if membership.IAM != nil {
|
2021-06-07 05:20:47 +00:00
|
|
|
iamAgg := iam.NewAggregate()
|
|
|
|
removeEvent := c.removeIAMMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
|
|
|
|
events = append(events, removeEvent)
|
2022-01-13 07:58:14 +00:00
|
|
|
} else if membership.Org != nil {
|
|
|
|
iamAgg := org.NewAggregate(membership.Org.OrgID, membership.ResourceOwner)
|
2021-06-07 05:20:47 +00:00
|
|
|
removeEvent := c.removeOrgMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
|
|
|
|
events = append(events, removeEvent)
|
2022-01-13 07:58:14 +00:00
|
|
|
} else if membership.Project != nil {
|
|
|
|
projectAgg := project.NewAggregate(membership.Project.ProjectID, membership.ResourceOwner)
|
2021-06-07 05:20:47 +00:00
|
|
|
removeEvent := c.removeProjectMember(ctx, &projectAgg.Aggregate, membership.UserID, true)
|
|
|
|
events = append(events, removeEvent)
|
2022-01-13 07:58:14 +00:00
|
|
|
} else if membership.ProjectGrant != nil {
|
|
|
|
projectAgg := project.NewAggregate(membership.ProjectGrant.ProjectID, membership.ResourceOwner)
|
|
|
|
removeEvent := c.removeProjectGrantMember(ctx, &projectAgg.Aggregate, membership.UserID, membership.ProjectGrant.GrantID, true)
|
2021-06-07 05:20:47 +00:00
|
|
|
events = append(events, removeEvent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return events, nil
|
|
|
|
}
|