aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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