From 96528a34b44b185a4e1ce3633a1e73043cb8c7c2 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 12 Jul 2024 11:29:59 +0200 Subject: [PATCH] Policy: Use no_one rather than false --- app/policies/application_policy.rb | 8 ++++++-- app/policies/task_policy.rb | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index 6087f3d24..563895bbe 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -12,8 +12,8 @@ def initialize(user, record) def method_missing(method_name, *_args) if RESOURCE_ACTIONS.include?(method_name) - Rails.logger.debug { "Pundit policy does not have method #{method_name}. Returning false as default." } - return false + Rails.logger.debug { "Pundit policy does not have method #{method_name}. Returning no_one as default." } + return no_one end super @@ -46,6 +46,10 @@ def everyone @user.present? end + def no_one + false + end + class Scope def initialize(user, scope) @user = user diff --git a/app/policies/task_policy.rb b/app/policies/task_policy.rb index b86acaa3e..e481d74b8 100644 --- a/app/policies/task_policy.rb +++ b/app/policies/task_policy.rb @@ -29,14 +29,14 @@ def create? %i[add_to_collection? duplicate? export_external_start? export_external_check? export_external_confirm?].each do |action| define_method(action) do - return false if @user.blank? + return no_one if @user.blank? record_owner? || task.access_level_public? || task_in_group_with?(@user) || admin? end end def update? - return false if @user.blank? + return no_one if @user.blank? record_owner? || task_in_group_with?(@user) || admin? end