Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion app/services/organizations/delete_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def execute
end

transactional do |t|
namespace = organization.ensure_namespace

organization.delete

if organization.persisted?
Expand All @@ -25,12 +27,14 @@ def execute
details: organization.errors)
end

namespace.delete
Comment thread
raphael-goetz marked this conversation as resolved.

AuditService.audit(
:organization_deleted,
author_id: current_authentication.user.id,
entity: organization,
details: {},
target: organization.ensure_namespace
target: namespace
Comment thread
raphael-goetz marked this conversation as resolved.
Outdated
)

ServiceResponse.success(message: 'Organization deleted', payload: organization)
Expand Down
4 changes: 4 additions & 0 deletions app/services/users/delete_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def execute
end

transactional do |t|
namespace = user.namespace

user.destroy

if user.persisted?
Expand All @@ -27,6 +29,8 @@ def execute
)
end

namespace&.delete
Comment thread
raphael-goetz marked this conversation as resolved.

AuditService.audit(
:user_deleted,
author_id: current_authentication.user.id,
Expand Down
4 changes: 4 additions & 0 deletions spec/services/organizations/delete_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
it { expect(service_response.payload).to eq(organization) }
it { expect { service_response }.to change { Organization.count }.by(-1) }

it do
expect { service_response }.to change { Namespace.exists?(organization.namespace.id) }.from(true).to(false)
end

it do
expect { service_response }.to create_audit_event(
:organization_deleted,
Expand Down
5 changes: 5 additions & 0 deletions spec/services/users/delete_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
let(:current_user) { create(:user, :admin) }

it 'deletes the user successfully' do
namespace_id = user.ensure_namespace.id

expect { service_response }.to change { User.exists?(user.id) }.from(true).to(false)
.and change {
Namespace.exists?(namespace_id)
}.from(true).to(false)
expect(service_response).to be_success
expect(service_response.payload).to eq(user)

Expand Down