From c679c47a3db17561a2949750cc8529ba5f927ec5 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Mon, 6 Nov 2023 18:06:24 -0500 Subject: [PATCH] Fixes #36892 - Pass host results to REX slot; allow root node permissions to be extended --- app/controllers/api/v2/base_controller.rb | 9 ++++++++- app/views/api/v2/layouts/index_layout.json.erb | 3 +-- .../javascripts/react_app/components/HostsIndex/index.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v2/base_controller.rb b/app/controllers/api/v2/base_controller.rb index de48ea0ac91d..7060a15a1df7 100644 --- a/app/controllers/api/v2/base_controller.rb +++ b/app/controllers/api/v2/base_controller.rb @@ -47,7 +47,7 @@ class BaseController < Api::BaseController layout 'api/v2/layouts/index_layout', :only => :index helper_method :root_node_name, :metadata_total, :metadata_subtotal, :metadata_search, - :metadata_order, :metadata_by, :metadata_page, :metadata_per_page + :metadata_order, :metadata_by, :metadata_page, :metadata_per_page, :index_node_permissions def root_node_name @root_node_name ||= if Rabl.configuration.use_controller_name_as_json_root controller_name.split('/').last @@ -58,6 +58,13 @@ def root_node_name end end + def index_node_permissions + { + :can_create => can_create?, + :can_edit => authorized_for(:controller => controller_name, :action => 'edit') + } + end + def metadata_total @total ||= resource_scope.try(:size).to_i end diff --git a/app/views/api/v2/layouts/index_layout.json.erb b/app/views/api/v2/layouts/index_layout.json.erb index 3c056c97e1ce..8a2ab25cb023 100644 --- a/app/views/api/v2/layouts/index_layout.json.erb +++ b/app/views/api/v2/layouts/index_layout.json.erb @@ -5,8 +5,7 @@ "per_page": <%= metadata_per_page.to_json %>, "search": <%= metadata_search.to_json.html_safe %>, <% if params.has_key?(:include_permissions) %> - "can_create": <%= can_create?.to_json %>, - "can_edit": <%= can_edit?.to_json %>, + <%= index_node_permissions.to_json.gsub(/[{}]/,'').html_safe %>, <% end %> "sort": { "by": <%= metadata_by.to_json.html_safe %>, diff --git a/webpack/assets/javascripts/react_app/components/HostsIndex/index.js b/webpack/assets/javascripts/react_app/components/HostsIndex/index.js index 5df6b4056a8c..5ca064561d50 100644 --- a/webpack/assets/javascripts/react_app/components/HostsIndex/index.js +++ b/webpack/assets/javascripts/react_app/components/HostsIndex/index.js @@ -213,7 +213,8 @@ const HostsIndex = () => {