From 59ecff9274c0672e7b5eceecdd13f8f8fa9b146c Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 9 Nov 2021 08:11:21 +0000 Subject: [PATCH] Fixes #3841 - Zammad returns stack error when one tries to remove groups via API. --- app/controllers/groups_controller.rb | 1 + spec/requests/group_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spec/requests/group_spec.rb diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index cae0d5425..c18d4ff48 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -149,6 +149,7 @@ curl http://localhost/api/v1/groups/{id} -v -u #{login}:#{password} -H "Content- =end def destroy + model_references_check(Group, params) model_destroy_render(Group, params) end end diff --git a/spec/requests/group_spec.rb b/spec/requests/group_spec.rb new file mode 100644 index 000000000..4e3bef8a1 --- /dev/null +++ b/spec/requests/group_spec.rb @@ -0,0 +1,20 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Group', type: :request, authenticated_as: -> { user } do + describe 'Zammad returns stack error when one tries to remove groups via API #3841' do + let(:group) { create(:group) } + let(:ticket) { create(:ticket, group: group) } + let(:user) { create(:admin) } + + before do + ticket + end + + it 'does return reference error on delete if related objects exist' do + delete "/api/v1/groups/#{group.id}", params: {}, as: :json + expect(json_response['error']).to eq("Can't delete, object has references.") + end + end +end