diff --git a/app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee b/app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee index c13490d9b..5263f59e7 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee +++ b/app/assets/javascripts/app/controllers/_ui_element/_application_selector.coffee @@ -435,15 +435,15 @@ class App.UiElement.ApplicationSelector selection = $("") options = {} if preCondition is 'user' - options = - 'current_user.id': App.i18n.translateInline('current user') - 'specific': App.i18n.translateInline('specific user') - 'not_set': App.i18n.translateInline('not set (not defined)') + if attributeConfig.noCurrentUser isnt true + options['current_user.id'] = App.i18n.translateInline('current user') + options['specific'] = App.i18n.translateInline('specific user') + options['not_set'] = App.i18n.translateInline('not set (not defined)') else if preCondition is 'org' - options = - 'current_user.organization_id': App.i18n.translateInline('current user organization') - 'specific': App.i18n.translateInline('specific organization') - 'not_set': App.i18n.translateInline('not set (not defined)') + if attributeConfig.noCurrentUser isnt true + options['current_user.organization_id'] = App.i18n.translateInline('current user organization') + options['specific'] = App.i18n.translateInline('specific organization') + options['not_set'] = App.i18n.translateInline('not set (not defined)') for key, value of options selected = '' diff --git a/app/assets/javascripts/app/models/job.coffee b/app/assets/javascripts/app/models/job.coffee index 8b7c71df2..a233213b8 100644 --- a/app/assets/javascripts/app/models/job.coffee +++ b/app/assets/javascripts/app/models/job.coffee @@ -5,7 +5,7 @@ class App.Job extends App.Model @configure_attributes = [ { 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: '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: '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 }, diff --git a/app/assets/javascripts/app/models/sla.coffee b/app/assets/javascripts/app/models/sla.coffee index cf5512afc..824db43cf 100644 --- a/app/assets/javascripts/app/models/sla.coffee +++ b/app/assets/javascripts/app/models/sla.coffee @@ -4,7 +4,7 @@ class App.Sla extends App.Model @url: @apiPath + '/slas' @configure_attributes = [ { 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: 'sla_times', display: 'SLA Times', tag: 'sla_times', null: true }, { name: 'created_by_id', display: 'Created by', relation: 'User', readonly: 1 }, diff --git a/app/models/ticket.rb b/app/models/ticket.rb index fe027e936..049f676cd 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1305,9 +1305,7 @@ perform active triggers on ticket user_id = article.updated_by_id end - user = if user_id != 1 - User.lookup(id: user_id) - end + user = User.lookup(id: user_id) # verify is condition is matching ticket_count, tickets = Ticket.selectors(condition, limit: 1, execution_time: true, current_user: user, access: 'ignore') diff --git a/db/migrate/20210830150400_issue_3503_fix_current_user.rb b/db/migrate/20210830150400_issue_3503_fix_current_user.rb new file mode 100644 index 000000000..b8cd6de1a --- /dev/null +++ b/db/migrate/20210830150400_issue_3503_fix_current_user.rb @@ -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 diff --git a/spec/db/migrate/issue_3503_fix_current_user_spec.rb b/spec/db/migrate/issue_3503_fix_current_user_spec.rb new file mode 100644 index 000000000..2a54c0317 --- /dev/null +++ b/spec/db/migrate/issue_3503_fix_current_user_spec.rb @@ -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