From f03ff5b4f7e0c5aa3c84545775411f7fd4f4f30e Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 21 Apr 2024 17:07:51 +0100 Subject: [PATCH 1/2] Fix path for bulk file edit form resolves #2060 --- app/views/model_files/bulk_edit.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/model_files/bulk_edit.html.erb b/app/views/model_files/bulk_edit.html.erb index 0853e9833..1dd0156c4 100644 --- a/app/views/model_files/bulk_edit.html.erb +++ b/app/views/model_files/bulk_edit.html.erb @@ -1,7 +1,7 @@ <%= render partial: "breadcrumb" %>

Bulk Edit <%= ModelFile.model_name.human.pluralize %>

-<%= form_with url: library_model_model_files_path(@library, @model), method: :patch do |form| %> +<%= form_with url: bulk_update_library_model_model_files_path(@library, @model), method: :patch do |form| %>

Select files to change:

From cacdc500bc96a79d6d36a66ea36ef82615d69b43 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 21 Apr 2024 17:13:30 +0100 Subject: [PATCH 2/2] Refactor models#bulk_update so we call policy scope resolves #2061 --- app/controllers/models_controller.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/controllers/models_controller.rb b/app/controllers/models_controller.rb index cb968cb1a..a114faa1c 100644 --- a/app/controllers/models_controller.rb +++ b/app/controllers/models_controller.rb @@ -98,15 +98,12 @@ def bulk_update add_tags = Set.new(hash.delete(:add_tags)) remove_tags = Set.new(hash.delete(:remove_tags)) - - params[:models].each_pair do |id, selected| - if selected == "1" - model = policy_scope(Model).find(id) - if model&.update(hash) - existing_tags = Set.new(model.tag_list) - model.tag_list = existing_tags + add_tags - remove_tags - model.save - end + ids = params[:models].select { |k, v| v == "1" }.keys + policy_scope(Model).find(ids).each do |model| + if model&.update(hash) + existing_tags = Set.new(model.tag_list) + model.tag_list = existing_tags + add_tags - remove_tags + model.save end end redirect_back_or_to edit_models_path(@filters), notice: t(".success")