Added overview user relation to set overviews for multiple users. Moved to new column_select widget.
This commit is contained in:
parent
de56206045
commit
d8bb951032
8 changed files with 352 additions and 10 deletions
|
@ -144,7 +144,7 @@ class App.UiElement.ticket_perform_action
|
|||
elementFull.find('.js-remove').addClass('is-disabled')
|
||||
|
||||
@rebuildAttributeSelectors: (elementFull, elementRow, groupAndAttribute, elements, meta, attribute) ->
|
||||
console.log('aa', groupAndAttribute, meta)
|
||||
|
||||
# set attribute
|
||||
if groupAndAttribute
|
||||
elementRow.find('.js-attributeSelector select').val(groupAndAttribute)
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
class App.Overview extends App.Model
|
||||
@configure 'Overview', 'name', 'prio', 'condition', 'order', 'group_by', 'view', 'user_id', 'organization_shared', 'role_id', 'order', 'group_by', 'active', 'updated_at'
|
||||
@configure 'Overview', 'name', 'prio', 'condition', 'order', 'group_by', 'view', 'user_ids', 'organization_shared', 'role_id', 'order', 'group_by', 'active', 'updated_at'
|
||||
@extend Spine.Model.Ajax
|
||||
@url: @apiPath + '/overviews'
|
||||
@configure_attributes = [
|
||||
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, 'null': false },
|
||||
{ name: 'link', display: 'Link', readonly: 1 },
|
||||
{ name: 'role_id', display: 'Available for Role', tag: 'select', multiple: false, nulloption: true, null: false, relation: 'Role', translate: true },
|
||||
{ name: 'user_id', display: 'Available for User', tag: 'select', multiple: true, nulloption: true, null: true, relation: 'User', sortBy: 'firstname' },
|
||||
{ name: 'user_ids', display: 'Available for User', tag: 'column_select', multiple: true, nulloption: false, null: true, relation: 'User', sortBy: 'firstname' },
|
||||
{ name: 'organization_shared', display: 'Only available for Users with shared Organization', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true },
|
||||
# { name: 'content', display: 'Content', tag: 'textarea', limit: 250, 'null': false },
|
||||
{ name: 'condition', display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false },
|
||||
{ name: 'prio', display: 'Prio', readonly: 1 },
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ Example:
|
|||
"order":{"o_a":1,"o_b":2},
|
||||
"group_by":"group",
|
||||
"view":{"v_a":1,"v_b":2},
|
||||
"user_id": null,
|
||||
"user_ids": null,
|
||||
"role_id": null,
|
||||
"updated_at":"2012-09-14T17:51:53Z",
|
||||
"created_at":"2012-09-14T17:51:53Z",
|
||||
|
@ -91,7 +91,7 @@ Payload:
|
|||
"order":{"o_a":1,"o_b":2},
|
||||
"group_by":"group",
|
||||
"view":{"v_a":1,"v_b":2},
|
||||
"user_id": null,
|
||||
"user_ids": null,
|
||||
"role_id": null,
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ Payload:
|
|||
"order":{"o_a":1,"o_b":2},
|
||||
"group_by":"group",
|
||||
"view":{"v_a":1,"v_b":2},
|
||||
"user_id": null,
|
||||
"user_ids": null,
|
||||
"role_id": null,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class Overview < ApplicationModel
|
||||
has_and_belongs_to_many :users, after_add: :cache_update, after_remove: :cache_update
|
||||
store :condition
|
||||
store :order
|
||||
store :view
|
||||
|
|
|
@ -25,13 +25,26 @@ returns
|
|||
else
|
||||
Overview.where(role_id: role.id, organization_shared: false, active: true).order(:prio)
|
||||
end
|
||||
return overviews
|
||||
overviews_list = []
|
||||
overviews.each {|overview|
|
||||
user_ids = overview.user_ids
|
||||
next if !user_ids.empty? && !user_ids.include?(data[:current_user].id)
|
||||
overviews_list.push overview
|
||||
}
|
||||
return overviews_list
|
||||
end
|
||||
|
||||
# get agent overviews
|
||||
return if !data[:current_user].role?('Agent')
|
||||
role = Role.find_by(name: 'Agent')
|
||||
Overview.where(role_id: role.id, active: true).order(:prio)
|
||||
overviews = Overview.where(role_id: role.id, active: true).order(:prio)
|
||||
overviews_list = []
|
||||
overviews.each {|overview|
|
||||
user_ids = overview.user_ids
|
||||
next if !user_ids.empty? && !user_ids.include?(data[:current_user].id)
|
||||
overviews_list.push overview
|
||||
}
|
||||
overviews_list
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
13
db/migrate/20160314000001_overview_user_relation.rb
Normal file
13
db/migrate/20160314000001_overview_user_relation.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
class OverviewUserRelation < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :overviews_users, id: false do |t|
|
||||
t.integer :overview_id
|
||||
t.integer :user_id
|
||||
end
|
||||
add_index :overviews_users, [:overview_id]
|
||||
add_index :overviews_users, [:user_id]
|
||||
remove_column :overviews, :user_id
|
||||
end
|
||||
|
||||
end
|
|
@ -467,7 +467,6 @@ test('form checks', function() {
|
|||
},
|
||||
}
|
||||
deepEqual(params, test_params, 'form param check')
|
||||
console.log('APO3', App.Organization.find(12))
|
||||
|
||||
//deepEqual(el.find('[name="times::days"]').val(), ['mon', 'wed'], 'check times::days value')
|
||||
//equal(el.find('[name="times::hours"]').val(), 2, 'check times::hours value')
|
||||
|
|
317
test/unit/ticket_overview_test.rb
Normal file
317
test/unit/ticket_overview_test.rb
Normal file
|
@ -0,0 +1,317 @@
|
|||
# encoding: utf-8
|
||||
require 'test_helper'
|
||||
|
||||
class TicketOverviewTest < ActiveSupport::TestCase
|
||||
|
||||
# create base
|
||||
group = Group.create_or_update(
|
||||
name: 'OverviewTest',
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
roles = Role.where(name: 'Agent')
|
||||
agent1 = User.create_or_update(
|
||||
login: 'ticket-overview-agent1@example.com',
|
||||
firstname: 'Overview',
|
||||
lastname: 'Agent1',
|
||||
email: 'ticket-overview-agent1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: [group],
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
agent2 = User.create_or_update(
|
||||
login: 'ticket-overview-agent2@example.com',
|
||||
firstname: 'Overview',
|
||||
lastname: 'Agent2',
|
||||
email: 'ticket-overview-agent2@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
#groups: groups,
|
||||
updated_at: '2015-02-05 16:38:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
roles = Role.where(name: 'Customer')
|
||||
organization1 = Organization.create_or_update(
|
||||
name: 'Overview Org',
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
customer1 = User.create_or_update(
|
||||
login: 'ticket-overview-customer1@example.com',
|
||||
firstname: 'Overview',
|
||||
lastname: 'Customer1',
|
||||
email: 'ticket-overview-customer1@example.com',
|
||||
password: 'customerpw',
|
||||
active: true,
|
||||
organization_id: organization1.id,
|
||||
roles: roles,
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
customer2 = User.create_or_update(
|
||||
login: 'ticket-overview-customer2@example.com',
|
||||
firstname: 'Overview',
|
||||
lastname: 'Customer2',
|
||||
email: 'ticket-overview-customer2@example.com',
|
||||
password: 'customerpw',
|
||||
active: true,
|
||||
organization_id: organization1.id,
|
||||
roles: roles,
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
customer3 = User.create_or_update(
|
||||
login: 'ticket-overview-customer3@example.com',
|
||||
firstname: 'Overview',
|
||||
lastname: 'Customer3',
|
||||
email: 'ticket-overview-customer3@example.com',
|
||||
password: 'customerpw',
|
||||
active: true,
|
||||
organization_id: nil,
|
||||
roles: roles,
|
||||
updated_at: '2015-02-05 16:37:00',
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
Overview.destroy_all
|
||||
UserInfo.current_user_id = 1
|
||||
overview_role = Role.find_by(name: 'Agent')
|
||||
Overview.create_or_update(
|
||||
name: 'My assigned Tickets',
|
||||
link: 'my_assigned',
|
||||
prio: 1000,
|
||||
role_id: overview_role.id,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3, 7 ],
|
||||
},
|
||||
'ticket.owner_id' => {
|
||||
operator: 'is',
|
||||
pre_condition: 'current_user.id',
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'ASC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer group created_at),
|
||||
s: %w(title customer group created_at),
|
||||
m: %w(number title customer group created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
|
||||
Overview.create_or_update(
|
||||
name: 'Unassigned & Open',
|
||||
link: 'all_unassigned',
|
||||
prio: 1010,
|
||||
role_id: overview_role.id,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [1, 2, 3],
|
||||
},
|
||||
'ticket.owner_id' => {
|
||||
operator: 'is',
|
||||
value: 1,
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'ASC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer group created_at),
|
||||
s: %w(title customer group created_at),
|
||||
m: %w(number title customer group created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
Overview.create_or_update(
|
||||
name: 'My Tickets 2',
|
||||
link: 'my_tickets_2',
|
||||
prio: 1020,
|
||||
role_id: overview_role.id,
|
||||
user_ids: [agent2.id],
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3, 7 ],
|
||||
},
|
||||
'ticket.owner_id' => {
|
||||
operator: 'is',
|
||||
pre_condition: 'current_user.id',
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'ASC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer group created_at),
|
||||
s: %w(title customer group created_at),
|
||||
m: %w(number title customer group created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
|
||||
overview_role = Role.find_by(name: 'Customer')
|
||||
Overview.create_or_update(
|
||||
name: 'My Tickets',
|
||||
link: 'my_tickets',
|
||||
prio: 1100,
|
||||
role_id: overview_role.id,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3, 4, 6, 7 ],
|
||||
},
|
||||
'ticket.customer_id' => {
|
||||
operator: 'is',
|
||||
pre_condition: 'current_user.id',
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'DESC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer state created_at),
|
||||
s: %w(number title state created_at),
|
||||
m: %w(number title state created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
Overview.create_or_update(
|
||||
name: 'My Organization Tickets',
|
||||
link: 'my_organization_tickets',
|
||||
prio: 1200,
|
||||
role_id: overview_role.id,
|
||||
organization_shared: true,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3, 4, 6, 7 ],
|
||||
},
|
||||
'ticket.organization_id' => {
|
||||
operator: 'is',
|
||||
pre_condition: 'current_user.organization_id',
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'DESC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer state created_at),
|
||||
s: %w(number title customer state created_at),
|
||||
m: %w(number title customer state created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
Overview.create_or_update(
|
||||
name: 'My Organization Tickets (open)',
|
||||
link: 'my_organization_tickets_open',
|
||||
prio: 1200,
|
||||
role_id: overview_role.id,
|
||||
user_ids: [customer2.id],
|
||||
organization_shared: true,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3 ],
|
||||
},
|
||||
'ticket.organization_id' => {
|
||||
operator: 'is',
|
||||
pre_condition: 'current_user.organization_id',
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'DESC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer state created_at),
|
||||
s: %w(number title customer state created_at),
|
||||
m: %w(number title customer state created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
|
||||
overview_role = Role.find_by(name: 'Admin')
|
||||
Overview.create_or_update(
|
||||
name: 'Not Shown Admin',
|
||||
link: 'not_shown_admin',
|
||||
prio: 9900,
|
||||
role_id: overview_role.id,
|
||||
condition: {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [ 1, 2, 3 ],
|
||||
},
|
||||
},
|
||||
order: {
|
||||
by: 'created_at',
|
||||
direction: 'DESC',
|
||||
},
|
||||
view: {
|
||||
d: %w(title customer state created_at),
|
||||
s: %w(number title customer state created_at),
|
||||
m: %w(number title customer state created_at),
|
||||
view_mode_default: 's',
|
||||
},
|
||||
)
|
||||
|
||||
test 'ticket create' do
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
current_user: agent1,
|
||||
)
|
||||
assert_equal(2, result.count)
|
||||
assert_equal('My assigned Tickets', result[0].name)
|
||||
assert_equal('Unassigned & Open', result[1].name)
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
current_user: agent2,
|
||||
)
|
||||
assert_equal(3, result.count)
|
||||
assert_equal('My assigned Tickets', result[0].name)
|
||||
assert_equal('Unassigned & Open', result[1].name)
|
||||
assert_equal('My Tickets 2', result[2].name)
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
current_user: customer1,
|
||||
)
|
||||
assert_equal(2, result.count)
|
||||
assert_equal('My Tickets', result[0].name)
|
||||
assert_equal('My Organization Tickets', result[1].name)
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
current_user: customer2,
|
||||
)
|
||||
assert_equal(3, result.count)
|
||||
assert_equal('My Tickets', result[0].name)
|
||||
assert_equal('My Organization Tickets', result[1].name)
|
||||
assert_equal('My Organization Tickets (open)', result[2].name)
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
current_user: customer3,
|
||||
)
|
||||
assert_equal(1, result.count)
|
||||
assert_equal('My Tickets', result[0].name)
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue