diff --git a/app/controllers/api/v2/mappings_controller.rb b/app/controllers/api/v2/mappings_controller.rb index ae25a3c2..61f18940 100644 --- a/app/controllers/api/v2/mappings_controller.rb +++ b/app/controllers/api/v2/mappings_controller.rb @@ -7,11 +7,13 @@ module Api end def update - # mappings are the only things where the user is set to the latest updater - # done this way so that the model hooks can use the mapping user to determine who took this action - resource.user = current_user if current_user.present? # current_user should always be present + # hack: set the user temporarily so the model hook can reference it, then set it back + temp = resource.user + resource.user = current_user update_action respond_with_resource + resourse.user = temp + update_action end def destroy diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 61270948..f6fc05bf 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -31,6 +31,8 @@ class MappingsController < ApplicationController def update @mapping = Mapping.find(params[:id]) authorize @mapping + # hack: set the user temporarily so that the model hook can reference it, and then set it back + temp = @mapping.user @mapping.user = current_user @mapping.assign_attributes(mapping_params) @@ -39,12 +41,16 @@ class MappingsController < ApplicationController else render json: @mapping.errors, status: :unprocessable_entity end + # restore the original mapping creator + @mapping.user = temp + @mapping.save end # DELETE /mappings/1.json def destroy @mapping = Mapping.find(params[:id]) authorize @mapping + # hack: set the user temporarily so that the model hook can reference this user who is taking the action @mapping.user = current_user @mapping.destroy