mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-18 05:47:32 +00:00
1143e3773e
* fix: remove usermemberships on user remove * fix: text user remove with memberships * fix: translations * Update internal/iam/repository/eventsourcing/model/types.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: uncomment tests * fix: remove memberships if user removed Co-authored-by: Livio Amstutz <livio.a@gmail.com>
37 lines
1.5 KiB
Go
37 lines
1.5 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/repository/iam"
|
|
"github.com/caos/zitadel/internal/repository/org"
|
|
"github.com/caos/zitadel/internal/repository/project"
|
|
)
|
|
|
|
func (c *Commands) removeUserMemberships(ctx context.Context, memberships []*domain.UserMembership, cascade bool) (_ []eventstore.EventPusher, err error) {
|
|
events := make([]eventstore.EventPusher, 0)
|
|
for _, membership := range memberships {
|
|
switch membership.MemberType {
|
|
case domain.MemberTypeIam:
|
|
iamAgg := iam.NewAggregate()
|
|
removeEvent := c.removeIAMMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
case domain.MemberTypeOrganisation:
|
|
iamAgg := org.NewAggregate(membership.AggregateID, membership.ResourceOwner)
|
|
removeEvent := c.removeOrgMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
case domain.MemberTypeProject:
|
|
projectAgg := project.NewAggregate(membership.AggregateID, membership.ResourceOwner)
|
|
removeEvent := c.removeProjectMember(ctx, &projectAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
case domain.MemberTypeProjectGrant:
|
|
projectAgg := project.NewAggregate(membership.AggregateID, membership.ResourceOwner)
|
|
removeEvent := c.removeProjectGrantMember(ctx, &projectAgg.Aggregate, membership.UserID, membership.ObjectID, true)
|
|
events = append(events, removeEvent)
|
|
}
|
|
}
|
|
return events, nil
|
|
}
|