Skip to content
Merged
10 changes: 6 additions & 4 deletions app/models/search/work_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def type_filter
def user_filter
return if user_ids.blank?

if viewing_own_collected_works_page?
if collected_works_page_owner_or_admin?
{
has_child: {
type: "creator",
Expand Down Expand Up @@ -331,9 +331,10 @@ def collected?
options[:collected]
end

def viewing_own_collected_works_page?
def collected_works_page_owner_or_admin?
collected? && options[:works_parent].present? &&
options[:works_parent] == User.current_user
(options[:works_parent] == User.current_user ||
User.current_user.is_a?(Admin))
end

def include_restricted?
Expand All @@ -348,9 +349,10 @@ def include_unrevealed?

# Include anonymous works if we're not on a user/pseud page
# OR if the user is viewing their own collected works
# OR an admin is viewing someone's collected works
def include_anon?
(user_ids.blank? && pseud_ids.blank?) ||
viewing_own_collected_works_page?
collected_works_page_owner_or_admin?
end

def user_ids
Expand Down
5 changes: 2 additions & 3 deletions app/views/works/_work_module.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<% # expects "work" %>

<% if work.unrevealed? && !is_author_of?(work) %>
<% if work.unrevealed? && !is_author_of?(work) && !(User.current_user.is_a?(Admin) && current_page?(controller: "works", action: "collected")) %>
<%= render "works/mystery_blurb", item: work %>
<% else %>
<!--title, author, fandom-->
<div class="header module">
<!-- updated_at=<%= work.updated_at.to_i.to_s %> -->
<h4 class="heading">
<% if (work.unrevealed? || work.anonymous?) && is_author_of?(work) %>
<% if (work.unrevealed? || work.anonymous?) && (is_author_of?(work) || User.current_user.is_a?(Admin)) %>
<span class="status">
<% if work.unrevealed? %>
<%= ts("Unrevealed:") %>
Expand Down
34 changes: 34 additions & 0 deletions features/search/works_collected.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,37 @@ Feature: Search collected works
And I should not see "New Title"
And I should see "Revised Title"
And I should see "Old Title"

Scenario: Works that are collected in an unrevealed or anonymous collection
has correct blurbs in the creator's collected works page for admins and the
creator, and the collections exist on filters on that page
Given I have the anonymous collection "Johnlock"
And I have the hidden collection "Adlock"
And I am logged in as "author"
And I post the work "Normal"
And I post the work "Scarlet" in the collection "Johnlock"
And I post the work "Hound" in the collection "Adlock"
When I go to author's user page
And I follow "Works (1)"
And I follow "Works in Collections"
Then I should see "Anonymous: Scarlet by Anonymous"
And I should see "Unrevealed: Hound by author"
And I should see "Johnlock (1)"
And I should see "Adlock (1)"
When I am logged in as an admin
And I go to author's user page
And I follow "Works (1)"
And I follow "Works in Collections"
Then I should see "Anonymous: Scarlet by Anonymous"
And I should see "Unrevealed: Hound by author"
And I should see "Johnlock (1)"
And I should see "Adlock (1)"
When I am logged in as a random user
And I go to author's user page
And I follow "Works (1)"
And I follow "Works in Collections"
Then I should not see "Anonymous: Scarlet by Anonymous"
And I should not see "Unrevealed: Hound by author"
And I should not see "Johnlock (1)"
And I should not see "Adlock (1)"

5 changes: 5 additions & 0 deletions features/users/user_dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ Feature: User dashboard
And I go to meatloaf's user page
Then I should see "Recent works"
And I should not see "Anon Work" within "#user-works"
When I am logged in as an admin
And I go to meatloaf's user page
Then I should see "Recent works"
And I should not see "Anon Work" within "#user-works"


Scenario: The user dashboard should list up to five of the user's series and link to more
Given I am logged in as "meatloaf"
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/works/default_rails_actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,12 @@ def call_with_params(params)
get :collected, params: { user_id: collected_user.login }
expect(assigns(:works)).to include(work, anonymous_work)
end

it "returns anonymous works in collections for admins" do
fake_login_admin(create(:admin))
get :collected, params: { user_id: collected_user.login }
expect(assigns(:works)).to include(work, anonymous_work)
end
end

context "with restricted works" do
Expand Down Expand Up @@ -889,6 +895,12 @@ def call_with_params(params)
get :collected, params: { user_id: collected_user.login }
expect(assigns(:works)).to include(work, unrevealed_work)
end

it "returns unrevealed works in collections for admins" do
fake_login_admin(create(:admin))
get :collected, params: { user_id: collected_user.login }
expect(assigns(:works)).to include(work, unrevealed_work)
end
end

context "with sorting options" do
Expand Down
Loading