You don't need to override Devise's RegistrationsController
for what you're trying to do.
If you want admins to be able to create users that have an arbitrary role set, you could simply use your own controller. Devise still makes it easy to create a user yourself, so you'll just have to make a controller handling this. Of course, don't forget to protect it using Pundit so only admins can use this functionality.
This approach still works if you use the Confirmable
module. As no confirmation e-mail will be sent on user creation, though, you'll either have to call user.confirm!
after saving the model to immediately unlock the account, or manually send the confirmation e-mail using user.send_confirmation_instructions
.
Edit:
This Pundit policy may or may not work for what you're trying to do. You will have to override the create
action of Devise's RegistrationsController
here in order to use Pundit's authorize
method. For dryness' sake, you should also move the roles list elsewhere, perhaps into the model.
class UserPolicy < Struct.new(:current_user, :target_user)
def create?
registration_roles.include?(target_user.role) if current_user.nil?
end
private
def registration_roles
%w(RED BLU Spectator)
end
end