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

[FEATURE] Require 'system_administrator' permission to '/plugins/caas_next_refid' endpoint #19 #22

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/controllers/caas_next_refid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ArchivesSpaceService < Sinatra::Base
Endpoint.post('/plugins/caas_next_refid')
.description("Get next ref_id for provided resource")
.params(["resource_id", Integer, "The resource id", :required => "true"])
.permissions([])
.permissions([:administer_system])
.returns([200, "{'resource_id', 'ID', 'next_refid', N}"]) \
do
existing_refid_record = CaasAspaceRefid.find(resource_id: params[:resource_id])
Expand Down
16 changes: 16 additions & 0 deletions backend/spec/controller_caas_next_refid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@
expect(JSON(last_response.body)['next_refid']).to eq(41)
end
end

context 'when a user without administer system permissions' do
before do
make_test_user('archivist')
end

it 'denies access' do
as_test_user('archivist') do
post '/plugins/caas_next_refid', params = { resource_id: 1 }

expect(last_response).not_to be_ok
expect(last_response.status).to eq(403)
expect(last_response.body).to match(/Access denied/)
end
end
end
end
end

Expand Down