Skip to content

Commit

Permalink
Merge pull request #1057 from ElixirTeSS/collection-policy-fix
Browse files Browse the repository at this point in the history
Ensure collaborators can see private collections
  • Loading branch information
fbacall authored Nov 25, 2024
2 parents 2fa8e11 + 0fee6e9 commit b3dc1cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/policies/collection_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def update?
end

def show?
(!@record.from_unverified_or_rejected? && @record.public?) || manage?
(!@record.from_unverified_or_rejected? && @record.public?) || update?
end

def curate?
Expand Down
20 changes: 19 additions & 1 deletion test/controllers/collections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CollectionsControllerTest < ActionController::TestCase
description: 'New description'
}
end

#INDEX TESTS
test 'should get index' do
get :index
Expand Down Expand Up @@ -81,6 +82,14 @@ class CollectionsControllerTest < ActionController::TestCase
assert_response :success
end

test 'should get edit for collection collaborator' do
collaborator = users(:another_regular_user)
@collection.collaborators << collaborator
sign_in collaborator
get :edit, params: { id: @collection }
assert_response :success
end

test 'should get edit for admin' do
#Owner of collection logged in = SUCCESS
sign_in users(:admin)
Expand Down Expand Up @@ -507,12 +516,21 @@ class CollectionsControllerTest < ActionController::TestCase
assert_response :forbidden
end

test 'should allow access to private collections if privileged' do
test 'should allow access to private collections if privileged as owner' do
sign_in users(:regular_user)
get :show, params: { id: collections(:secret_collection) }
assert_response :success
end

test 'should allow access to private collections if privileged as collaborator' do
collection = collections(:secret_collection)
collaborator = users(:another_regular_user)
collection.collaborators << collaborator
sign_in collaborator
get :show, params: { id: collection }
assert_response :success
end

test 'should hide private collections from index' do
get :index
assert_response :success
Expand Down

0 comments on commit b3dc1cb

Please sign in to comment.