diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index 14e133574..33e006081 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -5,12 +5,12 @@ class BulkUpdateRequestsController < ApplicationController before_filter :load_bulk_update_request, :except => [:new, :create, :index] def new - @bulk_update_request = BulkUpdateRequest.new(:user_id => CurrentUser.user.id) + @bulk_update_request = BulkUpdateRequest.new respond_with(@bulk_update_request) end def create - @bulk_update_request = BulkUpdateRequest.create(params[:bulk_update_request]) + @bulk_update_request = BulkUpdateRequest.create(bur_params(:create)) respond_with(@bulk_update_request, :location => bulk_update_requests_path) end @@ -23,7 +23,7 @@ class BulkUpdateRequestsController < ApplicationController def update if @bulk_update_request.editable?(CurrentUser.user) - @bulk_update_request.update_attributes(params[:bulk_update_request]) + @bulk_update_request.update(bur_params(:update)) flash[:notice] = "Bulk update request updated" respond_with(@bulk_update_request, :location => bulk_update_requests_path) else @@ -56,4 +56,11 @@ class BulkUpdateRequestsController < ApplicationController def load_bulk_update_request @bulk_update_request = BulkUpdateRequest.find(params[:id]) end + + def bur_params(context) + permitted_params = %i[script skip_secondary_validations] + permitted_params += %i[title reason forum_topic_id] if context == :create + + params.require(:bulk_update_request).permit(permitted_params) + end end diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index ff452633b..6ba3f6db6 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -13,8 +13,6 @@ class BulkUpdateRequest < ApplicationRecord validate :script_formatted_correctly validate :forum_topic_id_not_invalid validate :validate_script, :on => :create - attr_accessible :user_id, :forum_topic_id, :forum_post_id, :script, :title, :reason, :skip_secondary_validations - attr_accessible :status, :approver_id, :as => [:admin] before_validation :initialize_attributes, :on => :create before_validation :normalize_text after_create :create_forum_topic @@ -94,7 +92,7 @@ class BulkUpdateRequest < ApplicationRecord def approve!(approver) CurrentUser.scoped(approver) do AliasAndImplicationImporter.new(script, forum_topic_id, "1", true).process! - update({ :status => "approved", :approver_id => CurrentUser.id, :skip_secondary_validations => true }, :as => CurrentUser.role) + update(status: "approved", approver: CurrentUser.user, skip_secondary_validations: true) forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.", "APPROVED") end diff --git a/app/views/bulk_update_requests/_form.html.erb b/app/views/bulk_update_requests/_form.html.erb index 2408ff459..098146469 100644 --- a/app/views/bulk_update_requests/_form.html.erb +++ b/app/views/bulk_update_requests/_form.html.erb @@ -1,7 +1,9 @@ <%= simple_form_for(@bulk_update_request) do |f| %> <%= error_messages_for("bulk_update_request") %> - <%= f.input :title, :as => :string %> + <% if @bulk_update_request.new_record? %> + <%= f.input :title, :as => :string %> + <% end %>