scope.rb 879 B

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