Skip to content

AO3-6218 Allow certain admins to access all collection and challenge pages usually reserved for owners#5592

Open
not-varram wants to merge 6 commits intootwcode:masterfrom
not-varram:AO3-6218-Allow-certain-admins-to-access-all-collection
Open

AO3-6218 Allow certain admins to access all collection and challenge pages usually reserved for owners#5592
not-varram wants to merge 6 commits intootwcode:masterfrom
not-varram:AO3-6218-Allow-certain-admins-to-access-all-collection

Conversation

@not-varram
Copy link
Contributor

Pull Request Checklist

Issue

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

Purpose

Allow admins with support, policy_and_abuse, or superadmin roles to access owner/maintainer collection and challenge pages for viewing/troubleshooting, without granting write permissions.

Implemented via shared controller helpers and action-level filter changes so read routes are opened for those roles while create/update/destroy paths remain owner/maintainer-only.

Testing Instructions

Automated coverage was added/updated for the affected controllers to verify:

  • allowed admin roles can access read pages
  • other admin roles cannot
  • privileged admins still cannot perform protected updates

(Functional QA flow is already documented in the Jira ticket.)

Credit

varram (he/him)

Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

Please use pundit for the access control. You can find our existing policies in the app/policies folder if you'd like examples. The other issues on the admin role Epic also have examples of pundit implementations.

Since this is a rather big PR already just with the permission changes, I would prefer if you didn't action unrelated rubocop issues, like the i18n changes you did here. The risk that something accidentally breaks is just too big there to include it all with the permission changes.

For the specs, please use the an action only authorized admins can access shared example if possible, it tests a lot of admin roles automatically. Examples for it's use can be found all across the admin role tests.

@not-varram
Copy link
Contributor Author

Hey- I dont have a way to get this out of "Coder has reviewed action" tag but I'm still working on it.

@not-varram
Copy link
Contributor Author

it's ready to be reviewed :)

Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! This looks pretty good already, I just have a few nitpicks

I wanted to note that this doesn't touch anything in the views, so there are a bunch of links/buttons that will show for owners but not authorized admins, e.g. the links the collection sidebar. Please keep it that way! We'll make separate Jira issues to add these links into the pages for the authorized admins later, since this PR is already quick big to code/review/test

Comment on lines +3 to +5
before_action :users_or_privileged_collection_admin_only, only: [:edit]
before_action :load_collection_from_id, only: [:show, :edit, :update, :destroy, :confirm_delete]
before_action :collection_owners_only, only: [:edit, :update, :destroy, :confirm_delete]
before_action :collection_owners_or_privileged_admins_only, only: [:edit]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be enough to list edit only in collection_owners_or_privileged_admins_only?

I suppose the duplication comes from edit being listed in users_only, but from what I can tell both it and update can be removed from there

Comment on lines +41 to 45
elsif logged_in_as_admin?
admin_only_access_denied and return
else
flash[:error] = ts("You don't have permission to see that, sorry!")
redirect_to collections_path and return
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
elsif logged_in_as_admin?
admin_only_access_denied and return
else
flash[:error] = ts("You don't have permission to see that, sorry!")
redirect_to collections_path and return
else
admin_only_access_denied and return if logged_in_as_admin?
flash[:error] = ts("You don't have permission to see that, sorry!")
redirect_to collections_path and return

is more readable to me? very style/opinion based though, so definitely tell me no here if you disagree, the existing code is also fine

class CollectionParticipantsController < ApplicationController
before_action :users_only
before_action :users_only, except: [:index]
before_action :users_or_privileged_collection_admin_only, only: [:index]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be enough to list index only in collection_maintainers_or_privileged_admins_only?

redirect_to "/" and return
end
unless @collection.challenge_type == "PromptMeme" || (@collection.challenge_type == "GiftExchange" && @collection.challenge.user_allowed_to_see_requests_summary?(current_user))
unless @collection.challenge_type == "PromptMeme" || privileged_collection_admin? || (@collection.challenge_type == "GiftExchange" && @collection.challenge.user_allowed_to_see_requests_summary?(current_user))
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about combining the admin check into user_allowed_to_see_requests_summary? (and maybe renaming the method)?

That would make this a bit shorter here


before_action :users_only
before_action :users_only, except: [:index, :show]
before_action :users_or_privileged_collection_admin_only, only: [:index, :show]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be enough to list index and show only in collection_maintainers_or_privileged_admins_only?

In fact the whole before_action :users_only also seems useless to me, since everything is either collection_maintainers_or_privileged_admins_only or collection_maintainers_only

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, shouldn't it only be index that's allowed for admins?

policy(Collection).access?
end

def users_or_privileged_collection_admin_only
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def users_or_privileged_collection_admin_only
def users_or_privileged_collection_admins_only

it's inconsistent :(

not_allowed(@collection) unless user_scoped? || @challenge.user_allowed_to_see_assignments?(current_user) || privileged_collection_admin?

@claims = ChallengeClaim.unposted_in_collection(@collection)
@claims = @claims.where(claiming_user_id: current_user.id) if user_scoped?
Copy link
Contributor

Choose a reason for hiding this comment

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

This will error 500 for admins, won't it?

describe "admin access to assignments pages" do
authorized_roles = %w[support policy_and_abuse superadmin].freeze
let(:gift_exchange) { create(:gift_exchange, assignments_sent_at: Faker::Time.backward) }
let(:user) { other_user }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required?

Copy link
Contributor

Choose a reason for hiding this comment

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

while you're in this file, could you check whether bookmark_search: true, collection_search: true, work_search: true could be removed from the topmost describe? I have no idea why those are there

let(:gift_exchange) { create(:gift_exchange, assignments_sent_at: Faker::Time.backward) }
let(:user) { other_user }

before { fake_logout }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this required? I'd expect the admin login from the it_behaves_like to override the user login that's define in this file

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.

2 participants