2020-03-19 09:39:51 +00:00
|
|
|
class OrganizationPolicy < ApplicationPolicy
|
|
|
|
|
|
|
|
def show?
|
|
|
|
return true if user.permissions?(['admin', 'ticket.agent'])
|
2020-08-20 07:10:08 +00:00
|
|
|
return true if record.id == user.organization_id
|
2020-03-19 09:39:51 +00:00
|
|
|
|
2020-08-20 07:10:08 +00:00
|
|
|
false
|
2020-03-19 09:39:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update?
|
2020-08-20 07:10:08 +00:00
|
|
|
return true if user.permissions?(['admin', 'ticket.agent'])
|
2020-03-19 09:39:51 +00:00
|
|
|
|
2020-08-20 07:10:08 +00:00
|
|
|
false
|
2020-03-19 09:39:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Scope < ApplicationPolicy::Scope
|
|
|
|
|
|
|
|
def resolve
|
|
|
|
if user.permissions?(['ticket.agent', 'admin.organization'])
|
|
|
|
scope.all
|
|
|
|
elsif user.organization_id
|
|
|
|
scope.where(id: user.organization_id)
|
|
|
|
else
|
|
|
|
scope.none
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|