Member invitations via email link - #13
Merged
Merged
Conversation
Admins can now invite a teammate without typing a password for them. Leaving the password blank on the new-user form stashes an unusable random password and emails a 7-day link (generates_token_for :invitation) to set their own. The link is single-use — accepting stamps invitation_accepted_at, which both flips the 'Invite pending' badge and invalidates the token. - User: :invitation token generator + pending_invitation scope + #invitation_pending? - InvitationsController: token-guarded edit/update, signs in on accept - InvitationMailer + text/html views - UsersController#create branches on a blank password; #resend_invitation - SetupController stamps the first admin as accepted - migration backfills existing users to created_at
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today an admin has to type a password for every teammate and pass it along out of band. Now they can leave the password field blank and Tally emails an invitation instead.
Flow
UsersController#create— blank password → stash an unusableSecureRandom.base58(24), save,InvitationMailer.invite(user, current_user).deliver_later. A typed password keeps the old behaviour and marks the user active immediately.InvitationsController—GET/PATCH /invitations/:token.User.find_by_token_for!(:invitation, token); the accept sets name + password, stampsinvitation_accepted_at, and starts a session.User—generates_token_for :invitation, expires_in: 7.dayskeyed on[password_salt, invitation_accepted_at], so the link is single-use and dies on acceptance or a later password change.pending_invitationscope +invitation_pending?.POST /users/:id/resend_invitation, admin-only).users.invitation_accepted_atand backfills existing rows tocreated_at;SetupControllerstamps the first admin.Tests — request specs for the invite/accept/expiry/replay paths,
UsersControllerinvite-vs-direct + resend + non-admin guard, and anInvitationMailerspec. Suite 289 green, rubocop clean, brakeman 0.db/structure.sqlregenerated.