Fixes #4032 - Admin macros are not usable with admin permissions only.

This commit is contained in:
Rolf Schmidt 2022-03-28 08:21:52 +01:00
parent a3a8661e90
commit 772bf3516c
3 changed files with 21 additions and 1 deletions

View file

@ -3,5 +3,5 @@
class Controllers::MacrosControllerPolicy < Controllers::ApplicationControllerPolicy
default_permit! ['admin.macro']
permit! %i[index show], to: ['ticket.agent']
permit! %i[index show], to: ['admin.macro', 'ticket.agent']
end

View file

@ -48,6 +48,10 @@ FactoryBot.define do
roles { Role.where(name: %w[Admin Agent]) }
end
factory :admin_only do
roles { Role.where(name: %w[Admin]) }
end
trait :with_valid_password do
password { generate :password_valid }
end

View file

@ -128,6 +128,14 @@ RSpec.describe 'Macro', type: :request, authenticated_as: :user do
expect(json_response.map { |elem| elem['id'] }).to eq [Macro.first.id]
end
end
context 'when user is admin only' do
let(:user) { create(:admin_only) }
it 'returns array of macros' do
expect(json_response.map { |elem| elem['id'] }).to eq [Macro.first.id]
end
end
end
describe '#show' do
@ -160,5 +168,13 @@ RSpec.describe 'Macro', type: :request, authenticated_as: :user do
end
end
end
context 'when user is admin only' do
let(:user) { create(:admin_only) }
it 'returns array of macros' do
expect(response).to have_http_status(:ok)
end
end
end
end