Fixes #2568 - Change-Right allows creation of new tickets.

This commit is contained in:
Rolf Schmidt 2020-11-13 15:10:24 +01:00 committed by Thorsten Eckel
parent e7039d7046
commit 386ed0f4f8
4 changed files with 45 additions and 1 deletions

View file

@ -143,6 +143,7 @@ class TicketsController < ApplicationController
clean_params = Ticket.param_cleanup(clean_params, true) clean_params = Ticket.param_cleanup(clean_params, true)
ticket = Ticket.new(clean_params) ticket = Ticket.new(clean_params)
authorize!(ticket, :create?)
# check if article is given # check if article is given
if !params[:article] if !params[:article]
@ -432,6 +433,7 @@ class TicketsController < ApplicationController
# get attributes to update # get attributes to update
attributes_to_change = Ticket::ScreenOptions.attributes_to_change( attributes_to_change = Ticket::ScreenOptions.attributes_to_change(
view: 'ticket_create',
current_user: current_user, current_user: current_user,
) )
render json: attributes_to_change render json: attributes_to_change

View file

@ -100,7 +100,11 @@ returns
filter[:group_id] = [] filter[:group_id] = []
groups = if params[:current_user].permissions?('ticket.agent') groups = if params[:current_user].permissions?('ticket.agent')
if params[:view] == 'ticket_create'
params[:current_user].groups_access(%w[create])
else
params[:current_user].groups_access(%w[create change]) params[:current_user].groups_access(%w[create change])
end
else else
Group.where(active: true) Group.where(active: true)
end end

View file

@ -5,6 +5,7 @@ class TicketPolicy < ApplicationPolicy
end end
def create? def create?
ensure_group!
access?('create') access?('create')
end end
@ -26,6 +27,12 @@ class TicketPolicy < ApplicationPolicy
access?('full') access?('full')
end end
def ensure_group!
return if record.group_id
raise Exceptions::UnprocessableEntity, "Group can't be blank"
end
def follow_up? def follow_up?
return true if user.permissions?('ticket.agent') # agents can always reopen tickets, regardless of group configuration return true if user.permissions?('ticket.agent') # agents can always reopen tickets, regardless of group configuration
return true if record.group.follow_up_possible != 'new_ticket' # check if the setting for follow_up_possible is disabled return true if record.group.follow_up_possible != 'new_ticket' # check if the setting for follow_up_possible is disabled

View file

@ -5,12 +5,22 @@ RSpec.describe 'Ticket', type: :request do
let!(:ticket_group) do let!(:ticket_group) do
create(:group, email_address: create(:email_address) ) create(:group, email_address: create(:email_address) )
end end
let!(:ticket_group_without_create) do
create(:group, email_address: create(:email_address) )
end
let(:admin) do let(:admin) do
create(:admin, groups: Group.all, firstname: 'Tickets', lastname: 'Admin') create(:admin, groups: Group.all, firstname: 'Tickets', lastname: 'Admin')
end end
let!(:agent) do let!(:agent) do
create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent') create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent')
end end
let!(:agent_change_only) do
user = create(:agent, groups: Group.all, firstname: 'Tickets', lastname: 'Agent')
user.group_names_access_map = {
ticket_group_without_create.name => %w[read change],
}
user
end
let!(:customer) do let!(:customer) do
create( create(
:customer, :customer,
@ -58,6 +68,27 @@ RSpec.describe 'Ticket', type: :request do
expect(json_response['error']).to eq('No lookup value found for \'group\': "not_existing"') expect(json_response['error']).to eq('No lookup value found for \'group\': "not_existing"')
end end
it 'does ticket create with agent - valid group but no create permissions (01.02a)' do
params = {
title: 'a new ticket #1',
group: ticket_group_without_create.name,
priority: '2 normal',
state: 'new',
customer_id: customer.id,
article: {
content_type: 'text/plain', # or text/html
body: 'some body',
sender: 'Customer',
type: 'note',
},
}
authenticated_as(agent_change_only)
post '/api/v1/tickets', params: params, as: :json
expect(response).to have_http_status(:unauthorized)
expect(json_response).to be_a_kind_of(Hash)
expect(json_response['error']).to eq('Not authorized')
end
it 'does ticket create with agent - missing article.body (01.03)' do it 'does ticket create with agent - missing article.body (01.03)' do
params = { params = {
title: 'a new ticket #3', title: 'a new ticket #3',