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-6672 Allow some admins to set a generic username #4994

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

Conversation

brianjaustin
Copy link
Member

Pull Request Checklist

Issue

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

Purpose

Allow superadmins and policy_and_abuse to set a generic username for users (even when banned). Because #4991 is already open, I have not added the subscript for "Ticket ID" as noted in the ticket.

Side question: do we want to update some of the copy/variables here to be more consistent? I observed login (has to stay), user name, and username in different spots...

@sarken
Copy link
Collaborator

sarken commented Dec 17, 2024

If you're up for changing copy in a whole bunch of places, I'm up for testing! We ultimately want to switch from "user name" to "username" but it's in soooo many places I didn't want to inflict that on anyone.

I think this covers all the references to this page so we could at least have some consistency in this area:

  • this change_username page, including error messages
  • the link in the /views/users/_edit_header_navigation.html.erb partial
  • the link in the /views/users/_edit_user_navigation.html.erb partial
  • the reference to this page on /app/views/pseuds/_pseuds_form.html.erb ("You cannot change the pseud that matches your user name. However, you can change your user name instead.")
  • the link in /app/views/preferences/index.html.erb

Copy link
Collaborator

@sarken sarken left a comment

Choose a reason for hiding this comment

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

Just a couple quick frontend suggestions since we were talking about text changes!

app/views/users/_admin_change_username.html.erb Outdated Show resolved Hide resolved
config/locales/models/en.yml Outdated Show resolved Hide resolved
app/views/users/_admin_change_username.html.erb Outdated Show resolved Hide resolved
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.

Besides the comments I left, I think it would be good to have a feature test that goes through renaming a user as an admin. Just to make sure nothing gets missed because the specs test pretty close to the implementation itself.

.rubocop.yml Outdated Show resolved Hide resolved
app/controllers/pseuds_controller.rb Outdated Show resolved Hide resolved
app/controllers/pseuds_controller.rb Show resolved Hide resolved
app/controllers/users_controller.rb Outdated Show resolved Hide resolved
app/models/user.rb Outdated Show resolved Hide resolved
config/locales/views/en.yml Outdated Show resolved Hide resolved
end

it_behaves_like "an action only authorized admins can access", authorized_roles: %w[superadmin policy_and_abuse] do
let(:user) { create(:user, banned: true) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a banned user?

Copy link
Member Author

Choose a reason for hiding this comment

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

Non-exhaustive checking that users who cannot access this page themselves can be renamed by an admin

end

it "does not prevent changing the username" do
allow(existing_user).to receive(:justification_enabled?).and_return(false)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about ticket_number?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since https://github.com/otwcode/otwarchive/pull/4994/files#diff-a55bf747ae62cffdcdb15d898d6bde2ab06b44df40317d8c44330e1615b6c50fR133 already tests that, I disabled the ticket_number requirement here. I'd rather not turn it back on, because we have to mock quite a few things to make the Zoho validation happy

spec/models/user_spec.rb Show resolved Hide resolved
Copy link
Collaborator

@sarken sarken left a comment

Choose a reason for hiding this comment

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

I was reviewing in two tabs simultaneously so I could go back and forth between the views and the locales, so I'm sure this will be quality. If anything is confusing or contradictory, my bad, please yell!

app/controllers/pseuds_controller.rb Show resolved Hide resolved
@@ -564,11 +572,25 @@ def reindex_user_creations_after_rename
end

def add_renamed_at
return if User.current_user.is_a?(Admin)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with Brian here. Since we're already supposed to be ignoring the renamed_at when an admin goes to change a name, I think it makes sense that admin renames just ignore the renamed_at entirely.

However, we could add a separate admin_renamed_at column to the users table for general tracking purposes. That does feel like something that could be both useful and clarifying if you're looking at an audit or just a user in the database.

app/views/admin/admin_invitations/find.html.erb Outdated Show resolved Hide resolved
app/views/admin/admin_invitations/find.html.erb Outdated Show resolved Hide resolved
app/views/admin/admin_invitations/index.html.erb Outdated Show resolved Hide resolved
app/views/invitations/_user_invitations.html.erb Outdated Show resolved Hide resolved
app/views/users/_admin_change_username.html.erb Outdated Show resolved Hide resolved
config/locales/controllers/en.yml Outdated Show resolved Hide resolved
config/locales/devise/en.yml Show resolved Hide resolved
@github-actions github-actions bot added the Has Migrations Contains migrations and therefore needs special attention when deploying label Dec 30, 2024
@@ -1,29 +1,29 @@
<dl>
<dt>Sender</dt>
<dd><%= creator_link(invitation) %></dd>
<dd><%= creator_link(@invitation) %></dd>
Copy link
Member Author

Choose a reason for hiding this comment

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

I needed to make changes here to fix issues with how @invitation is referenced (locals versus just passing it in). For everyone's sanity, I'll do the rest of the erb lint fixes in #5000 since that has most of them already anyways

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!

<!--/descriptions-->

<!--subnav-->
<!--/subnav-->

<!--main content-->
<%= form_tag url_for(:controller => 'admin/admin_invitations', :action => 'find'), :method => :get do %>
<%= form_tag url_for(controller: "admin/admin_invitations", action: "find"), autocomplete: "off", method: :get do %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're now updating the actual form tags, let's add the classes that are missing on so many forms:

Suggested change
<%= form_tag url_for(controller: "admin/admin_invitations", action: "find"), autocomplete: "off", method: :get do %>
<%= form_tag url_for(controller: "admin/admin_invitations", action: "find"), autocomplete: "off", class: "invitation simple search", method: :get do %>

<dd><%= text_field_tag "invitation[user_name]", params[:invitation][:user_name] %></dd>
<dt><%= label_tag "invitation[token]", t(".token") %></dt>
<dd><%= text_field_tag "invitation[token]", params[:invitation][:token] %></dd>
<dt><%= label_tag "invitee_email", t(".email") %></dt>
<dd><%= text_field_tag "invitation[invitee_email]", params[:invitation][:invitee_email], id: "invitee_email" %></dd>
</dl>
<p class="submit actions"><%= submit_tag "Go" %></p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missed a string, although it could really be "Search" instead of "Go."

<dd><%= text_field_tag "invitation[invitee_email]", params[:invitation][:invitee_email], id: "invitee_email" %></dd>
</dl>
<p class="submit actions"><%= submit_tag "Go" %></p>
<% end %>

<% if @user %>
<h3 class="heading"><%h= 'Invitations for' %> <%= link_to @user.login, user_invitations_path(@user) %></h3>
<%= render :partial => 'invitations/user_invitations', :locals => {:invitations => @invitations} %>
<h3 class="heading"><%= t(".invitations_for") %> <%= link_to @user.login, user_invitations_path(@user) %></h3>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this needs some interpolation so the link to the name is part of the translated text.

Comment on lines +26 to 27
<%= form_tag url_for(controller: "admin/admin_invitations", action: :invite_from_queue), autocomplete: "off" do %>
<fieldset class="simple">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= form_tag url_for(controller: "admin/admin_invitations", action: :invite_from_queue), autocomplete: "off" do %>
<fieldset class="simple">
<%= form_tag url_for(controller: "admin/admin_invitations", action: :invite_from_queue), class: "queue invitation simple post", autocomplete: "off" do %>
<fieldset>

Comment on lines +13 to 14
<%= form_tag url_for(controller: "admin/admin_invitations", action: :create), autocomplete: "off" do |f| %>
<fieldset class="simple">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= form_tag url_for(controller: "admin/admin_invitations", action: :create), autocomplete: "off" do |f| %>
<fieldset class="simple">
<%= form_tag url_for(controller: "admin/admin_invitations", action: :create), class: "invitation simple post", autocomplete: "off" do |f| %>
<fieldset>

Conveniently, this will move the submit button closer to the fields. simple was in the wrong place to have any effect before.

Comment on lines +32 to +33
<%= form_tag changed_username_user_path(@user), autocomplete: "off" do %>
<dl>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same suggestion for the legend and heading as in the admin partial:

Suggested change
<%= form_tag changed_username_user_path(@user), autocomplete: "off" do %>
<dl>
<%= form_tag changed_username_user_path(@user), class: "simple post", autocomplete: "off" do %>
<legend><%= t(".legend") %></legend>
<h3 class="landmark heading"><%= t(".heading") %></h3>
<dl>

</p>
</dd>
<dt><%= label_tag :password, t(".password") %></dt>
<dd><%= password_field_tag :password, nil, autocomplete: "disabled" %></dd>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need autocomplete: "disabled" when the form has autocomplete: "off" because it's a password field?

<h3 class="heading"><%h= 'Invitations for' %> <%= link_to @user.login, user_invitations_path(@user) %></h3>
<%= render :partial => 'invitations/user_invitations', :locals => {:invitations => @invitations} %>
<h3 class="heading"><%= t(".invitations_for") %> <%= link_to @user.login, user_invitations_path(@user) %></h3>
<%= render partial: "invitations/user_invitations", invitations: @invitations %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= render partial: "invitations/user_invitations", invitations: @invitations %>
<%= render "invitations/user_invitations", invitations: @invitations %>

<% elsif @invitation %>
<%= render :partial => 'invitations/invitation', :locals => {:invitation => @invitation} %>
<%= render partial: "invitations/invitation", invitation: @invitation %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= render partial: "invitations/invitation", invitation: @invitation %>
<%= render "invitations/invitation", invitation: @invitation %>

<% elsif @invitations %>
<%= render :partial => 'invitations/user_invitations', :locals => {:invitations => @invitations} %>
<%= render partial: "invitations/user_invitations", invitations: @invitations %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= render partial: "invitations/user_invitations", invitations: @invitations %>
<%= render "invitations/user_invitations", invitations: @invitations %>

@sarken
Copy link
Collaborator

sarken commented Jan 6, 2025

(Sorry for all the comments! If it makes you feel any better, the review took me three days to finish. 😆)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Has Migrations Contains migrations and therefore needs special attention when deploying Reviewed: Action Needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants