Fixes #3503 - ticket.customer_id is current_user breaks email fetching.

This commit is contained in:
Rolf Schmidt 2021-09-01 11:46:34 +02:00 committed by Thorsten Eckel
parent decf868823
commit 871d9609e1
6 changed files with 56 additions and 13 deletions

View file

@ -435,15 +435,15 @@ class App.UiElement.ApplicationSelector
selection = $("<select class=\"form-control\" name=\"#{name}\" ></select>") selection = $("<select class=\"form-control\" name=\"#{name}\" ></select>")
options = {} options = {}
if preCondition is 'user' if preCondition is 'user'
options = if attributeConfig.noCurrentUser isnt true
'current_user.id': App.i18n.translateInline('current user') options['current_user.id'] = App.i18n.translateInline('current user')
'specific': App.i18n.translateInline('specific user') options['specific'] = App.i18n.translateInline('specific user')
'not_set': App.i18n.translateInline('not set (not defined)') options['not_set'] = App.i18n.translateInline('not set (not defined)')
else if preCondition is 'org' else if preCondition is 'org'
options = if attributeConfig.noCurrentUser isnt true
'current_user.organization_id': App.i18n.translateInline('current user organization') options['current_user.organization_id'] = App.i18n.translateInline('current user organization')
'specific': App.i18n.translateInline('specific organization') options['specific'] = App.i18n.translateInline('specific organization')
'not_set': App.i18n.translateInline('not set (not defined)') options['not_set'] = App.i18n.translateInline('not set (not defined)')
for key, value of options for key, value of options
selected = '' selected = ''

View file

@ -5,7 +5,7 @@ class App.Job extends App.Model
@configure_attributes = [ @configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'timeplan', display: 'When should the job run?', tag: 'timer', null: true }, { name: 'timeplan', display: 'When should the job run?', tag: 'timer', null: true },
{ name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: true, executionTime: true }, { name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: true, executionTime: true, noCurrentUser: true },
{ name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true, notification: true, ticket_delete: true }, { name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true, notification: true, ticket_delete: true },
{ name: 'disable_notification', display: 'Disable Notifications', tag: 'boolean', default: true }, { name: 'disable_notification', display: 'Disable Notifications', tag: 'boolean', default: true },
{ name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, null: true }, { name: 'note', display: 'Note', tag: 'textarea', note: 'Notes are visible to agents only, never to customers.', limit: 250, null: true },

View file

@ -4,7 +4,7 @@ class App.Sla extends App.Model
@url: @apiPath + '/slas' @url: @apiPath + '/slas'
@configure_attributes = [ @configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'condition', display: 'Ticket Selector', tag: 'ticket_selector', null: false, note: 'Create rules that single out the tickets for the Service Level Agreement.' }, { name: 'condition', display: 'Ticket Selector', tag: 'ticket_selector', null: false, note: 'Create rules that single out the tickets for the Service Level Agreement.', noCurrentUser: true },
{ name: 'calendar_id', display: 'Calendar', tag: 'select', relation: 'Calendar', null: false }, { name: 'calendar_id', display: 'Calendar', tag: 'select', relation: 'Calendar', null: false },
{ name: 'sla_times', display: 'SLA Times', tag: 'sla_times', null: true }, { name: 'sla_times', display: 'SLA Times', tag: 'sla_times', null: true },
{ name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 },

View file

@ -1305,9 +1305,7 @@ perform active triggers on ticket
user_id = article.updated_by_id user_id = article.updated_by_id
end end
user = if user_id != 1 user = User.lookup(id: user_id)
User.lookup(id: user_id)
end
# verify is condition is matching # verify is condition is matching
ticket_count, tickets = Ticket.selectors(condition, limit: 1, execution_time: true, current_user: user, access: 'ignore') ticket_count, tickets = Ticket.selectors(condition, limit: 1, execution_time: true, current_user: user, access: 'ignore')

View file

@ -0,0 +1,23 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class Issue3503FixCurrentUser < ActiveRecord::Migration[6.0]
def change
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
remove_current_user(Job)
remove_current_user(Sla)
end
def remove_current_user(target)
target.find_each do |row|
row.condition.each do |key, condition|
next if condition['pre_condition'].blank?
next if condition['pre_condition'].exclude?('current_user')
row.condition.delete(key)
row.save
end
end
end
end

View file

@ -0,0 +1,22 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'rails_helper'
RSpec.describe Issue3503FixCurrentUser, type: :db_migration do
let!(:job) { create(:job) }
let!(:sla) { create(:sla) }
before do
condition = { 'ticket.organization_id' => { 'operator' => 'is', 'pre_condition' => 'current_user.organization_id', 'value' => '' }, 'ticket.action' => { 'operator' => 'is', 'value' => 'create' } }
job.update_column(:condition, condition)
sla.update_column(:condition, condition)
end
it 'removes current user condition from Jobs' do
expect { migrate }.to change { job.reload.condition }.to({ 'ticket.action'=>{ 'operator' => 'is', 'value' => 'create' } })
end
it 'removes current user condition from Slas' do
expect { migrate }.to change { sla.reload.condition }.to({ 'ticket.action'=>{ 'operator' => 'is', 'value' => 'create' } })
end
end