mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-24 00:28:18 +00:00
a1d404291d
* start implement notify user in projection * fix(stmt): add copy to multi stmt * use projections for notify users * feat: notifications from projections * feat: notifications from projections * cleanup * pre-release * fix tests * fix types * fix command * fix queryNotifyUser * fix: build version * fix: HumanPasswordlessInitCodeSent Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
"github.com/zitadel/zitadel/internal/repository/org"
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
|
)
|
|
|
|
type CascadingMembership struct {
|
|
UserID string
|
|
ResourceOwner string
|
|
|
|
IAM *CascadingIAMMembership
|
|
Org *CascadingOrgMembership
|
|
Project *CascadingProjectMembership
|
|
ProjectGrant *CascadingProjectGrantMembership
|
|
}
|
|
|
|
type CascadingIAMMembership struct {
|
|
IAMID string
|
|
}
|
|
|
|
type CascadingOrgMembership struct {
|
|
OrgID string
|
|
}
|
|
|
|
type CascadingProjectMembership struct {
|
|
ProjectID string
|
|
}
|
|
|
|
type CascadingProjectGrantMembership struct {
|
|
ProjectID string
|
|
GrantID string
|
|
}
|
|
|
|
func (c *Commands) removeUserMemberships(ctx context.Context, memberships []*CascadingMembership) (_ []eventstore.Command, err error) {
|
|
events := make([]eventstore.Command, 0)
|
|
for _, membership := range memberships {
|
|
if membership.IAM != nil {
|
|
iamAgg := instance.NewAggregate(membership.IAM.IAMID)
|
|
removeEvent := c.removeInstanceMember(ctx, &iamAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
} else if membership.Org != nil {
|
|
orgAgg := org.NewAggregate(membership.Org.OrgID)
|
|
removeEvent := c.removeOrgMember(ctx, &orgAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
} else if membership.Project != nil {
|
|
projectAgg := project.NewAggregate(membership.Project.ProjectID, membership.ResourceOwner)
|
|
removeEvent := c.removeProjectMember(ctx, &projectAgg.Aggregate, membership.UserID, true)
|
|
events = append(events, removeEvent)
|
|
} 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)
|
|
events = append(events, removeEvent)
|
|
}
|
|
}
|
|
return events, nil
|
|
}
|