Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Merge bug fix from branch 'artefact-audit-trail'.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhwthompson committed Aug 7, 2012
2 parents e1ec482 + 6465ac2 commit 43ac18e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
11 changes: 9 additions & 2 deletions app/controllers/artefacts_controller.rb
Expand Up @@ -37,7 +37,7 @@ def edit
end end


def create def create
@artefact.save_as current_user @artefact.save_as action_user
respond_with @artefact, location: @artefact.admin_url(params.slice(:return_to)) respond_with @artefact, location: @artefact.admin_url(params.slice(:return_to))
end end


Expand All @@ -62,7 +62,7 @@ def update
return return
end end


saved = @artefact.update_attributes_as(current_user, parameters_to_use) saved = @artefact.update_attributes_as(action_user, parameters_to_use)
flash[:notice] = saved ? 'Panopticon item updated' : 'Failed to save item' flash[:notice] = saved ? 'Panopticon item updated' : 'Failed to save item'


if saved && params[:commit] == 'Save and continue editing' if saved && params[:commit] == 'Save and continue editing'
Expand Down Expand Up @@ -111,4 +111,11 @@ def extract_parameters(params)
parameters_to_use parameters_to_use
end end


def action_user
# The user to associate with actions
# Currently this returns nil for the API user: this should go away once
# we have real user authentication for API requests
action_user = current_user.is_a?(User) ? current_user : nil
end

end end
19 changes: 19 additions & 0 deletions test/functional/artefacts_controller_test.rb
Expand Up @@ -158,6 +158,25 @@ class ArtefactsControllerTest < ActionController::TestCase
assert_equal stub_user, artefact.actions.last.user assert_equal stub_user, artefact.actions.last.user
end end


should "Not record the user for API requests" do
login_as GDS::SSO::ApiUser.new
artefact = Artefact.create!(
:slug => 'whatever',
:kind => 'guide',
:owning_app => 'publisher',
:rendering_app => 'frontend',
:name => 'Whatever',
:need_id => 1
)

put :update, id: artefact.id, format: :json, name: "Changed"
assert_response :success

artefact.reload
assert_equal nil, artefact.actions.last.user
end


should "Update our primary section and ensure it persists into sections" do should "Update our primary section and ensure it persists into sections" do
@tags = FactoryGirl.create_list(:tag, 3) @tags = FactoryGirl.create_list(:tag, 3)
artefact = Artefact.create!(:slug => 'whatever', :kind => 'guide', artefact = Artefact.create!(:slug => 'whatever', :kind => 'guide',
Expand Down
6 changes: 5 additions & 1 deletion test/test_helper.rb
Expand Up @@ -41,10 +41,14 @@ def stub_user
end end


def login_as_stub_user def login_as_stub_user
login_as stub_user
end

def login_as(user)
request.env['warden'] = stub( request.env['warden'] = stub(
:authenticate! => true, :authenticate! => true,
:authenticated? => true, :authenticated? => true,
:user => stub_user :user => user
) )
end end


Expand Down

0 comments on commit 43ac18e

Please sign in to comment.