Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints to lock and unlock a document #5107

Merged
merged 5 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/controllers/admin/export/document_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Admin::Export::DocumentController < Admin::Export::BaseController
skip_before_action :verify_authenticity_token
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

self.responder = Api::Responder

def show
Expand All @@ -16,6 +17,16 @@ def index
)
end

def lock
document = Document.find(params[:id])
document.update!(locked: true)
end

def unlock
document = Document.find(params[:id])
document.update!(locked: false)
end

private

def paginated_document_ids
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ def external_redirect(path_prefix, target)
root to: "dashboard#index", via: :get

namespace "export" do
resources :document, only: %i[show index], defaults: { format: :json }
resources :document, only: %i[show index], defaults: { format: :json } do
member do
post :lock
post :unlock
end
end
end

get "find-in-admin-bookmarklet" => "find_in_admin_bookmarklet#index", as: :find_in_admin_bookmarklet_instructions_index
Expand Down
32 changes: 32 additions & 0 deletions test/functional/admin/export/document_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,36 @@ class Admin::Export::DocumentControllerTest < ActionController::TestCase

assert_equal expected_response, json_response
end

test "lock returns forbidden if user does not have export data permission" do
login_as :world_editor
post :lock, params: { id: "1" }, format: "json"
assert_response :forbidden
end

test "locks document" do
document = create(:document)
login_as :export_data_user

post :lock, params: { id: document.id }, format: "json"

assert document.reload.locked
assert_response :no_content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

test "unlock returns forbidden if user does not have export data permission" do
login_as :world_editor
post :unlock, params: { id: "1" }, format: "json"
assert_response :forbidden
end

test "unlocks document" do
document = create(:document, locked: true)
login_as :export_data_user

post :unlock, params: { id: document.id }, format: "json"

refute document.reload.locked
assert_response :no_content
end
end