Init version of triggers.
This commit is contained in:
parent
ea4b7c4bd9
commit
0487fa1d12
25 changed files with 1010 additions and 142 deletions
|
@ -410,8 +410,8 @@ class App.ControllerForm extends App.Controller
|
||||||
for key in array
|
for key in array
|
||||||
|
|
||||||
# check if item is-hidden and should not be used
|
# check if item is-hidden and should not be used
|
||||||
if lookupForm.find('[name="' + key.name + '"]').hasClass('is-hidden')
|
if lookupForm.find('[name="' + key.name + '"]').hasClass('is-hidden') || lookupForm.find('div[data-name="' + key.name + '"]').hasClass('is-hidden')
|
||||||
param[key.name] = undefined
|
delete param[key.name]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# collect all params, push it to an array if already exists
|
# collect all params, push it to an array if already exists
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# coffeelint: disable=camel_case_classes
|
# coffeelint: disable=camel_case_classes
|
||||||
class App.UiElement.ticket_perform_action
|
class App.UiElement.ticket_perform_action
|
||||||
@defaults: ->
|
@defaults: (attribute) ->
|
||||||
defaults = ['ticket.state_id']
|
defaults = ['ticket.state_id']
|
||||||
|
|
||||||
groups =
|
groups =
|
||||||
|
@ -8,9 +8,18 @@ class App.UiElement.ticket_perform_action
|
||||||
name: 'Ticket'
|
name: 'Ticket'
|
||||||
model: 'Ticket'
|
model: 'Ticket'
|
||||||
|
|
||||||
|
if attribute.notification
|
||||||
|
groups.notification =
|
||||||
|
name: 'Notification'
|
||||||
|
model: 'Notification'
|
||||||
|
|
||||||
# megre config
|
# megre config
|
||||||
elements = {}
|
elements = {}
|
||||||
for groupKey, groupMeta of groups
|
for groupKey, groupMeta of groups
|
||||||
|
if !App[groupMeta.model]
|
||||||
|
elements["#{groupKey}.email"] = { name: 'email', display: 'Email' }
|
||||||
|
else
|
||||||
|
|
||||||
for row in App[groupMeta.model].configure_attributes
|
for row in App[groupMeta.model].configure_attributes
|
||||||
|
|
||||||
# ignore passwords and relations
|
# ignore passwords and relations
|
||||||
|
@ -27,12 +36,12 @@ class App.UiElement.ticket_perform_action
|
||||||
|
|
||||||
@render: (attribute, params = {}) ->
|
@render: (attribute, params = {}) ->
|
||||||
|
|
||||||
[defaults, groups, elements] = @defaults()
|
[defaults, groups, elements] = @defaults(attribute)
|
||||||
|
|
||||||
selector = @buildAttributeSelector(groups, elements)
|
selector = @buildAttributeSelector(groups, elements)
|
||||||
|
|
||||||
# return item
|
# return item
|
||||||
item = $( App.view('generic/ticket_perform_action')( attribute: attribute ) )
|
item = $( App.view('generic/ticket_perform_action/index')( attribute: attribute ) )
|
||||||
item.find('.js-attributeSelector').prepend(selector)
|
item.find('.js-attributeSelector').prepend(selector)
|
||||||
|
|
||||||
# add filter
|
# add filter
|
||||||
|
@ -65,8 +74,6 @@ class App.UiElement.ticket_perform_action
|
||||||
selectorExists = false
|
selectorExists = false
|
||||||
for groupAndAttribute, meta of params[attribute.name]
|
for groupAndAttribute, meta of params[attribute.name]
|
||||||
selectorExists = true
|
selectorExists = true
|
||||||
value = meta.value
|
|
||||||
operator = meta.operator
|
|
||||||
|
|
||||||
# get selector rows
|
# get selector rows
|
||||||
elementFirst = item.find('.js-filterElement').first()
|
elementFirst = item.find('.js-filterElement').first()
|
||||||
|
@ -149,6 +156,18 @@ class App.UiElement.ticket_perform_action
|
||||||
if groupAndAttribute
|
if groupAndAttribute
|
||||||
elementRow.find('.js-attributeSelector select').val(groupAndAttribute)
|
elementRow.find('.js-attributeSelector select').val(groupAndAttribute)
|
||||||
|
|
||||||
|
if groupAndAttribute is 'notification.email'
|
||||||
|
elementRow.find('.js-setAttribute').html('')
|
||||||
|
@buildRecipientList(elementFull, elementRow, groupAndAttribute, elements, meta, attribute)
|
||||||
|
else
|
||||||
|
elementRow.find('.js-setNotification').html('')
|
||||||
|
if !elementRow.find('.js-setAttribute div').get(0)
|
||||||
|
attributeSelectorElement = $( App.view('generic/ticket_perform_action/attribute_selector')(
|
||||||
|
attribute: attribute
|
||||||
|
name: name
|
||||||
|
meta: meta || {}
|
||||||
|
))
|
||||||
|
elementRow.find('.js-setAttribute').html(attributeSelectorElement)
|
||||||
@buildOperator(elementFull, elementRow, groupAndAttribute, elements, meta, attribute)
|
@buildOperator(elementFull, elementRow, groupAndAttribute, elements, meta, attribute)
|
||||||
|
|
||||||
@buildOperator: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
@buildOperator: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
||||||
|
@ -160,9 +179,7 @@ class App.UiElement.ticket_perform_action
|
||||||
name = "#{attribute.name}::#{groupAndAttribute}::operator"
|
name = "#{attribute.name}::#{groupAndAttribute}::operator"
|
||||||
|
|
||||||
selection = $("<select class=\"form-control\" name=\"#{name}\"></select>")
|
selection = $("<select class=\"form-control\" name=\"#{name}\"></select>")
|
||||||
|
|
||||||
attributeConfig = elements[groupAndAttribute]
|
attributeConfig = elements[groupAndAttribute]
|
||||||
|
|
||||||
if !attributeConfig.operator
|
if !attributeConfig.operator
|
||||||
elementRow.find('.js-operator').addClass('hide')
|
elementRow.find('.js-operator').addClass('hide')
|
||||||
else
|
else
|
||||||
|
@ -282,7 +299,36 @@ class App.UiElement.ticket_perform_action
|
||||||
|
|
||||||
elementRow.find('.js-value').removeClass('hide').html(item)
|
elementRow.find('.js-value').removeClass('hide').html(item)
|
||||||
|
|
||||||
|
@buildRecipientList: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
||||||
|
|
||||||
|
return if elementRow.find('.js-setNotification .js-body').get(0)
|
||||||
|
|
||||||
|
options =
|
||||||
|
'ticket_owner': 'Owner'
|
||||||
|
'ticket_customer': 'Customer'
|
||||||
|
'ticket_agents': 'All Agents'
|
||||||
|
|
||||||
|
name = "#{attribute.name}::notification.email"
|
||||||
|
|
||||||
|
selection = $("<select class=\"form-control\" name=\"#{name}::recipient\" ></select>")
|
||||||
|
for key, value of options
|
||||||
|
selected = ''
|
||||||
|
if key is meta.recipient
|
||||||
|
selected = 'selected="selected"'
|
||||||
|
selection.append("<option value=\"#{key}\" #{selected}>#{App.i18n.translateInline(value)}</option>")
|
||||||
|
|
||||||
|
notificationElement = $( App.view('generic/ticket_perform_action/notification_email')(
|
||||||
|
attribute: attribute
|
||||||
|
name: name
|
||||||
|
meta: meta || {}
|
||||||
|
))
|
||||||
|
notificationElement.find('.js-recipient select').replaceWith(selection)
|
||||||
|
notificationElement.find('.js-body div[contenteditable="true"]').ce(
|
||||||
|
mode: 'richtext'
|
||||||
|
placeholder: 'message'
|
||||||
|
maxlength: 2000
|
||||||
|
)
|
||||||
|
elementRow.find('.js-setNotification').html(notificationElement)
|
||||||
|
|
||||||
@humanText: (condition) ->
|
@humanText: (condition) ->
|
||||||
none = App.i18n.translateContent('No filter.')
|
none = App.i18n.translateContent('No filter.')
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
# coffeelint: disable=camel_case_classes
|
# coffeelint: disable=camel_case_classes
|
||||||
class App.UiElement.ticket_selector
|
class App.UiElement.ticket_selector
|
||||||
@defaults: ->
|
@defaults: (attribute) ->
|
||||||
defaults = ['ticket.state_id']
|
defaults = ['ticket.state_id']
|
||||||
|
|
||||||
groups =
|
groups =
|
||||||
ticket:
|
ticket:
|
||||||
name: 'Ticket'
|
name: 'Ticket'
|
||||||
model: 'Ticket'
|
model: 'Ticket'
|
||||||
|
#article:
|
||||||
|
# name: 'Article'
|
||||||
|
# model: 'TicketArticle'
|
||||||
customer:
|
customer:
|
||||||
name: 'Customer'
|
name: 'Customer'
|
||||||
model: 'User'
|
model: 'User'
|
||||||
|
@ -25,13 +28,25 @@ class App.UiElement.ticket_selector
|
||||||
'_id$': ['is', 'is not']
|
'_id$': ['is', 'is not']
|
||||||
'_ids$': ['is', 'is not']
|
'_ids$': ['is', 'is not']
|
||||||
|
|
||||||
# megre config
|
# merge config
|
||||||
elements = {}
|
elements = {}
|
||||||
|
|
||||||
|
if attribute.action
|
||||||
|
elements['ticket.action'] =
|
||||||
|
name: 'action'
|
||||||
|
display: 'Action'
|
||||||
|
tag: 'select'
|
||||||
|
null: false
|
||||||
|
options:
|
||||||
|
create: 'created'
|
||||||
|
update: 'updated'
|
||||||
|
operator: ['is', 'is not']
|
||||||
|
|
||||||
for groupKey, groupMeta of groups
|
for groupKey, groupMeta of groups
|
||||||
for row in App[groupMeta.model].configure_attributes
|
for row in App[groupMeta.model].configure_attributes
|
||||||
|
|
||||||
# ignore passwords and relations
|
# ignore passwords and relations
|
||||||
if row.type isnt 'password' && row.name.substr(row.name.length-4,4) isnt '_ids'
|
if row.type isnt 'password' && row.name.substr(row.name.length-4,4) isnt '_ids' && row.searchable isnt false
|
||||||
config = _.clone(row)
|
config = _.clone(row)
|
||||||
for operatorRegEx, operator of operators_type
|
for operatorRegEx, operator of operators_type
|
||||||
myRegExp = new RegExp(operatorRegEx, 'i')
|
myRegExp = new RegExp(operatorRegEx, 'i')
|
||||||
|
@ -47,13 +62,10 @@ class App.UiElement.ticket_selector
|
||||||
|
|
||||||
@render: (attribute, params = {}) ->
|
@render: (attribute, params = {}) ->
|
||||||
|
|
||||||
[defaults, groups, elements] = @defaults()
|
[defaults, groups, elements] = @defaults(attribute)
|
||||||
|
|
||||||
selector = @buildAttributeSelector(groups, elements)
|
selector = @buildAttributeSelector(groups, elements)
|
||||||
|
|
||||||
search = =>
|
|
||||||
@preview(item)
|
|
||||||
|
|
||||||
# return item
|
# return item
|
||||||
item = $( App.view('generic/ticket_selector')(attribute: attribute) )
|
item = $( App.view('generic/ticket_selector')(attribute: attribute) )
|
||||||
item.find('.js-attributeSelector').prepend(selector)
|
item.find('.js-attributeSelector').prepend(selector)
|
||||||
|
@ -65,6 +77,7 @@ class App.UiElement.ticket_selector
|
||||||
element.after(elementClone)
|
element.after(elementClone)
|
||||||
elementClone.find('.js-attributeSelector select').trigger('change')
|
elementClone.find('.js-attributeSelector select').trigger('change')
|
||||||
@updateAttributeSelectors(item)
|
@updateAttributeSelectors(item)
|
||||||
|
if attribute.preview isnt false
|
||||||
@preview(item)
|
@preview(item)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,6 +86,7 @@ class App.UiElement.ticket_selector
|
||||||
return if $(e.currentTarget).hasClass('is-disabled')
|
return if $(e.currentTarget).hasClass('is-disabled')
|
||||||
$(e.target).closest('.js-filterElement').remove()
|
$(e.target).closest('.js-filterElement').remove()
|
||||||
@updateAttributeSelectors(item)
|
@updateAttributeSelectors(item)
|
||||||
|
if attribute.preview isnt false
|
||||||
@preview(item)
|
@preview(item)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -108,23 +122,6 @@ class App.UiElement.ticket_selector
|
||||||
elementLast.after(elementClone)
|
elementLast.after(elementClone)
|
||||||
item.find('.js-filterElement').first().remove()
|
item.find('.js-filterElement').first().remove()
|
||||||
|
|
||||||
triggerSearch = ->
|
|
||||||
item.find('.js-previewCounterContainer').addClass('hide')
|
|
||||||
item.find('.js-previewLoader').removeClass('hide')
|
|
||||||
App.Delay.set(
|
|
||||||
search,
|
|
||||||
600,
|
|
||||||
'preview',
|
|
||||||
)
|
|
||||||
|
|
||||||
# bind for preview
|
|
||||||
item.on('change', 'select.form-control', (e) ->
|
|
||||||
triggerSearch()
|
|
||||||
)
|
|
||||||
item.on('change keyup', 'input.form-control', (e) ->
|
|
||||||
triggerSearch()
|
|
||||||
)
|
|
||||||
|
|
||||||
# change attribute selector
|
# change attribute selector
|
||||||
item.find('.js-attributeSelector select').bind('change', (e) =>
|
item.find('.js-attributeSelector select').bind('change', (e) =>
|
||||||
elementRow = $(e.target).closest('.js-filterElement')
|
elementRow = $(e.target).closest('.js-filterElement')
|
||||||
|
@ -140,6 +137,27 @@ class App.UiElement.ticket_selector
|
||||||
@buildOperator(item, elementRow, groupAndAttribute, elements, {}, attribute)
|
@buildOperator(item, elementRow, groupAndAttribute, elements, {}, attribute)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# bind for preview
|
||||||
|
if attribute.preview isnt false
|
||||||
|
search = =>
|
||||||
|
@preview(item)
|
||||||
|
|
||||||
|
triggerSearch = ->
|
||||||
|
item.find('.js-previewCounterContainer').addClass('hide')
|
||||||
|
item.find('.js-previewLoader').removeClass('hide')
|
||||||
|
App.Delay.set(
|
||||||
|
search,
|
||||||
|
600,
|
||||||
|
'preview',
|
||||||
|
)
|
||||||
|
|
||||||
|
item.on('change', 'select', (e) ->
|
||||||
|
triggerSearch()
|
||||||
|
)
|
||||||
|
item.on('change keyup', 'input', (e) ->
|
||||||
|
triggerSearch()
|
||||||
|
)
|
||||||
|
|
||||||
item
|
item
|
||||||
|
|
||||||
@preview: (item) ->
|
@preview: (item) ->
|
||||||
|
|
|
@ -10,7 +10,6 @@ class Index extends App.ControllerContent
|
||||||
id: @id
|
id: @id
|
||||||
genericObject: 'Trigger'
|
genericObject: 'Trigger'
|
||||||
defaultSortBy: 'name'
|
defaultSortBy: 'name'
|
||||||
#groupBy: 'role'
|
|
||||||
pageData:
|
pageData:
|
||||||
title: 'Triggers'
|
title: 'Triggers'
|
||||||
home: 'triggers'
|
home: 'triggers'
|
||||||
|
|
|
@ -4,9 +4,8 @@ class App.Trigger extends App.Model
|
||||||
@url: @apiPath + '/triggers'
|
@url: @apiPath + '/triggers'
|
||||||
@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: 'Conditions for effected objects', tag: 'ticket_selector', null: false },
|
{ name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: true },
|
||||||
{ name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true },
|
{ name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true, notification: true },
|
||||||
{ name: 'disable_notiifcation', display: 'Disable Notifications', tag: 'boolean', default: true },
|
|
||||||
{ name: 'active', display: 'Active', tag: 'active', default: true },
|
{ name: 'active', display: 'Active', tag: 'active', default: true },
|
||||||
{ name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 },
|
{ name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 },
|
||||||
]
|
]
|
||||||
|
@ -14,8 +13,9 @@ class App.Trigger extends App.Model
|
||||||
@configure_overview = [
|
@configure_overview = [
|
||||||
'name',
|
'name',
|
||||||
]
|
]
|
||||||
|
###
|
||||||
@description = '''
|
@description = '''
|
||||||
Trigger are....
|
Trigger are....
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
###
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<div class="flex horizontal">
|
||||||
|
<div class="controls">
|
||||||
|
<div class="u-positionOrigin js-operator">
|
||||||
|
<select></select>
|
||||||
|
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<div class="u-positionOrigin js-preCondition">
|
||||||
|
<select></select>
|
||||||
|
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="controls js-value"></div>
|
||||||
|
</div>
|
|
@ -6,19 +6,8 @@
|
||||||
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="controls">
|
<div class="js-setAttribute"></div>
|
||||||
<div class="u-positionOrigin js-operator">
|
<div class="js-setNotification flex"></div>
|
||||||
<select></select>
|
|
||||||
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="controls">
|
|
||||||
<div class="u-positionOrigin js-preCondition">
|
|
||||||
<select></select>
|
|
||||||
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="controls js-value"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="filter-controls">
|
<div class="filter-controls">
|
||||||
<div class="filter-control filter-control-remove js-remove" title="<%- @Ti('Remote') %>">
|
<div class="filter-control filter-control-remove js-remove" title="<%- @Ti('Remote') %>">
|
|
@ -0,0 +1,8 @@
|
||||||
|
<div class="flex">
|
||||||
|
<div class="controls js-recipient u-positionOrigin">
|
||||||
|
<select></select>
|
||||||
|
<%- @Icon('arrow-down', 'dropdown-arrow') %>
|
||||||
|
</div>
|
||||||
|
<div class="controls js-subject"><input type="text" name="<%= @name %>::subject" value="<%= @meta.subject %>" style="width: 100%;" placeholder="<%- @T('Subject') %>"></div>
|
||||||
|
<div class="controls js-body"><div class="richtext form-control"><div contenteditable="true" data-name="<%= @name %>::body"><%- @meta.body %></div></div></div>
|
||||||
|
</div>
|
|
@ -30,7 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="js-preview">
|
<div class="js-preview <% if @attribute.preview is false: %>hide<% end %>">
|
||||||
<h3><%- @T('Preview') %><span class="subtitle js-previewCounterContainer hide"> <span class="u-highlight js-previewCounter">?</span> <%- @T('matches') %></span> <span class="tiny loading icon js-previewLoader hide" style="margin-left: 3px;"></span></h3>
|
<h3><%- @T('Preview') %><span class="subtitle js-previewCounterContainer hide"> <span class="u-highlight js-previewCounter">?</span> <%- @T('matches') %></span> <span class="tiny loading icon js-previewLoader hide" style="margin-left: 3px;"></span></h3>
|
||||||
<div class="js-previewTable"></div>
|
<div class="js-previewTable"></div>
|
||||||
</div>
|
</div>
|
|
@ -44,21 +44,7 @@ class Job < ApplicationModel
|
||||||
# use transaction
|
# use transaction
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
UserInfo.current_user_id = 1
|
UserInfo.current_user_id = 1
|
||||||
|
ticket.perform_changes(job.perform, 'job')
|
||||||
logger.debug "Perform job #{job.perform.inspect} in Ticket.find(#{ticket.id})"
|
|
||||||
changed = false
|
|
||||||
job.perform.each do |key, value|
|
|
||||||
(object_name, attribute) = key.split('.', 2)
|
|
||||||
raise "Unable to update object #{object_name}.#{attribute}, only can update tickets!" if object_name != 'ticket'
|
|
||||||
|
|
||||||
next if ticket[attribute].to_s == value['value'].to_s
|
|
||||||
changed = true
|
|
||||||
|
|
||||||
ticket[attribute] = value['value']
|
|
||||||
logger.debug "set #{object_name}.#{attribute} = #{value['value'].inspect}"
|
|
||||||
end
|
|
||||||
next if !changed
|
|
||||||
ticket.save
|
|
||||||
|
|
||||||
# execute object transaction
|
# execute object transaction
|
||||||
Observer::Transaction.commit(
|
Observer::Transaction.commit(
|
||||||
|
|
|
@ -19,6 +19,12 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
|
|
||||||
channel = ticket.group.email_address.channel
|
channel = ticket.group.email_address.channel
|
||||||
|
|
||||||
|
notification = false
|
||||||
|
sender = Ticket::Article::Sender.lookup(id: record.sender_id)
|
||||||
|
if sender['name'] == 'System'
|
||||||
|
notification = true
|
||||||
|
end
|
||||||
|
|
||||||
# get linked channel and send
|
# get linked channel and send
|
||||||
message = channel.deliver(
|
message = channel.deliver(
|
||||||
{
|
{
|
||||||
|
@ -32,7 +38,8 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
content_type: record.content_type,
|
content_type: record.content_type,
|
||||||
body: record.body,
|
body: record.body,
|
||||||
attachments: record.attachments
|
attachments: record.attachments
|
||||||
}
|
},
|
||||||
|
notification
|
||||||
)
|
)
|
||||||
|
|
||||||
# store mail plain
|
# store mail plain
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
||||||
raise "No email address found for group '#{ticket.group.name}'"
|
raise "No email address found for group '#{ticket.group.name}'"
|
||||||
end
|
end
|
||||||
system_sender = "#{email_address.realname} <#{email_address.email}>"
|
system_sender = "#{email_address.realname} <#{email_address.email}>"
|
||||||
if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
|
if record.created_by_id != 1 && Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
|
||||||
seperator = Setting.get('ticket_define_email_from_seperator')
|
seperator = Setting.get('ticket_define_email_from_seperator')
|
||||||
sender = User.find(record.created_by_id)
|
sender = User.find(record.created_by_id)
|
||||||
record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"
|
record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"
|
||||||
|
|
|
@ -26,15 +26,41 @@ class Observer::Transaction < ActiveRecord::Observer
|
||||||
# reset buffer
|
# reset buffer
|
||||||
EventBuffer.reset('transaction')
|
EventBuffer.reset('transaction')
|
||||||
|
|
||||||
|
# get asyn backends
|
||||||
|
sync_backends = []
|
||||||
|
Setting.where(area: 'Transaction::Backend::Sync').order(:name).each {|setting|
|
||||||
|
backend = Setting.get(setting.name)
|
||||||
|
sync_backends.push Kernel.const_get(backend)
|
||||||
|
}
|
||||||
|
|
||||||
# get uniq objects
|
# get uniq objects
|
||||||
list_objects = get_uniq_changes(list)
|
list_objects = get_uniq_changes(list)
|
||||||
list_objects.each {|_object, objects|
|
list_objects.each {|_object, objects|
|
||||||
objects.each {|_id, item|
|
objects.each {|_id, item|
|
||||||
|
|
||||||
|
# execute sync backends
|
||||||
|
sync_backends.each {|backend|
|
||||||
|
execute_singel_backend(backend, item, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
# execute async backends
|
||||||
Delayed::Job.enqueue(Transaction::BackgroundJob.new(item, params))
|
Delayed::Job.enqueue(Transaction::BackgroundJob.new(item, params))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.execute_singel_backend(backend, item, params)
|
||||||
|
Rails.logger.error "Execute singel backend #{backend}"
|
||||||
|
begin
|
||||||
|
UserInfo.current_user_id = nil
|
||||||
|
integration = backend.new(item, params)
|
||||||
|
integration.perform
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.error 'ERROR: ' + backend.inspect
|
||||||
|
Rails.logger.error 'ERROR: ' + e.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
result = get_uniq_changes(events)
|
result = get_uniq_changes(events)
|
||||||
|
|
|
@ -16,9 +16,13 @@ class Tag < ApplicationModel
|
||||||
tag_object_id = tag_object_lookup(data[:object])
|
tag_object_id = tag_object_lookup(data[:object])
|
||||||
end
|
end
|
||||||
if data[:item]
|
if data[:item]
|
||||||
tag_item_id = tag_item_lookup( data[:item] )
|
tag_item_id = tag_item_lookup(data[:item].strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# return in duplicate
|
||||||
|
current_tags = tag_list(data)
|
||||||
|
return true if current_tags.include?(data[:item].downcase.strip)
|
||||||
|
|
||||||
# create history
|
# create history
|
||||||
Tag.create(
|
Tag.create(
|
||||||
tag_object_id: tag_object_id,
|
tag_object_id: tag_object_id,
|
||||||
|
@ -36,7 +40,7 @@ class Tag < ApplicationModel
|
||||||
tag_object_id = tag_object_lookup(data[:object])
|
tag_object_id = tag_object_lookup(data[:object])
|
||||||
end
|
end
|
||||||
if data[:item]
|
if data[:item]
|
||||||
tag_item_id = tag_item_lookup( data[:item] )
|
tag_item_id = tag_item_lookup(data[:item].strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
# create history
|
# create history
|
||||||
|
@ -88,9 +92,7 @@ class Tag < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
# create
|
# create
|
||||||
tag_item = Tag::Item.create(
|
tag_item = Tag::Item.create(name: name)
|
||||||
name: name
|
|
||||||
)
|
|
||||||
@@cache_item[name] = tag_item.id
|
@@cache_item[name] = tag_item.id
|
||||||
tag_item.id
|
tag_item.id
|
||||||
end
|
end
|
||||||
|
@ -119,9 +121,7 @@ class Tag < ApplicationModel
|
||||||
end
|
end
|
||||||
|
|
||||||
# create
|
# create
|
||||||
tag_object = Tag::Object.create(
|
tag_object = Tag::Object.create(name: name)
|
||||||
name: name
|
|
||||||
)
|
|
||||||
@@cache_object[name] = tag_object.id
|
@@cache_object[name] = tag_object.id
|
||||||
tag_object.id
|
tag_object.id
|
||||||
end
|
end
|
||||||
|
|
|
@ -457,6 +457,9 @@ condition example
|
||||||
elsif selector[0] == 'owner'
|
elsif selector[0] == 'owner'
|
||||||
tables += ', users owners'
|
tables += ', users owners'
|
||||||
query += 'tickets.owner_id = owners.id'
|
query += 'tickets.owner_id = owners.id'
|
||||||
|
elsif selector[0] == 'article'
|
||||||
|
tables += ', ticket_articles articles'
|
||||||
|
query += 'tickets.id = articles.ticket_id'
|
||||||
else
|
else
|
||||||
raise "invalid selector #{attribute.inspect}->#{selector.inspect}"
|
raise "invalid selector #{attribute.inspect}->#{selector.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -630,6 +633,129 @@ condition example
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
perform changes on ticket
|
||||||
|
|
||||||
|
ticket.perform_changes({}, 'trigger')
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def perform_changes(perform, log)
|
||||||
|
logger.debug "Perform #{log} #{perform.inspect} on Ticket.find(#{id})"
|
||||||
|
changed = false
|
||||||
|
perform.each do |key, value|
|
||||||
|
(object_name, attribute) = key.split('.', 2)
|
||||||
|
raise "Unable to update object #{object_name}.#{attribute}, only can update tickets and send notifications!" if object_name != 'ticket' && object_name != 'notification'
|
||||||
|
|
||||||
|
# send notification
|
||||||
|
if object_name == 'notification'
|
||||||
|
recipients = []
|
||||||
|
if value['recipient'] == 'ticket_customer'
|
||||||
|
recipients.push User.lookup(id: customer_id)
|
||||||
|
elsif value['recipient'] == 'ticket_owner'
|
||||||
|
recipients.push User.lookup(id: owner_id)
|
||||||
|
elsif value['recipient'] == 'ticket_agents'
|
||||||
|
recipients = recipients.concat(agent_of_group)
|
||||||
|
else
|
||||||
|
logger.error "Unknown email notification recipient '#{value['recipient']}'"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
recipient_string = ''
|
||||||
|
recipient_already = {}
|
||||||
|
recipients.each {|user|
|
||||||
|
next if !user.email
|
||||||
|
next if user.email !~ /@/
|
||||||
|
email = user.email.downcase.strip
|
||||||
|
next if recipient_already[email]
|
||||||
|
recipient_already[email] = true
|
||||||
|
if recipient_string != ''
|
||||||
|
recipient_string += ', '
|
||||||
|
end
|
||||||
|
recipient_string += email
|
||||||
|
}
|
||||||
|
next if recipient_string == ''
|
||||||
|
group = self.group
|
||||||
|
next if !group
|
||||||
|
email_address = group.email_address
|
||||||
|
next if !email_address
|
||||||
|
next if !email_address.channel_id
|
||||||
|
|
||||||
|
objects = {
|
||||||
|
ticket: self,
|
||||||
|
article: articles.last,
|
||||||
|
#recipient: user,
|
||||||
|
#changes: changes,
|
||||||
|
}
|
||||||
|
|
||||||
|
# get subject
|
||||||
|
value['subject'].gsub!(/\#\{(.+?)\}/, '<%= d "\\1", false %>')
|
||||||
|
subject = NotificationFactory::Mailer.template(
|
||||||
|
templateInline: value['subject'],
|
||||||
|
locale: 'en-en',
|
||||||
|
objects: objects,
|
||||||
|
)
|
||||||
|
subject = subject_build(subject)
|
||||||
|
|
||||||
|
value['body'].gsub!(/\#\{(.+?)\}/, '<%= d "\\1", true %>')
|
||||||
|
body = NotificationFactory::Mailer.template(
|
||||||
|
templateInline: value['body'],
|
||||||
|
locale: 'en-en',
|
||||||
|
objects: objects,
|
||||||
|
)
|
||||||
|
Ticket::Article.create(
|
||||||
|
ticket_id: id,
|
||||||
|
#from: 'some_sender@example.com',
|
||||||
|
to: recipient_string,
|
||||||
|
subject: subject,
|
||||||
|
content_type: 'text/html',
|
||||||
|
body: body,
|
||||||
|
internal: false,
|
||||||
|
sender: Ticket::Article::Sender.find_by(name: 'System'),
|
||||||
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
# update tags
|
||||||
|
if key == 'ticket.tags'
|
||||||
|
next if value['value'].empty?
|
||||||
|
tags = value['value'].split(/,/)
|
||||||
|
if value['operator'] == 'add'
|
||||||
|
tags.each {|tag|
|
||||||
|
Tag.tag_add(
|
||||||
|
object: 'Ticket',
|
||||||
|
o_id: id,
|
||||||
|
item: tag,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
elsif value['operator'] == 'remove'
|
||||||
|
tags.each {|tag|
|
||||||
|
Tag.tag_remove(
|
||||||
|
object: 'Ticket',
|
||||||
|
o_id: id,
|
||||||
|
item: tag,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.error "Unknown #{attribute} operator #{value['operator']}"
|
||||||
|
end
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
# update ticket
|
||||||
|
next if self[attribute].to_s == value['value'].to_s
|
||||||
|
changed = true
|
||||||
|
|
||||||
|
self[attribute] = value['value']
|
||||||
|
logger.debug "set #{object_name}.#{attribute} = #{value['value'].inspect}"
|
||||||
|
end
|
||||||
|
return if !changed
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
get all email references headers of a ticket, to exclude some, parse it as array into method
|
get all email references headers of a ticket, to exclude some, parse it as array into method
|
||||||
|
|
||||||
references = ticket.get_references
|
references = ticket.get_references
|
||||||
|
|
|
@ -22,16 +22,9 @@ class Transaction::BackgroundJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Setting.where(area: 'Transaction::Backend').order(:name).each {|setting|
|
Setting.where(area: 'Transaction::Backend::Async').order(:name).each {|setting|
|
||||||
backend = Setting.get(setting.name)
|
backend = Kernel.const_get(Setting.get(setting.name))
|
||||||
begin
|
Observer::Transaction.execute_singel_backend(backend, @item, @params)
|
||||||
UserInfo.current_user_id = nil
|
|
||||||
integration = Kernel.const_get(backend).new(@item, @params)
|
|
||||||
integration.perform
|
|
||||||
rescue => e
|
|
||||||
Rails.logger.error 'ERROR: ' + setting.inspect
|
|
||||||
Rails.logger.error 'ERROR: ' + e.inspect
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
77
app/models/transaction/trigger.rb
Normal file
77
app/models/transaction/trigger.rb
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
class Transaction::Trigger
|
||||||
|
|
||||||
|
=begin
|
||||||
|
{
|
||||||
|
object: 'Ticket',
|
||||||
|
type: 'update',
|
||||||
|
object_id: 123,
|
||||||
|
via_web: true,
|
||||||
|
changes: {
|
||||||
|
'attribute1' => [before, now],
|
||||||
|
'attribute2' => [before, now],
|
||||||
|
}
|
||||||
|
user_id: 123,
|
||||||
|
},
|
||||||
|
=end
|
||||||
|
|
||||||
|
def initialize(item, params = {})
|
||||||
|
@item = item
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
|
||||||
|
# return if we run import mode
|
||||||
|
return if Setting.get('import_mode')
|
||||||
|
|
||||||
|
return if @item[:object] != 'Ticket'
|
||||||
|
|
||||||
|
triggers = Trigger.where(active: true)
|
||||||
|
return if triggers.empty?
|
||||||
|
|
||||||
|
ticket = Ticket.lookup(id: @item[:object_id])
|
||||||
|
return if !ticket
|
||||||
|
if @item[:article_id]
|
||||||
|
article = Ticket::Article.lookup(id: @item[:article_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
UserInfo.current_user_id = 1
|
||||||
|
|
||||||
|
triggers.each {|trigger|
|
||||||
|
condition = trigger.condition
|
||||||
|
|
||||||
|
# check action
|
||||||
|
if condition['ticket.action']
|
||||||
|
next if condition['ticket.action']['operator'] == 'is' && condition['ticket.action']['value'] != @item[:type]
|
||||||
|
next if condition['ticket.action']['operator'] != 'is' && condition['ticket.action']['value'] == @item[:type]
|
||||||
|
condition.delete('ticket.action')
|
||||||
|
end
|
||||||
|
|
||||||
|
condition['ticket.id'] = {
|
||||||
|
operator: 'is',
|
||||||
|
value: ticket.id,
|
||||||
|
}
|
||||||
|
ticket_count, tickets = Ticket.selectors(condition, 1)
|
||||||
|
next if ticket_count == 0
|
||||||
|
next if tickets.first.id != ticket.id
|
||||||
|
|
||||||
|
# check in min one attribute has changed
|
||||||
|
if @item[:type] == 'update'
|
||||||
|
match = false
|
||||||
|
trigger.condition.each do |key, _value|
|
||||||
|
(object_name, attribute) = key.split('.', 2)
|
||||||
|
next if object_name != 'ticket'
|
||||||
|
next if !@item[:changes][attribute]
|
||||||
|
match = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
next if !match
|
||||||
|
end
|
||||||
|
|
||||||
|
ticket.perform_changes(trigger.perform, 'trigger')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,4 +1,7 @@
|
||||||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
class Trigger < ActiveRecord::Base
|
class Trigger < ApplicationModel
|
||||||
|
store :condition
|
||||||
|
store :perform
|
||||||
|
validates :name, presence: true
|
||||||
end
|
end
|
||||||
|
|
63
db/migrate/20160501000001_update_transaction.rb
Normal file
63
db/migrate/20160501000001_update_transaction.rb
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
class UpdateTransaction < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
|
||||||
|
# return if it's a new setup
|
||||||
|
return if !Setting.find_by(name: 'system_init_done')
|
||||||
|
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define sync transaction backend.',
|
||||||
|
name: '0100_trigger',
|
||||||
|
area: 'Transaction::Backend::Sync',
|
||||||
|
description: 'Define the transaction backend to execute triggers.',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::Trigger',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define transaction backend.',
|
||||||
|
name: '0100_notification',
|
||||||
|
area: 'Transaction::Backend::Async',
|
||||||
|
description: 'Define the transaction backend to send agent notifications.',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::Notification',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define transaction backend.',
|
||||||
|
name: '1000_signature_detection',
|
||||||
|
area: 'Transaction::Backend::Async',
|
||||||
|
description: 'Define the transaction backend to detect customers signature in email.',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::SignatureDetection',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define transaction backend.',
|
||||||
|
name: '6000_slack_webhook',
|
||||||
|
area: 'Transaction::Backend::Async',
|
||||||
|
description: 'Define the transaction backend which posts messages to (http://www.slack.com).',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::Slack',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define transaction backend.',
|
||||||
|
name: '9000_clearbit_enrichment',
|
||||||
|
area: 'Transaction::Backend::Async',
|
||||||
|
description: 'Define the transaction backend which will enrich customer and organization informations from (http://www.clearbit.com).',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::ClearbitEnrichment',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
Setting.create_or_update(
|
||||||
|
title: 'Define transaction backend.',
|
||||||
|
name: '9100_cti_caller_id_detection',
|
||||||
|
area: 'Transaction::Backend::Async',
|
||||||
|
description: 'Define the transaction backend which detects caller ids in objects and store them for cti lookups.',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::CtiCallerIdDetection',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
19
db/seeds.rb
19
db/seeds.rb
|
@ -1769,10 +1769,19 @@ Setting.create_if_not_exists(
|
||||||
preferences: { prio: 4 },
|
preferences: { prio: 4 },
|
||||||
frontend: false
|
frontend: false
|
||||||
)
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
title: 'Define sync transaction backend.',
|
||||||
|
name: '0100_trigger',
|
||||||
|
area: 'Transaction::Backend::Sync',
|
||||||
|
description: 'Define the transaction backend to execute triggers.',
|
||||||
|
options: {},
|
||||||
|
state: 'Transaction::Trigger',
|
||||||
|
frontend: false
|
||||||
|
)
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define transaction backend.',
|
title: 'Define transaction backend.',
|
||||||
name: '0100_notification',
|
name: '0100_notification',
|
||||||
area: 'Transaction::Backend',
|
area: 'Transaction::Backend::Async',
|
||||||
description: 'Define the transaction backend to send agent notifications.',
|
description: 'Define the transaction backend to send agent notifications.',
|
||||||
options: {},
|
options: {},
|
||||||
state: 'Transaction::Notification',
|
state: 'Transaction::Notification',
|
||||||
|
@ -1781,7 +1790,7 @@ Setting.create_if_not_exists(
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define transaction backend.',
|
title: 'Define transaction backend.',
|
||||||
name: '1000_signature_detection',
|
name: '1000_signature_detection',
|
||||||
area: 'Transaction::Backend',
|
area: 'Transaction::Backend::Async',
|
||||||
description: 'Define the transaction backend to detect customers signature in email.',
|
description: 'Define the transaction backend to detect customers signature in email.',
|
||||||
options: {},
|
options: {},
|
||||||
state: 'Transaction::SignatureDetection',
|
state: 'Transaction::SignatureDetection',
|
||||||
|
@ -1790,7 +1799,7 @@ Setting.create_if_not_exists(
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define transaction backend.',
|
title: 'Define transaction backend.',
|
||||||
name: '6000_slack_webhook',
|
name: '6000_slack_webhook',
|
||||||
area: 'Transaction::Backend',
|
area: 'Transaction::Backend::Async',
|
||||||
description: 'Define the transaction backend which posts messages to (http://www.slack.com).',
|
description: 'Define the transaction backend which posts messages to (http://www.slack.com).',
|
||||||
options: {},
|
options: {},
|
||||||
state: 'Transaction::Slack',
|
state: 'Transaction::Slack',
|
||||||
|
@ -1900,7 +1909,7 @@ Setting.create_if_not_exists(
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define transaction backend.',
|
title: 'Define transaction backend.',
|
||||||
name: '9000_clearbit_enrichment',
|
name: '9000_clearbit_enrichment',
|
||||||
area: 'Transaction::Backend',
|
area: 'Transaction::Backend::Async',
|
||||||
description: 'Define the transaction backend which will enrich customer and organization informations from (http://www.clearbit.com).',
|
description: 'Define the transaction backend which will enrich customer and organization informations from (http://www.clearbit.com).',
|
||||||
options: {},
|
options: {},
|
||||||
state: 'Transaction::ClearbitEnrichment',
|
state: 'Transaction::ClearbitEnrichment',
|
||||||
|
@ -1909,7 +1918,7 @@ Setting.create_if_not_exists(
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
title: 'Define transaction backend.',
|
title: 'Define transaction backend.',
|
||||||
name: '9100_cti_caller_id_detection',
|
name: '9100_cti_caller_id_detection',
|
||||||
area: 'Transaction::Backend',
|
area: 'Transaction::Backend::Async',
|
||||||
description: 'Define the transaction backend which detects caller ids in objects and store them for cti lookups.',
|
description: 'Define the transaction backend which detects caller ids in objects and store them for cti lookups.',
|
||||||
options: {},
|
options: {},
|
||||||
state: 'Transaction::CtiCallerIdDetection',
|
state: 'Transaction::CtiCallerIdDetection',
|
||||||
|
|
|
@ -474,7 +474,6 @@ test("form dependend fields check", function() {
|
||||||
var test_params = {
|
var test_params = {
|
||||||
input1: "",
|
input1: "",
|
||||||
input2: "some used default",
|
input2: "some used default",
|
||||||
input3: undefined,
|
|
||||||
select1: "false",
|
select1: "false",
|
||||||
select2: "false",
|
select2: "false",
|
||||||
selectmulti2: [ "true", "false" ],
|
selectmulti2: [ "true", "false" ],
|
||||||
|
@ -503,7 +502,6 @@ test("form dependend fields check", function() {
|
||||||
params = App.ControllerForm.params(el)
|
params = App.ControllerForm.params(el)
|
||||||
test_params = {
|
test_params = {
|
||||||
input1: "",
|
input1: "",
|
||||||
input2: undefined,
|
|
||||||
input3: "some used default",
|
input3: "some used default",
|
||||||
select1: "true",
|
select1: "true",
|
||||||
select2: "false",
|
select2: "false",
|
||||||
|
@ -853,7 +851,6 @@ test("form required_if + shown_if", function() {
|
||||||
input1: "some not used default33",
|
input1: "some not used default33",
|
||||||
input2: "some name66",
|
input2: "some name66",
|
||||||
input3: "some name77",
|
input3: "some name77",
|
||||||
input4: undefined,
|
|
||||||
active: true,
|
active: true,
|
||||||
};
|
};
|
||||||
params = App.ControllerForm.params(el)
|
params = App.ControllerForm.params(el)
|
||||||
|
@ -868,9 +865,6 @@ test("form required_if + shown_if", function() {
|
||||||
el.find('[name="{boolean}active"]').val('false').trigger('change')
|
el.find('[name="{boolean}active"]').val('false').trigger('change')
|
||||||
test_params = {
|
test_params = {
|
||||||
input1: "some not used default33",
|
input1: "some not used default33",
|
||||||
input2: undefined,
|
|
||||||
input3: undefined,
|
|
||||||
input4: undefined,
|
|
||||||
active: false,
|
active: false,
|
||||||
};
|
};
|
||||||
params = App.ControllerForm.params(el)
|
params = App.ControllerForm.params(el)
|
||||||
|
@ -886,7 +880,6 @@ test("form required_if + shown_if", function() {
|
||||||
input1: "some not used default33",
|
input1: "some not used default33",
|
||||||
input2: "some name66",
|
input2: "some name66",
|
||||||
input3: "some name77",
|
input3: "some name77",
|
||||||
input4: undefined,
|
|
||||||
active: true,
|
active: true,
|
||||||
};
|
};
|
||||||
params = App.ControllerForm.params(el)
|
params = App.ControllerForm.params(el)
|
||||||
|
|
|
@ -268,7 +268,7 @@ test('form checks', function() {
|
||||||
model: {
|
model: {
|
||||||
configure_attributes: [
|
configure_attributes: [
|
||||||
{ name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
|
{ name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
|
||||||
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true },
|
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
autofocus: true
|
autofocus: true
|
||||||
|
@ -290,7 +290,7 @@ test('form checks', function() {
|
||||||
deepEqual(params, test_params, 'form param check');
|
deepEqual(params, test_params, 'form param check');
|
||||||
|
|
||||||
/* with params or defaults */
|
/* with params or defaults */
|
||||||
$('#forms').append('<hr><h1>form time check</h1><form id="form3"></form>')
|
$('#forms').append('<hr><h1>form 3</h1><form id="form3"></form>')
|
||||||
var el = $('#form3')
|
var el = $('#form3')
|
||||||
var defaults = {
|
var defaults = {
|
||||||
condition: {
|
condition: {
|
||||||
|
@ -342,6 +342,11 @@ test('form checks', function() {
|
||||||
operator: 'remove',
|
operator: 'remove',
|
||||||
value: 'tag1, tag2',
|
value: 'tag1, tag2',
|
||||||
},
|
},
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_customer',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: "some<br>\nbody",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
new App.ControllerForm({
|
new App.ControllerForm({
|
||||||
|
@ -349,7 +354,7 @@ test('form checks', function() {
|
||||||
model: {
|
model: {
|
||||||
configure_attributes: [
|
configure_attributes: [
|
||||||
{ name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
|
{ name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
|
||||||
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true },
|
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
params: defaults,
|
params: defaults,
|
||||||
|
@ -409,6 +414,11 @@ test('form checks', function() {
|
||||||
operator: 'remove',
|
operator: 'remove',
|
||||||
value: 'tag1, tag2',
|
value: 'tag1, tag2',
|
||||||
},
|
},
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_customer',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: "some<br>\nbody",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
deepEqual(params, test_params, 'form param check')
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
@ -464,12 +474,172 @@ test('form checks', function() {
|
||||||
operator: 'remove',
|
operator: 'remove',
|
||||||
value: 'tag1, tag2',
|
value: 'tag1, tag2',
|
||||||
},
|
},
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_customer',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: "some<br>\nbody",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
deepEqual(params, test_params, 'form param check')
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
//deepEqual(el.find('[name="times::days"]').val(), ['mon', 'wed'], 'check times::days value')
|
// change selector
|
||||||
//equal(el.find('[name="times::hours"]').val(), 2, 'check times::hours value')
|
el.find('[name="executions::notification.email::subject"]').closest('.js-filterElement').find('.js-remove').click()
|
||||||
//equal(el.find('[name="times::minutes"]').val(), null, 'check times::minutes value')
|
|
||||||
|
var params = App.ControllerForm.params(el)
|
||||||
|
var test_params = {
|
||||||
|
condition: {
|
||||||
|
'ticket.title': {
|
||||||
|
operator: 'contains',
|
||||||
|
value: 'some title',
|
||||||
|
},
|
||||||
|
'ticket.created_at': {
|
||||||
|
operator: 'before (absolute)',
|
||||||
|
value: '2015-09-20T03:41:00.000Z',
|
||||||
|
},
|
||||||
|
'ticket.updated_at': {
|
||||||
|
operator: 'within last (relative)',
|
||||||
|
range: 'year',
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
'ticket.organization_id': {
|
||||||
|
operator: 'is not',
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '12',
|
||||||
|
},
|
||||||
|
'ticket.owner_id': {
|
||||||
|
operator: 'is',
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '47',
|
||||||
|
value_completion: 'Bob Smith <bod@example.com>',
|
||||||
|
},
|
||||||
|
'ticket.created_by_id': {
|
||||||
|
operator: 'is',
|
||||||
|
pre_condition: 'current_user.id',
|
||||||
|
value: '',
|
||||||
|
value_completion: ''
|
||||||
|
},
|
||||||
|
},
|
||||||
|
executions: {
|
||||||
|
'ticket.priority_id': {
|
||||||
|
value: '3',
|
||||||
|
},
|
||||||
|
'ticket.owner_id': {
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '47',
|
||||||
|
value_completion: 'Bob Smith <bod@example.com>'
|
||||||
|
},
|
||||||
|
'ticket.tags': {
|
||||||
|
operator: 'remove',
|
||||||
|
value: 'tag1, tag2',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
|
// change selector
|
||||||
|
el.find('.js-attributeSelector').last().find('select').val('notification.email').trigger('change')
|
||||||
|
el.find('[name="executions::notification.email::subject"]').val('some subject')
|
||||||
|
el.find('[data-name="executions::notification.email::body"]').html('lala')
|
||||||
|
|
||||||
|
var params = App.ControllerForm.params(el)
|
||||||
|
var test_params = {
|
||||||
|
condition: {
|
||||||
|
'ticket.title': {
|
||||||
|
operator: 'contains',
|
||||||
|
value: 'some title',
|
||||||
|
},
|
||||||
|
'ticket.created_at': {
|
||||||
|
operator: 'before (absolute)',
|
||||||
|
value: '2015-09-20T03:41:00.000Z',
|
||||||
|
},
|
||||||
|
'ticket.updated_at': {
|
||||||
|
operator: 'within last (relative)',
|
||||||
|
range: 'year',
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
'ticket.organization_id': {
|
||||||
|
operator: 'is not',
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '12',
|
||||||
|
},
|
||||||
|
'ticket.owner_id': {
|
||||||
|
operator: 'is',
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '47',
|
||||||
|
value_completion: 'Bob Smith <bod@example.com>',
|
||||||
|
},
|
||||||
|
'ticket.created_by_id': {
|
||||||
|
operator: 'is',
|
||||||
|
pre_condition: 'current_user.id',
|
||||||
|
value: '',
|
||||||
|
value_completion: ''
|
||||||
|
},
|
||||||
|
},
|
||||||
|
executions: {
|
||||||
|
'ticket.priority_id': {
|
||||||
|
value: '3',
|
||||||
|
},
|
||||||
|
'ticket.owner_id': {
|
||||||
|
pre_condition: 'specific',
|
||||||
|
value: '47',
|
||||||
|
value_completion: 'Bob Smith <bod@example.com>'
|
||||||
|
},
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_owner',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: 'lala',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
|
/* with params or defaults */
|
||||||
|
$('#forms').append('<hr><h1>form 4</h1><form id="form4"></form>')
|
||||||
|
var el = $('#form4')
|
||||||
|
var defaults = {
|
||||||
|
condition: {
|
||||||
|
'ticket.title': {
|
||||||
|
operator: 'contains',
|
||||||
|
value: 'some title',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
executions: {
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_customer',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: "some<br>\nbody",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
new App.ControllerForm({
|
||||||
|
el: el,
|
||||||
|
model: {
|
||||||
|
configure_attributes: [
|
||||||
|
{ name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
|
||||||
|
{ name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
params: defaults,
|
||||||
|
autofocus: true
|
||||||
|
})
|
||||||
|
var params = App.ControllerForm.params(el)
|
||||||
|
var test_params = {
|
||||||
|
condition: {
|
||||||
|
'ticket.title': {
|
||||||
|
operator: 'contains',
|
||||||
|
value: 'some title',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
executions: {
|
||||||
|
|
||||||
|
'notification.email': {
|
||||||
|
recipient: 'ticket_customer',
|
||||||
|
subject: 'some subject',
|
||||||
|
body: "some<br>\nbody",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
deepEqual(params, test_params, 'form param check')
|
||||||
|
|
||||||
});
|
});
|
3
test/fixtures/seeds.rb
vendored
3
test/fixtures/seeds.rb
vendored
|
@ -1,6 +1,9 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
# inital data set as extention to db/seeds.rb
|
# inital data set as extention to db/seeds.rb
|
||||||
|
|
||||||
|
Trigger.destroy_all
|
||||||
|
Job.destroy_all
|
||||||
|
|
||||||
# create email address and apply it to all groups
|
# create email address and apply it to all groups
|
||||||
channel_id = nil
|
channel_id = nil
|
||||||
channel = Channel.find_by(area: 'Email::Notification', active: true)
|
channel = Channel.find_by(area: 'Email::Notification', active: true)
|
||||||
|
|
337
test/unit/ticket_trigger_test.rb
Normal file
337
test/unit/ticket_trigger_test.rb
Normal file
|
@ -0,0 +1,337 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
|
test '1 basic' do
|
||||||
|
trigger1 = Trigger.create_or_update(
|
||||||
|
name: 'auto reply',
|
||||||
|
condition: {
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'new').id.to_s,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}',
|
||||||
|
'recipient' => 'ticket_customer',
|
||||||
|
'subject' => 'Thanks for your inquery (#{ticket.title})!',
|
||||||
|
},
|
||||||
|
'ticket.priority_id' => {
|
||||||
|
'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
|
||||||
|
},
|
||||||
|
'ticket.tags' => {
|
||||||
|
'operator' => 'add',
|
||||||
|
'value' => 'aa, kk',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
trigger2 = Trigger.create_or_update(
|
||||||
|
name: 'not matching',
|
||||||
|
condition: {
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'closed').id.to_s,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'ticket.priority_id' => {
|
||||||
|
'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1 = Ticket.create(
|
||||||
|
title: "some <b>title</b>\n äöüß",
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer_id: 2,
|
||||||
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
assert(ticket1, 'ticket1 created')
|
||||||
|
|
||||||
|
assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal([], Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Thanks for your inquery (some <b>title</b> äöüß)!', article1.subject)
|
||||||
|
assert_match('Braun<br>some <b>title</b>', article1.body)
|
||||||
|
assert_equal('text/html', article1.content_type)
|
||||||
|
|
||||||
|
ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'open')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('open', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'new')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some <b>title</b> äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal(%w(aa kk), Tag.tag_list(object: 'Ticket', o_id: ticket1.id))
|
||||||
|
|
||||||
|
ticket2 = Ticket.create(
|
||||||
|
title: "some title\n äöüß",
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer_id: 2,
|
||||||
|
state: Ticket::State.lookup(name: 'open'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
assert(ticket2, 'ticket2 created')
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
|
||||||
|
assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
|
||||||
|
assert_equal('open', ticket2.state.name, 'ticket2.state verify')
|
||||||
|
assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
|
||||||
|
assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
|
||||||
|
assert_equal([], Tag.tag_list(object: 'Ticket', o_id: ticket2.id))
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket2 = Ticket.lookup(id: ticket2.id)
|
||||||
|
assert_equal('some title äöüß', ticket2.title, 'ticket2.title verify')
|
||||||
|
assert_equal('Users', ticket2.group.name, 'ticket2.group verify')
|
||||||
|
assert_equal('open', ticket2.state.name, 'ticket2.state verify')
|
||||||
|
assert_equal('2 normal', ticket2.priority.name, 'ticket2.priority verify')
|
||||||
|
assert_equal(0, ticket2.articles.count, 'ticket2.articles verify')
|
||||||
|
assert_equal([], Tag.tag_list(object: 'Ticket', o_id: ticket2.id))
|
||||||
|
|
||||||
|
Trigger.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
test '2 actions - create' do
|
||||||
|
trigger1 = Trigger.create_or_update(
|
||||||
|
name: 'auto reply',
|
||||||
|
condition: {
|
||||||
|
'ticket.action' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => 'create',
|
||||||
|
},
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'new').id.to_s,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => 'dasdasdasd',
|
||||||
|
'recipient' => 'ticket_customer',
|
||||||
|
'subject' => 'asdasdas',
|
||||||
|
},
|
||||||
|
'ticket.priority_id' => {
|
||||||
|
'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1 = Ticket.create(
|
||||||
|
title: "some title\n äöüß",
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer_id: 2,
|
||||||
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
assert(ticket1, 'ticket1 created')
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'open')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('open', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'new')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
Trigger.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
test '2 actions - update' do
|
||||||
|
trigger1 = Trigger.create_or_update(
|
||||||
|
name: 'auto reply',
|
||||||
|
condition: {
|
||||||
|
'ticket.action' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => 'update',
|
||||||
|
},
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'new').id.to_s,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => 'dasdasdasd',
|
||||||
|
'recipient' => 'ticket_customer',
|
||||||
|
'subject' => 'asdasdas',
|
||||||
|
},
|
||||||
|
'ticket.priority_id' => {
|
||||||
|
'value' => Ticket::Priority.lookup(name: '3 high').id.to_s,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1 = Ticket.create(
|
||||||
|
title: "some title\n äöüß",
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer_id: 2,
|
||||||
|
state: Ticket::State.lookup(name: 'new'),
|
||||||
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
assert(ticket1, 'ticket1 created')
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.priority = Ticket::Priority.lookup(name: '2 normal')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'open')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('open', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(0, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
ticket1.state = Ticket::State.lookup(name: 'new')
|
||||||
|
ticket1.save
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1 = Ticket.lookup(id: ticket1.id)
|
||||||
|
assert_equal('some title äöüß', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('3 high', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
|
||||||
|
Trigger.destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue