Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/resources_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ResourcesController < ApplicationController
include ExternallyRedirectable, AhoyTracking, TagAssignable, MentionableScopable

skip_before_action :authenticate_user!, only: [ :index, :show ]
skip_before_action :authenticate_user!, only: [ :index, :show, :download ]

def index
authorize!
Expand Down
2 changes: 1 addition & 1 deletion app/policies/resource_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update?
end

def download?
true
show?

@maebeale maebeale Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i don't think show will be true for these hidden_from_search resources. i think true is better, or, we add show? || record.hidden_from_search?, or, update the show policy action.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There is a mix up between the policy scope and the policies related to controller actions.

hidden_from_search is not a controller action, it is just the flag the search scope looks at to filter out results.

I'm confident show? is set up correctly. A resource that is hidden from search would still need the correct settings for the correct users to see it regardless of if it is hidden from search or not. In turn, if a user can see the show page, they should be able to download it as well.

end

def filter_published?
Expand Down
50 changes: 30 additions & 20 deletions spec/policies/resource_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ def policy_for(record:, user:)
expect(policy_for(record: published_resource, user: guest_user))
.not_to be_allowed_to(:show?)
end

it "can still reach a publicly visible resource that is hidden from search" do
hidden_public_resource = build_stubbed(
:resource,
published: false,
publicly_visible: true,
hidden_from_search: true
)
expect(policy_for(record: hidden_public_resource, user: guest_user))
.to be_allowed_to(:show?)
end
end
end

Expand Down Expand Up @@ -135,19 +124,40 @@ def policy_for(record:, user:)
# -----------------------------------------

describe "#download?" do
it "allows admin" do
expect(policy_for(record: private_resource, user: admin_user))
.to be_allowed_to(:download?)
context "admin" do
it "can download anything" do
expect(policy_for(record: private_resource, user: admin_user))
.to be_allowed_to(:download?)
end
end

it "allows regular user" do
expect(policy_for(record: private_resource, user: regular_user))
.to be_allowed_to(:download?)
context "regular user" do
it "can download published resource" do
expect(policy_for(record: published_resource, user: regular_user))
.to be_allowed_to(:download?)
end

it "cannot download private resource" do
expect(policy_for(record: private_resource, user: regular_user))
.not_to be_allowed_to(:download?)
end

it "can download publicly visible resource" do
expect(policy_for(record: public_resource, user: regular_user))
.to be_allowed_to(:download?)
end
end

it "allows guest" do
expect(policy_for(record: private_resource, user: guest_user))
.to be_allowed_to(:download?)
context "guest" do
it "can download publicly visible resource" do
expect(policy_for(record: public_resource, user: guest_user))
.to be_allowed_to(:download?)
end

it "cannot download published-only resource" do
expect(policy_for(record: published_resource, user: guest_user))
.not_to be_allowed_to(:download?)
end
end
end

Expand Down