online_notification_policy.rb 794 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class OnlineNotificationPolicy < ApplicationPolicy
  3. def show?
  4. return false if !owner?
  5. return true if related_accessible?
  6. without_relation_permission_field_scope
  7. end
  8. def destroy?
  9. owner?
  10. end
  11. def update?
  12. owner?
  13. end
  14. private
  15. def owner?
  16. user == record.user
  17. end
  18. def related_accessible?
  19. return false if !record.related_object
  20. Pundit
  21. .policy(user, record.related_object)
  22. .show?
  23. end
  24. def relation
  25. object_klass.find_by(id: record.o_id)
  26. end
  27. def without_relation_permission_field_scope
  28. @without_relation_permission_field_scope ||=
  29. ApplicationPolicy::FieldScope.new(allow: %i[seen type_name object_name created_at updated_at])
  30. end
  31. end