scope.rb 920 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class Ticket::OverviewsPolicy < ApplicationPolicy
  3. class Scope < ApplicationPolicy::Scope
  4. def resolve(ignore_user_conditions: false)
  5. return scope.none if !user.permissions?(%w[ticket.customer ticket.agent])
  6. scope = base_query
  7. if !ignore_user_conditions
  8. scope = scope.where(organization_shared: false) if !user.shared_organizations?
  9. scope = scope.where.not(out_of_office: true) if !user.someones_out_of_office_replacement?
  10. end
  11. scope
  12. end
  13. private
  14. def base_query
  15. scope.distinct
  16. .joins(roles: :users)
  17. .where(active: true)
  18. .where(roles: { active: true })
  19. .where(users: { id: user.id, active: true })
  20. .left_joins(:users)
  21. .where(overviews_users: { user_id: [nil, user.id] })
  22. end
  23. end
  24. end