Allow also to search in inactive groups.
This commit is contained in:
parent
10e0592140
commit
a6cdde345c
2 changed files with 9 additions and 14 deletions
|
@ -116,20 +116,15 @@ class TicketsController < ApplicationController
|
||||||
assets = ticket.assets({})
|
assets = ticket.assets({})
|
||||||
|
|
||||||
# open tickets by customer
|
# open tickets by customer
|
||||||
group_ids = Group.select('groups.id')
|
access_condition = Ticket.access_condition(current_user)
|
||||||
.joins(:users)
|
|
||||||
.where('groups_users.user_id = ?', current_user.id)
|
|
||||||
.map(&:id)
|
|
||||||
|
|
||||||
access_condition = [ 'group_id IN (?)', group_ids ]
|
|
||||||
|
|
||||||
ticket_lists = Ticket
|
ticket_lists = Ticket
|
||||||
.where(
|
.where(
|
||||||
customer_id: ticket.customer_id,
|
customer_id: ticket.customer_id,
|
||||||
state_id: Ticket::State.by_category( 'open' )
|
state_id: Ticket::State.by_category('open')
|
||||||
)
|
)
|
||||||
.where(access_condition)
|
.where(access_condition)
|
||||||
.where( 'id != ?', [ ticket.id ] )
|
.where('id != ?', [ ticket.id ])
|
||||||
.order('created_at DESC')
|
.order('created_at DESC')
|
||||||
.limit(6)
|
.limit(6)
|
||||||
|
|
||||||
|
@ -174,7 +169,7 @@ class TicketsController < ApplicationController
|
||||||
return if !ticket_permission(ticket_master)
|
return if !ticket_permission(ticket_master)
|
||||||
|
|
||||||
# check slave ticket
|
# check slave ticket
|
||||||
ticket_slave = Ticket.find_by(id: params[:slave_ticket_id] )
|
ticket_slave = Ticket.find_by(id: params[:slave_ticket_id])
|
||||||
if !ticket_slave
|
if !ticket_slave
|
||||||
render json: {
|
render json: {
|
||||||
result: 'faild',
|
result: 'faild',
|
||||||
|
|
|
@ -108,16 +108,16 @@ returns
|
||||||
def self.access_condition(user)
|
def self.access_condition(user)
|
||||||
access_condition = []
|
access_condition = []
|
||||||
if user.role?(Z_ROLENAME_AGENT)
|
if user.role?(Z_ROLENAME_AGENT)
|
||||||
group_ids = Group.select( 'groups.id' ).joins(:users)
|
group_ids = Group.select('groups.id').joins(:users)
|
||||||
.where( 'groups_users.user_id = ?', user.id )
|
.where('groups_users.user_id = ?', user.id)
|
||||||
.where( 'groups.active = ?', true )
|
.where('groups.active = ?', true)
|
||||||
.map( &:id )
|
.map(&:id)
|
||||||
access_condition = [ 'group_id IN (?)', group_ids ]
|
access_condition = [ 'group_id IN (?)', group_ids ]
|
||||||
else
|
else
|
||||||
access_condition = if !user.organization || ( !user.organization.shared || user.organization.shared == false )
|
access_condition = if !user.organization || ( !user.organization.shared || user.organization.shared == false )
|
||||||
[ 'tickets.customer_id = ?', user.id ]
|
[ 'tickets.customer_id = ?', user.id ]
|
||||||
else
|
else
|
||||||
[ '( tickets.customer_id = ? OR tickets.organization_id = ? )', user.id, user.organization.id ]
|
[ '(tickets.customer_id = ? OR tickets.organization_id = ?)', user.id, user.organization.id ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
access_condition
|
access_condition
|
||||||
|
|
Loading…
Reference in a new issue