I have a Rails app with Clearance and Pundit and I'm trying to create "teams" where the "Team Leader" can invite other users to join their team. I would like to do something similar to devise_invitable, but with Clearance.
Here is my plan for how this might work:
Users that sign up to the site through the signup form are automatically assigned a unique Team ID and become the "Team Lead." They don't see this ID on the form. (Another way this could be done is they create a unique team name that is saved on sign up.) Is the best way to do this to create a before_filter for assigning the team ID and Team Leader on sign up?
Team IDs or names would be unique and each User can only belong to one team. Association would look like this:
Team
has_many :users
User
belongs_to :team
Once this "Team Leader" account is created, this user can invite other users to join the team by filling out a User#new form similar to the Clearance sign up form (name, email, etc.) This form would create the User and assign them to the Team Leader's team. They could be assigned a random password to give to Clearance so that the new user passes the validation.
Once a user has been created by the Team Leader they are saved in the database with the randomly generated password and a Mailer is sent to the invited user that is similar to the standard Clearance password reset Mailer. It just gives them a notification that they have been invited to the team and provides a link to reset their password and then log in. It's basically the Clearance password reset Mailer with different copy.
Is this a decent strategy or is there a more widely used pattern I'm missing for solving this problem with Clearance and Pundit? I've never done anything like this with Rails, so I have no idea if this is a ducted-tape way to use Clearance.