assets.rb 956 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Group
  3. module Assets
  4. extend ActiveSupport::Concern
  5. def filter_unauthorized_attributes(attributes)
  6. return super if UserInfo.assets.blank? || UserInfo.assets.agent?
  7. attributes = super
  8. attributes.slice('id', 'name', 'name_last', 'follow_up_possible', 'reopen_time_in_days', 'active', 'parent_id')
  9. end
  10. def authorized_asset?
  11. return true if UserInfo.assets.blank? || UserInfo.assets.agent? || Setting.get('customer_ticket_create_group_ids').blank?
  12. allowed_group_ids = Auth::RequestCache.fetch_value("Group/Assets/authorized_asset/groups/#{UserInfo.current_user_id}") do
  13. Array.wrap(Setting.get('customer_ticket_create_group_ids')).map(&:to_i) | TicketPolicy::ReadScope.new(User.find(UserInfo.current_user_id)).resolve.distinct(:group_id).pluck(:group_id)
  14. end
  15. allowed_group_ids.include?(id)
  16. end
  17. end
  18. end