Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func buildAPIDependencies(
)

cascadeDeleter := deleter.NewCascadeDeleter(organizationService, projectService, resourceService,
groupService, policyService, roleService, invitationService, userService, serviceUserService,
groupService, membershipService, policyService, roleService, invitationService, userService, serviceUserService,
customerService, subscriptionService, invoiceService,
)

Expand Down
22 changes: 11 additions & 11 deletions core/deleter/mocks/group_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions core/deleter/mocks/membership_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions core/deleter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ type ResourceService interface {

type GroupService interface {
List(ctx context.Context, flt group.Filter) ([]group.Group, error)
Delete(ctx context.Context, id string) error
DeleteModel(ctx context.Context, id string) error
RemoveUsers(ctx context.Context, groupID string, userIDs []string) error
}

type MembershipService interface {
OnGroupDeleted(ctx context.Context, groupID string) error
}

type InvitationService interface {
List(ctx context.Context, flt invitation.Filter) ([]invitation.Invitation, error)
Delete(ctx context.Context, id uuid.UUID) error
Expand Down Expand Up @@ -102,6 +106,7 @@ type Service struct {
orgService OrganizationService
resService ResourceService
groupService GroupService
membershipService MembershipService
policyService PolicyService
roleService RoleService
invitationService InvitationService
Expand All @@ -114,6 +119,7 @@ type Service struct {

func NewCascadeDeleter(orgService OrganizationService, projService ProjectService,
resService ResourceService, groupService GroupService,
membershipService MembershipService,
policyService PolicyService, roleService RoleService,
invitationService InvitationService, userService UserService,
serviceUserService ServiceUserService,
Expand All @@ -124,6 +130,7 @@ func NewCascadeDeleter(orgService OrganizationService, projService ProjectServic
orgService: orgService,
resService: resService,
groupService: groupService,
membershipService: membershipService,
policyService: policyService,
roleService: roleService,
invitationService: invitationService,
Expand Down Expand Up @@ -165,6 +172,16 @@ func (d Service) DeleteProject(ctx context.Context, id string) error {
return d.projService.DeleteModel(ctx, id)
}

// DeleteGroup orchestrates teardown of a single group: clears every member's
// policies and relations plus the org<->group hierarchy relations via
// membership, then deletes the group entity itself.
func (d Service) DeleteGroup(ctx context.Context, id string) error {
if err := d.membershipService.OnGroupDeleted(ctx, id); err != nil {
return fmt.Errorf("clean up group membership: %w", err)
}
return d.groupService.DeleteModel(ctx, id)
}

func (d Service) DeleteOrganization(ctx context.Context, id string) error {
// check if delete is allowed
if err := d.canDelete(ctx, id); err != nil {
Expand Down Expand Up @@ -203,7 +220,7 @@ func (d Service) DeleteOrganization(ctx context.Context, id string) error {
return err
}
for _, g := range groups {
if err = d.groupService.Delete(ctx, g.ID); err != nil {
if err = d.DeleteGroup(ctx, g.ID); err != nil {
return fmt.Errorf("failed to delete org while deleting a group[%s]: %w", g.Name, err)
}
}
Expand Down
Loading
Loading