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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Disables self invite #836

Open
brunoarueira opened this issue Oct 27, 2020 · 6 comments
Open

Feature Request: Disables self invite #836

brunoarueira opened this issue Oct 27, 2020 · 6 comments

Comments

@brunoarueira
Copy link
Contributor

On the project I'm working on, the users will be only invited after certain operations (e.g. create an user record or invite manually through an authenticated area)

I thought this will be a good addition to the project with a simple option like self_invite: false (probably on the model like the invite_for, enabling multiple resources using devise to be enable or disable invitations with this new option) and this will disable the route.

A workaround I've made is to override the controller using the default devise mechanism and override the new action with a redirect to a root path.

Would you accept a pull request for that?

@scambra
Copy link
Owner

scambra commented Nov 20, 2020

Sorry, I'm not sure if I understand your suggestion.

Do you want to use devise invitable to call invite! class method only from some custom controllers, or model callbacks, so you want to disable new and create actions in invitations controller? I can accept a pull request for that.

@scambra
Copy link
Owner

scambra commented Nov 20, 2020

I think another way to do it is defining authenticate_inviter! to raise an exception, redirect or render an error, but if you add that option it could be a cleaner way

@brunoarueira
Copy link
Contributor Author

Yeah, the suggested option will disable actions (new and create) on the invitations controller and avoid any unwanted user to invite himself.

@scambra
Copy link
Owner

scambra commented Nov 23, 2020

Do you think adding authenticate_inviter! method to application controller is good enough, or do you want to send pull request?

If that's enough, you could improve README or add something to wiki, to help others

@brunoarueira
Copy link
Contributor Author

I'll think a bit and return, because at my use case, the invited user needs to be invited by someone which previously sets some parameters and/or relationships.

@ukolovda
Copy link

I define InviteController and rewrote the method invite_resource:

class Users::InvitationsController < Devise::InvitationsController

  private
  def invite_resource
    super do |new_user|
      if new_user == current_user
        new_user.errors.add :email, :taken
      end
    end
  end
end

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

No branches or pull requests

3 participants