search.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Organization
  3. module Search
  4. extend ActiveSupport::Concern
  5. include CanSearch
  6. # methods defined here are going to extend the class, not the instance of it
  7. class_methods do
  8. =begin
  9. search organizations preferences
  10. result = Organization.search_preferences(user_model)
  11. returns if user has permissions to search
  12. result = {
  13. prio: 1000,
  14. direct_search_index: true
  15. }
  16. returns if user has no permissions to search
  17. result = false
  18. =end
  19. def search_preferences(current_user)
  20. return false if !current_user.permissions?(['ticket.agent', 'ticket.customer', 'admin.organization'])
  21. {
  22. prio: 1500,
  23. direct_search_index: !customer_only?(current_user),
  24. }
  25. end
  26. def customer_only?(current_user)
  27. return true if current_user.permissions?('ticket.customer') && !current_user.permissions?(['admin.organization', 'ticket.agent'])
  28. false
  29. end
  30. def search_default_sort_by
  31. %w[active updated_at]
  32. end
  33. def search_default_order_by
  34. %w[desc desc]
  35. end
  36. def search_params_pre(params)
  37. return if !customer_only?(params[:current_user])
  38. params[:ids] = params[:current_user].all_organization_ids
  39. end
  40. end
  41. end
  42. end