Skip to content

Commit

Permalink
[FEATURE] Require 'system_administrator' permission to '/plugins/caas…
Browse files Browse the repository at this point in the history
…_next_refid' endpoint Smithsonian#19
  • Loading branch information
lorawoodford committed Jan 21, 2025
1 parent f9682c7 commit 11f5905
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .github/workflows/codescan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Code Scan

on:
pull_request:
branches:
- main
push:

jobs:
backend_plugins:
runs-on: ubuntu-latest
env:
PROD_ARCHIVESSPACE_VERSION: v3.3.1

steps:
- name: Checkout ArchivesSpace
uses: actions/checkout@v4
with:
ref: ${{ env.PROD_ARCHIVESSPACE_VERSION }}
repository: Smithsonian/archivesspace

- name: Checkout plugin
uses: actions/checkout@v4
with:
path: ${{ github.event.repository.name }}

- name: Copy plugin to ArchivesSpace
run: |
cp -r ${{ github.workspace }}/${{ github.event.repository.name }} ${{ github.workspace }}/plugins
- name: Run Rubocop
run: |
./build/run rubocop -Ddir="plugins/${{ github.event.repository.name }}"
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
inherit_from: ../../.rubocop.yml

inherit_mode:
merge:
- Include

AllCops:
Include:
- .
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
current_refid = 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 @@ -21,6 +21,22 @@
expect(last_response).to be_ok
expect(last_response.status).to eq(200)
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

0 comments on commit 11f5905

Please sign in to comment.