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-5520 Admin roles restrict ability to add or modify wrangling guidelines #4398

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

Conversation

Cesium-Ice
Copy link
Contributor

@Cesium-Ice Cesium-Ice commented Nov 25, 2022

Pull Request Checklist

Issue

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

Purpose

What does this PR do?

Testing Instructions

How can the Archive's QA team verify that this is working as you intended?

If you have a Jira account with access, please update or comment on the issue
with any new or missing testing instructions instead.

References

Are there other relevant issues/pull requests/mailing list discussions?

Credit

What name and pronouns should we use to credit you in the Archive of Our Own's Release Notes?

Cesium-Ice, they/them
If you have a Jira account, please include the same name in the "Full name"
field on your Jira profile, so we can assign you the issues you're working on.

Please note that if you do not fill in this section, we will use your GitHub account name and
they/them pronouns.

@Cesium-Ice Cesium-Ice marked this pull request as ready for review November 26, 2022 01:00
@Cesium-Ice Cesium-Ice changed the title Ao3 5520 admin roles restrict ability to add or modify wrangling guidelines AO3-5520 Admin roles restrict ability to add or modify wrangling guidelines Nov 26, 2022
@@ -58,7 +60,9 @@
</ul>
</li>
<% end %>
<li><%= link_to ts("Tag Wrangling", key: "header"), tag_wranglings_path %></li>
<% if policy(WranglingGuideline).new? %>
Copy link
Member

Choose a reason for hiding this comment

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

We're not actually restricting Tag Wrangling in this PR, so let's leave the Tag Wrangling link as-is.

@@ -14,21 +14,25 @@ def show
# GET /wrangling_guidelines/new
def new
@wrangling_guideline = WranglingGuideline.new
authorize @wrangling_guideline
Copy link
Member

Choose a reason for hiding this comment

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

Anywhere we're doing @wrangling_guideline = WranglingGuideline.new or @wrangling_guideline = WranglingGuideline.find, we should be able to just stick authorize in front of WranglingGuideline to make things a bit neater.

@@ -8,7 +8,7 @@

<!--main content-->
<div class="admin" role="article">
<% if logged_in_as_admin? %>
<% if policy(WranglingGuideline).new? %>
Copy link
Member

Choose a reason for hiding this comment

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

Since we're deciding whether to display the edit link, let's use policy(WranglingGuideline).edit? instead.

@Cesium-Ice
Copy link
Contributor Author

Is there some way I can run the rubocop check locally?

@Bilka2
Copy link
Contributor

Bilka2 commented May 21, 2024

Is there some way I can run the rubocop check locally?

Yes, see https://github.com/otwcode/otwarchive/wiki/Coding-Standards#user-content-Previewing_Reviewdog_comments. If you're using Docker, I would recommend running the commands similarly to the tests, with docker compose run: docker compose run --rm test bundle exec rubocop app/controllers/wrangling_guidelines_controller.rb

@Cesium-Ice
Copy link
Contributor Author

Cesium-Ice commented May 21, 2024

When I fix the error with rubocop by replacing instances of ts with t, the wrangling_guidelines_controller_spec.rb unit tests fails with errors like so:

8) WranglingGuidelinesController DELETE #destroy when logged in as an admin with superadmin role deletes and redirects to index
     Failure/Error: expect(flash[:notice]).to eq notice
     
       expected: "Wrangling Guideline was successfully deleted."
            got: "translation missing: Wrangling Guideline was successfully deleted."
     

Does this mean instead of having instances of t("insert string here") I need to move "insert string here" into en.yml?

@Bilka2
Copy link
Contributor

Bilka2 commented May 21, 2024

Yes, as you said you need to move the string into the yml file and use a key in the t() call. You can find more information on the i18n standards wiki page. You may find the i18n-tasks section useful for some commands to find if you missed any translations - it would also flag this issue.

@Cesium-Ice Cesium-Ice requested a review from sarken May 22, 2024 07:50
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.

I'm not sarken, but I had a look over the PR and it looks good. Thank you!

@sarken
Copy link
Member

sarken commented Jul 18, 2024

Sorry for the delay! We were discussing how we wanted to approach admin roles for wrangling areas, and we determined the best way to do it would be to put everything -- including Wrangling Guidelines -- under one WranglingPolicy as described in AO3-6758.

Obviously, that would require significant changes to this pull request. Is that something you'd be interested in working on? If not, that's fine! You've already spent a lot of time on this and I bet you're sick of it -- someone else would be happy to take over (and give you credit for all the work you did, of course). There's no rush to actually update this, but if you could let us know within the next 14 days if you'd like to keep working on this or would prefer someone else adopt it, that would be great.

Thank you!

@Cesium-Ice
Copy link
Contributor Author

I’m good with working on it

@brianjaustin
Copy link
Member

Hi @Cesium-Ice! I started working on another issue in this same epic, with the WranglingPolicy: #4885. Feel free to pull that in and modify as needed if helpful! (Otherwise I'm happy to resolve merge conflicts later if you already have something in progress.)

@Bilka2
Copy link
Contributor

Bilka2 commented Aug 8, 2024

This is was missing from the Jira issue, but in app/views/admin/_admin_nav.html.erb there should be a check for the policy for showing the wrangling guidelines button, similar to the check in the admin header partial.

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.

Thanks for updating this, there are just some minor issues remaining.

@@ -9,7 +9,7 @@
</li>
<% if params[:controller] == "admin_posts" && params[:action] == "edit" %>
<li>
<%= link_to t("admin.admin_nav.delete", default: "Delete Post"),
<%= link_to t("admin.admin_nav.delete"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion to match #4891:

Suggested change
<%= link_to t("admin.admin_nav.delete"),
<%= link_to t(".news.delete_post"),

Comment on lines 2 to 3
include WranglingHelper

Copy link
Contributor

Choose a reason for hiding this comment

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

Is anything from the helper used in this file?

@@ -13,57 +15,64 @@ def show

# GET /wrangling_guidelines/new
def new
authorize :wrangling if logged_in_as_admin?
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these actions are admin only (see the before_action), so the logged_in_as_admin? check is redundant. Please remove it here and from the other authorize calls in this controller.

Suggested change
authorize :wrangling if logged_in_as_admin?
authorize :wrangling

</li>
<% if policy(:wrangling).new? %>
<li>
<%= span_if_current t("admin.admin_nav.wrangling_guidelines"), wrangling_guidelines_path %>
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be shortened by using a relative key:

Suggested change
<%= span_if_current t("admin.admin_nav.wrangling_guidelines"), wrangling_guidelines_path %>
<%= span_if_current t(".wrangling_guidelines"), wrangling_guidelines_path %>

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 very much!

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.

5 participants