aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-06-14 18:54:00 +0200
committerTeddy Wing2017-06-14 18:54:00 +0200
commit2e124ae18c975341a3afd49e29eb245ac40c1220 (patch)
tree746b672320ccc42bc7129b8d915892a9e8bda7a8 /app
parent467f787eb36b68f809409ec3a01797af30fe5128 (diff)
downloadchouette-core-2e124ae18c975341a3afd49e29eb245ac40c1220.tar.bz2
CustomLinks#actions_after_policy_check: Better document conditions
Add comments that describe what each `or` condition is doing. At first I thought maybe I should create separate methods to name these conditions, but settled for comments instead. Moved the final check to a method because that one seemed the most obscure about what it does. Refs #3479
Diffstat (limited to 'app')
-rw-r--r--app/helpers/table_builder_helper/custom_links.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb
index f47ef1a11..a4a8bba4f 100644
--- a/app/helpers/table_builder_helper/custom_links.rb
+++ b/app/helpers/table_builder_helper/custom_links.rb
@@ -40,20 +40,38 @@ module TableBuilderHelper
def actions_after_policy_check
@actions.select do |action|
+ # Has policy and can destroy
(action == :delete &&
Pundit.policy(@user_context, @obj).present? &&
Pundit.policy(@user_context, @obj).destroy?) ||
+
+ # Doesn't have policy
(action == :delete &&
!Pundit.policy(@user_context, @obj).present?) ||
+
+ # Has policy and can update
(action == :edit &&
Pundit.policy(@user_context, @obj).present? &&
Pundit.policy(@user_context, @obj).update?) ||
+
+ # Doesn't have policy
(action == :edit &&
!Pundit.policy(@user_context, @obj).present?) ||
+
+ # Object isn't archived
(action == :archive && !@obj.archived?) ||
+
+ # Object is archived
(action == :unarchive && @obj.archived?) ||
- (![:delete, :edit, :archive, :unarchive].include?(action))
+
+ action_is_allowed_regardless_of_policy(action)
end
end
+
+ private
+
+ def action_is_allowed_regardless_of_policy(action)
+ ![:delete, :edit, :archive, :unarchive].include?(action)
+ end
end
end