Remove name from invitation flow (#17438)
* remove name from invite user flow * remove name from invitation instructions * update invitations spec * update specs and invitation actions overflow menu name * allow users to set name when accepting invite
This commit is contained in:
parent
b2c7f7a5a3
commit
25bf8a0711
14 changed files with 23 additions and 29 deletions
|
|
@ -13,7 +13,6 @@ module Admin
|
|||
|
||||
def create
|
||||
email = params.dig(:user, :email)
|
||||
name = params.dig(:user, :name)
|
||||
|
||||
if User.exists?(email: email.downcase, registered: true)
|
||||
flash[:error] = I18n.t("admin.invitations_controller.duplicate", email: email)
|
||||
|
|
@ -21,9 +20,8 @@ module Admin
|
|||
return
|
||||
end
|
||||
|
||||
username = "#{name.downcase.tr(' ', '_').gsub(/[^0-9a-z ]/i, '')}_#{rand(1000)}"
|
||||
username = "#{email.split('@').first.gsub(/[^0-9a-z ]/i, '')}_#{rand(1000)}"
|
||||
User.invite!(email: email,
|
||||
name: name,
|
||||
username: username,
|
||||
remote_profile_image_url: ::Users::ProfileImageGenerator.call,
|
||||
registered: false)
|
||||
|
|
|
|||
|
|
@ -276,6 +276,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: %i[username name profile_image profile_image_url])
|
||||
devise_parameter_sanitizer.permit(:accept_invitation, keys: %i[name])
|
||||
end
|
||||
|
||||
def internal_nav_param
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class InvitationsController < Devise::InvitationsController
|
|||
yield resource if block_given?
|
||||
|
||||
if invitation_accepted
|
||||
resource.update!(registered_at: Time.current, registered: true)
|
||||
resource.update!(registered_at: Time.current, registered: true, name: params[:user][:name])
|
||||
if resource.class.allow_insecure_sign_in_after_accept
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message :notice, flash_message if is_flashing_format?
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
<div class="flex">
|
||||
<%= render "admin/users/index/member_image", user: user %>
|
||||
<div class="flex flex-col gap-2">
|
||||
<%= render "admin/users/index/member_data", user: user %>
|
||||
<span class="color-base-60">@<%= user.username %></span>
|
||||
<%= user.email %>
|
||||
<dl>
|
||||
<dt class="color-base-60 fw-normal">Invited on</dt>
|
||||
|
|
@ -69,9 +69,9 @@
|
|||
<% @invitations.each do |user| %>
|
||||
<tr>
|
||||
<td class="pl-7">
|
||||
<div class="flex">
|
||||
<div class="flex items-center">
|
||||
<%= render "admin/users/index/member_image", user: user %>
|
||||
<%= render "admin/users/index/member_data", user: user %>
|
||||
<span class="color-base-60">@<%= user.username %></span>
|
||||
</div>
|
||||
</td>
|
||||
<td><%= user.email %></td>
|
||||
|
|
|
|||
|
|
@ -30,13 +30,6 @@
|
|||
placeholder: "Email of invitee",
|
||||
required: true %>
|
||||
</div>
|
||||
<div class="crayons-field mt-6">
|
||||
<%= f.label :name, class: "crayons-field__label" %>
|
||||
<%= f.text_field :name,
|
||||
class: "crayons-textfield",
|
||||
placeholder: "Name of invitee",
|
||||
required: true %>
|
||||
</div>
|
||||
<div class="mt-6">
|
||||
<%= f.submit "Invite User", class: "crayons-btn" %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<div class="relative flex">
|
||||
<button type="button" id="<%= user.id %>-action-dropdown-btn-<%= context %>" data-toggle-dropdown="<%= user.id %>-action-dropdown-<%= context %>" aria-controls="<%= user.id %>-action-dropdown-<%= context %>" aria-haspopup="true" aria-expanded="false"
|
||||
class="c-btn c-btn--icon-alone ml-auto" aria-label="Invitation actions: <%= user.name %>">
|
||||
class="c-btn c-btn--icon-alone ml-auto" aria-label="Invitation actions: <%= user.email %>">
|
||||
<%= crayons_icon_tag("overflow-vertical", aria_hidden: true) %>
|
||||
</button>
|
||||
<div id="<%= user.id %>-action-dropdown-<%= context %>" class="crayons-dropdown right-0">
|
||||
|
|
|
|||
|
|
@ -7,12 +7,17 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div class="mt-3 crayons-card p-7 align-left">
|
||||
<h2>Set a password to access your account</h2>
|
||||
<h2>Finish setting up your account</h2>
|
||||
|
||||
<%= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put }) do |f| %>
|
||||
<%= render "devise/shared/error_messages", resource: resource %>
|
||||
<%= f.hidden_field :invitation_token, readonly: true %>
|
||||
|
||||
<div class="crayons-field mt-5">
|
||||
<%= f.label :name, class: "crayons-field__label" %>
|
||||
<%= f.text_field :name, class: "crayons-textfield" %>
|
||||
</div>
|
||||
|
||||
<% if f.object.class.require_password_on_accepting %>
|
||||
<div class="crayons-field mt-5">
|
||||
<%= f.label :password, class: "crayons-field__label" %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<p><%= t("devise.mailer.invitation_instructions.hello", name: @resource.name) %></p>
|
||||
<p><%= t("devise.mailer.invitation_instructions.hello") %></p>
|
||||
|
||||
<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", community_name: Settings::Community.community_name, url: root_url) %></p>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<%= t("devise.mailer.invitation_instructions.hello", name: @resource.name) %>
|
||||
<%= t("devise.mailer.invitation_instructions.hello") %>
|
||||
|
||||
<%= t("devise.mailer.invitation_instructions.someone_invited_you", community_name: Settings::Community.community_name, url: root_url) %>
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ en:
|
|||
accept_instructions: You can accept the invitation by clicking this link
|
||||
accept: Accept Invitation
|
||||
accept_until: This invitation will expire after %{due_date}.
|
||||
hello: Hello %{name}
|
||||
hello: Hello
|
||||
ignore: If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above and set your password.
|
||||
someone_invited_you: You’ve been invited to join the %{community_name} community at %{url}.
|
||||
subject: Invitation instructions
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ fr:
|
|||
accept_instructions: Vous pouvez accepter l'invitation en cliquant sur ce lien
|
||||
accept: Accepter l'invitation
|
||||
accept_until: Cette invitation expirera après %{due_date}.
|
||||
hello: Bonjour %{name}
|
||||
hello: Bonjour
|
||||
ignore: Si vous ne souhaitez pas accepter cette invitation, veuillez ignorer cet e-mail.<br />Votre compte ne sera pas créé tant que vous n'accéderez pas au lien ci-dessous et que vous ayez défini votre mot de passe.
|
||||
someone_invited_you: Vous avez été invité à rejoindre la communauté %{community_name} sur %{url}.
|
||||
subject: Vous avez reçu une invitation
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ describe('Invited users', () => {
|
|||
};
|
||||
|
||||
const resendInviteForTestMember = () => {
|
||||
cy.findByRole('button', { name: 'Invitation actions: Test user' })
|
||||
cy.findByRole('button', { name: 'Invitation actions: test@test.com' })
|
||||
.pipe(click)
|
||||
.should('have.attr', 'aria-expanded', 'true');
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ describe('Invited users', () => {
|
|||
};
|
||||
|
||||
const cancelInviteForTestMember = () => {
|
||||
cy.findByRole('button', { name: 'Invitation actions: Test user' })
|
||||
cy.findByRole('button', { name: 'Invitation actions: test@test.com' })
|
||||
.pipe(click)
|
||||
.should('have.attr', 'aria-expanded', 'true');
|
||||
|
||||
|
|
|
|||
|
|
@ -21,21 +21,20 @@ RSpec.describe "/admin/invitations", type: :request do
|
|||
it "renders to appropriate page" do
|
||||
get new_admin_invitation_path
|
||||
expect(response.body).to include("Email")
|
||||
expect(response.body).to include("Name")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /admin/invitations" do
|
||||
it "creates new invitation" do
|
||||
post admin_invitations_path,
|
||||
params: { user: { email: "hey#{rand(1000)}@email.co", name: "Roger #{rand(1000)}" } }
|
||||
params: { user: { email: "hey#{rand(1000)}@email.co" } }
|
||||
expect(User.last.registered).to be false
|
||||
end
|
||||
|
||||
it "enqueues an invitation email to be sent", :aggregate_failures do
|
||||
assert_enqueued_with(job: Devise.mailer.delivery_job) do
|
||||
post admin_invitations_path,
|
||||
params: { user: { email: "hey#{rand(1000)}@email.co", name: "Roger #{rand(1000)}" } }
|
||||
params: { user: { email: "hey#{rand(1000)}@email.co" } }
|
||||
end
|
||||
|
||||
expect(enqueued_jobs.first[:args]).to match(array_including("invitation_instructions"))
|
||||
|
|
@ -44,7 +43,7 @@ RSpec.describe "/admin/invitations", type: :request do
|
|||
it "does not create an invitation if a user with that email exists" do
|
||||
expect do
|
||||
post admin_invitations_path,
|
||||
params: { user: { email: admin.email, name: "Roger #{rand(1000)}" } }
|
||||
params: { user: { email: admin.email } }
|
||||
end.not_to change { User.all.count }
|
||||
expect(admin.reload.registered).to be true
|
||||
expect(flash[:error].present?).to be true
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ RSpec.describe "Admin invites user", type: :system do
|
|||
|
||||
it "does not contain any for fields" do
|
||||
expect(page).not_to have_field "Email"
|
||||
expect(page).not_to have_field "Name"
|
||||
end
|
||||
|
||||
it "does not contain any submit buttons" do
|
||||
|
|
@ -49,9 +48,8 @@ RSpec.describe "Admin invites user", type: :system do
|
|||
visit new_admin_invitation_path
|
||||
end
|
||||
|
||||
it "shows the input fields" do
|
||||
it "shows the input field" do
|
||||
expect(page).to have_field "Email"
|
||||
expect(page).to have_field "Name"
|
||||
end
|
||||
|
||||
it "shows the submit button" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue