keep mapping.user as the creator
This commit is contained in:
parent
32700d3ac1
commit
f8e7bf6d31
2 changed files with 11 additions and 3 deletions
|
@ -7,11 +7,13 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
# mappings are the only things where the user is set to the latest updater
|
# hack: set the user temporarily so the model hook can reference it, then set it back
|
||||||
# done this way so that the model hooks can use the mapping user to determine who took this action
|
temp = resource.user
|
||||||
resource.user = current_user if current_user.present? # current_user should always be present
|
resource.user = current_user
|
||||||
update_action
|
update_action
|
||||||
respond_with_resource
|
respond_with_resource
|
||||||
|
resourse.user = temp
|
||||||
|
update_action
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -31,6 +31,8 @@ class MappingsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
authorize @mapping
|
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.user = current_user
|
||||||
@mapping.assign_attributes(mapping_params)
|
@mapping.assign_attributes(mapping_params)
|
||||||
|
|
||||||
|
@ -39,12 +41,16 @@ class MappingsController < ApplicationController
|
||||||
else
|
else
|
||||||
render json: @mapping.errors, status: :unprocessable_entity
|
render json: @mapping.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
|
# restore the original mapping creator
|
||||||
|
@mapping.user = temp
|
||||||
|
@mapping.save
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /mappings/1.json
|
# DELETE /mappings/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
authorize @mapping
|
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.user = current_user
|
||||||
@mapping.destroy
|
@mapping.destroy
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue