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

AO3-6004 show hidden bookmarks on a bookmarkable to admins #4758

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

walshyb
Copy link
Contributor

@walshyb walshyb commented Mar 1, 2024

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-6004

Purpose

Allows admins to show hidden bookmarks on a bookmarkable

Testing Instructions

  • Go to a bookmark index page with bookmarks
  • Hide a bookmark
  • When page refreshes, see "Make Bookmark Visible"
  • Clicking "Make Bookmark Visible" should refresh page and bring back bookmark

Credit

Brandon W (he/him/they/them)

@@ -61,7 +61,9 @@ def search
def index
if @bookmarkable
access_denied unless is_admin? || @bookmarkable.visible?
@bookmarks = @bookmarkable.bookmarks.is_public.paginate(page: params[:page], per_page: ArchiveConfig.ITEMS_PER_PAGE)
@bookmarks = @bookmarkable.bookmarks.is_public
@bookmarks += @bookmarkable.bookmarks.where(hidden_by_admin: true) if is_admin?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a bit weird how I'm doing it, but I didn't see another way to include bookmarks that have been hidden by admin and the public bookmarks.

Also should I add check for policy_and_abuse role?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a quick drive-by comment, not a thorough review:

  1. Let's not check the admin role, since I'm pretty sure we don't currently check it for, e.g., accessing hidden works directly. But maybe we should changes this two instances of is_admin? to logged_in_as_admin? -- this seems to be the only file where we use is_admin? and that's weird, imo.
  2. I'm guessing the problem with simply removing the is_public scope is you get private bookmarks as well as those hidden by admin? Would changing it to the not_private scope fix that? If not, I'd suggest defining a new scope in the bookmark model that will get public bookmarks, regardless of whether they're hidden by admin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I updated those is_admin? references to be logged_in_as_admin?
  2. On a work's bookmarks page, users should only see public bookmarks, unless you're an admin, then they'll want to see public and hidden, right? Or should admins also be able to see private bookmarks on a work? Also, my changes here appear to work in that non-admins can only see public bookmarks and admins can see public and hidden; do you still think we should create a new scope? It's possible I'm misunderstanding the ask

Thank you!

Copy link
Contributor

@Bilka2 Bilka2 Nov 3, 2024

Choose a reason for hiding this comment

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

On a work's bookmarks page, users should only see public bookmarks, unless you're an admin, then they'll want to see public and hidden, right?

Yes and the current code does that. The suggestion is just about making the code a bit cleaner.

The way I understand sarken's suggestion is to use the not_private scope instead of is_public, since it gets the public bookmarks regardless of the hidden_by_admin status. Then filter out the hidden bookmarks depending on logged_in_as_admin?. That way, there aren't two queries that deal with hidden_by_admin (the is_public scope and the extra query with the where added in this PR), but only the one query (not_private and conditional where for hidden_by_admin on the returned relation).

@@ -82,6 +82,7 @@ Feature: Admin Actions for Works, Comments, Series, Bookmarks
When I follow "Hide Bookmark"
And all indexing jobs have been run
Then I should see "Item has been hidden."
And I should see "Make Bookmark Visible"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add another check to follow this and confirm visible from regular user end?

Copy link
Contributor

Choose a reason for hiding this comment

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

A regular user should not be able to see a hidden bookmark. But it would be nice to have a check that an admin can see the text of the hidden bookmark.

Copy link
Contributor Author

@walshyb walshyb Oct 12, 2024

Choose a reason for hiding this comment

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

Would you like me to write a test to make sure that a regular user cannot see a hidden bookmark?

I added a check for admins to see the text

Copy link
Contributor

Choose a reason for hiding this comment

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

The test already checks that regular_user cannot see the hidden bookmark, so there is no need to add another test.

@walshyb walshyb marked this pull request as ready for review October 12, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants