Skip to content

Commit e96c362

Browse files
committed
remove duplicates
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent a89235d commit e96c362

2 files changed

Lines changed: 2 additions & 40 deletions

File tree

app/controlplane/internal/service/organization.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationSe
9898
}
9999

100100
func (s *OrganizationService) Delete(ctx context.Context, req *pb.OrganizationServiceDeleteRequest) (*pb.OrganizationServiceDeleteResponse, error) {
101-
currentUser, err := requireCurrentUser(ctx)
102-
if err != nil {
101+
if _, err := requireCurrentUser(ctx); err != nil {
103102
return nil, err
104103
}
105104

@@ -120,7 +119,7 @@ func (s *OrganizationService) Delete(ctx context.Context, req *pb.OrganizationSe
120119
return nil, err
121120
}
122121

123-
if err := s.orgUC.DeleteByUser(ctx, req.Name, currentUser.ID); err != nil {
122+
if err := s.orgUC.Delete(ctx, orgUUID.String()); err != nil {
124123
return nil, handleUseCaseErr(err, s.log)
125124
}
126125

app/controlplane/pkg/biz/organization.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -290,43 +290,6 @@ func (uc *OrganizationUseCase) Delete(ctx context.Context, id string) error {
290290
return uc.orgRepo.Delete(ctx, orgUUID)
291291
}
292292

293-
// DeleteByUser deletes an organization initiated by a user with owner validation
294-
// Only organization owners can delete an organization
295-
func (uc *OrganizationUseCase) DeleteByUser(ctx context.Context, orgName, userID string) error {
296-
// Find organization by name
297-
org, err := uc.orgRepo.FindByName(ctx, orgName)
298-
if err != nil {
299-
return err
300-
} else if org == nil {
301-
return NewErrNotFound("organization")
302-
}
303-
304-
orgUUID, err := uuid.Parse(org.ID)
305-
if err != nil {
306-
return NewErrInvalidUUID(err)
307-
}
308-
309-
userUUID, err := uuid.Parse(userID)
310-
if err != nil {
311-
return NewErrInvalidUUID(err)
312-
}
313-
314-
// Check if user is an owner of the organization
315-
m, err := uc.membershipRepo.FindByOrgAndUser(ctx, orgUUID, userUUID)
316-
if err != nil {
317-
return fmt.Errorf("failed to find owners: %w", err)
318-
}
319-
320-
if m == nil || m.Role != authz.RoleOwner {
321-
return NewErrValidationStr("only organization owners can delete the organization")
322-
}
323-
324-
uc.logger.Infow("msg", "User deleting organization", "user_id", userID, "organization_id", org.ID)
325-
326-
// Use the existing Delete method to handle the actual deletion
327-
return uc.Delete(ctx, org.ID)
328-
}
329-
330293
// AutoOnboardOrganizations creates the organizations specified in the onboarding config and assigns the user to them
331294
// with the specified role if they are not already a member.
332295
func (uc *OrganizationUseCase) AutoOnboardOrganizations(ctx context.Context, userID string) error {

0 commit comments

Comments
 (0)