assets.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Role
  3. module Assets
  4. extend ActiveSupport::Concern
  5. =begin
  6. get all assets / related models for this roles
  7. role = Role.find(123)
  8. result = role.assets(assets_if_exists)
  9. returns
  10. result = {
  11. :Role => {
  12. 123 => role_model_123,
  13. 1234 => role_model_1234,
  14. }
  15. }
  16. =end
  17. def assets(data)
  18. app_model = self.class.to_app_model
  19. if !data[ app_model ]
  20. data[ app_model ] = {}
  21. end
  22. return data if data[ app_model ][ id ]
  23. local_attributes = attributes_with_association_ids
  24. # set temp. current attributes to assets pool to prevent
  25. # loops, will be updated with lookup attributes later
  26. data[ app_model ][ id ] = local_attributes
  27. local_attributes['group_ids'].each_key do |group_id|
  28. next if data[:Group] && data[:Group][group_id]
  29. group = Group.lookup(id: group_id)
  30. next if !group
  31. data = group.assets(data)
  32. end
  33. data
  34. end
  35. def filter_unauthorized_attributes(attributes)
  36. return super if UserInfo.assets.blank? || UserInfo.assets.agent?
  37. attributes = super
  38. attributes['name'] = "Role_#{id}"
  39. attributes.slice('id', 'name', 'group_ids', 'permission_ids', 'active')
  40. end
  41. end
  42. end