Class: ModelFilePolicy::Scope
- Inherits:
-
ApplicationPolicy::Scope
- Object
- ApplicationPolicy::Scope
- ModelFilePolicy::Scope
- Defined in:
- app/policies/model_file_policy.rb
Constant Summary collapse
- FULL_VIEW_PERMISSIONS =
["view", "edit", "own"]
Instance Method Summary collapse
Methods inherited from ApplicationPolicy::Scope
Constructor Details
This class inherits a constructor from ApplicationPolicy::Scope
Instance Method Details
#resolve ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/policies/model_file_policy.rb', line 47 def resolve return scope if @user&.is_moderator? subject_list = [nil, user, user&.roles].flatten scope # Where the user only has preview permissions, then show previewable files .where(previewable: true) .where(model: Model.granted_to("preview", subject_list)) .where.not(model: Model.granted_to(FULL_VIEW_PERMISSIONS, subject_list)) # Otherwise, show files where the user has full view permissions on the model .or( scope.where(model: Model.granted_to(FULL_VIEW_PERMISSIONS, subject_list)) ) end |