checks_user_attributes_by_current_user_permission.rb 965 B

1234567891011121314151617181920212223242526272829303132333435
  1. module ChecksUserAttributesByCurrentUserPermission
  2. extend ActiveSupport::Concern
  3. private
  4. def check_attributes_by_current_user_permission(params)
  5. authorize!
  6. # admins can do whatever they want
  7. return true if current_user.permissions?('admin.user')
  8. # regular agents are not allowed to set Groups and Roles
  9. %w[Role Group].each do |model|
  10. %w[_ids s].each do |suffix|
  11. attribute = "#{model.downcase}#{suffix}"
  12. values = params[attribute]
  13. next if values.nil?
  14. logger.warn "#{model} assignment is only allowed by admin! User with ID #{current_user.id} tried to assign #{values.inspect}"
  15. params.delete(attribute)
  16. end
  17. end
  18. # check for create requests and set
  19. # signup roles if no other roles are given
  20. return true if params[:id].present?
  21. return true if params[:role_ids]
  22. return true if params[:roles]
  23. params[:role_ids] = Role.signup_role_ids
  24. true
  25. end
  26. end