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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow admins to invite other staff #251

Merged
merged 3 commits into from Oct 13, 2023
Merged

Allow admins to invite other staff #251

merged 3 commits into from Oct 13, 2023

Conversation

marlena-b
Copy link
Collaborator

@marlena-b marlena-b commented Oct 10, 2023

馃敆 Issue

Fixes #226

鉁嶏笍 Description

This Pull Request adds the functionality of inviting new staff members to the organization by administrators (staff admins) using the devise_invitable gem. The invitation acceptance flow is currently in a basic form but improvements will be addressed in a subsequent PR.

馃摲 Screenshots/Demos

Nagranie.z.ekranu.2023-10-11.o.13.25.13.mov

@nsiwnf nsiwnf linked an issue Oct 11, 2023 that may be closed by this pull request
@marlena-b marlena-b marked this pull request as ready for review October 11, 2023 13:26
if @user.save
@user.staff_account.add_role(user_params[:staff_account_attributes][:roles])
@user.invite!(current_user)
redirect_to staff_index_path, notice: "Staff saved successfully."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change the notice to something like "Invite sent!"?

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 both make sense here. The staff account does get saved and the invitation is sent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think "Invite sent!" makes more sense from the user perspective. Fixed!

I also changed texts in a couple of other places from "Add staff" to "Invite staff".


<!-- button -->
<div class="col-12 mt-3">
<%= form.submit 'Save profile', class: 'btn btn-primary' %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change button to 'Send Invite' ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, thanks!

Copy link
Collaborator

@kasugaijin kasugaijin left a comment

Choose a reason for hiding this comment

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

Looks great! I tested it out locally and I like it.

I know you said you had improvements to follow in another PR, so the following is my thoughts, some which you may already have considered:

  • I am guessing the invite! call on line 16 of Organizations::InvitationsController is triggering the mailer. I am wondering if we are able to send any params to that? It would be good to send the organization so we can access its name and slug and recreate the Org's Url in the email e.g., https://www.petrescue.com/baja
  • The redirect after the invited user enters and saves their password to accept the invite, is this coming from registrations_controller def after_sign_in_path_for ? This is another place where it would be good to scope it to the organization's dashboard rather than the root path, if possible.
  • I think we could use the invitation_accepted_at column in the staff table to indicate whether or not the staff has accepted the invite in the staff table (not directly related to this work) e.g., in the status column

@@ -0,0 +1,26 @@
class DeviseInvitableAddToUsers < ActiveRecord::Migration[7.0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

My initial thought without considering the gem would be to separate Invitations from Users and have an Invitations table/model. This would be more maintainable in the long run.

However, looking at the gem, I see that adding to Users table is a 'normal' practice. I was thinking it doesn't make sense if only Org users use invites, as then we'd have a User class that for adopters has completely irrelevant fields. But, then I thought we could also leverage invitations between adopters as well at some point.

This is not to say this needs to change. I think it works like this and is ok a. But, I think with more time and a bigger budget I'd go for separating those concerns :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally agree with your point and would love to make those changes too, but sadly, this gem doesn't let us do that (there is even an issue for this: scambra/devise_invitable#888).

Let's go with what we have for now and think about extracting it later on if needed.

someone_invited_you: "Someone has invited you to %{url}, you can accept it through the link below."
accept: "Accept invitation"
accept_until: "This invitation will be due in %{due_date}."
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."
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the account is still created? Or does devise_invitation do something to the User record that gets created?

Copy link
Collaborator Author

@marlena-b marlena-b Oct 13, 2023

Choose a reason for hiding this comment

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

Hey @nsiwnf, this text was generated by Devise, and TBH I don't know why it says so. The user record will be created in the DB but with a random password so no one can access it. I will remove the Your account won't be created... sentence.

@nsiwnf
Copy link
Collaborator

nsiwnf commented Oct 13, 2023

These are great suggestions! Should we make them into tickets?

Looks great! I tested it out locally and I like it.

I know you said you had improvements to follow in another PR, so the following is my thoughts, some which you may already have considered:

* I am guessing the `invite!` call on line 16 of `Organizations::InvitationsController` is triggering the mailer. I am wondering if we are able to send any params to that? It would be good to send the organization so we can access its name and slug and recreate the Org's Url in the email e.g., https://www.petrescue.com/baja

* The redirect after the invited user enters and saves their password to accept the invite, is this coming from registrations_controller   def after_sign_in_path_for ? This is another place where it would be good to scope it to the organization's dashboard rather than the root path, if possible.

* I think we could use the invitation_accepted_at column in the staff table to indicate whether or not the staff has accepted the invite in the staff table (not directly related to this work) e.g., in the status column

Copy link
Collaborator

@nsiwnf nsiwnf left a comment

Choose a reason for hiding this comment

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

LGTM!

@marlena-b
Copy link
Collaborator Author

Thank you @kasugaijin and @nsiwnf for the review! 馃挭

I will create separate issues for your suggestions and start working on them soon :)

@marlena-b marlena-b merged commit e514793 into main Oct 13, 2023
3 checks passed
@marlena-b marlena-b deleted the devise-invitable branch October 13, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send new staff an invitation to the org
3 participants