Seguir

Did I dream it or there used to exist a Mastodon rake task to create a user with a username in the reserved_username list? Eg: create a user with admin or root as the username

@hugo There used to one "add_user" rake task, don't know if it ignored the reserved username list 🤔

@renatolond there still exists that rake task but it doesn’t ignore the reserved username, I tested it :| no big deal, just wondering if there is a way to do it that doesn’t require code changes

@hugo You could do it from rails console, ignoring validations. But you can only skip all of the validations, not just one :T

@renatolond well, there’s an idea. How do I skip/ignore validations?

@hugo You can do something like:

email = 'x@x.com'
username = 'x'
role = 'none'

u = User.new(email: email, password: SecureRandom.hex, admin: role == 'admin', moderator: role == 'moderator', account_attributes: { username: username })

u.save # try to save to see errors

u.errors # should only contain username reserved error

u.save(validate:false)

@renatolond pretty cool :) always learning. I will test it on my Dev environment. Thank you so much

@renatolond it works :)

just not sure what this does:

admin: role == 'admin', moderator: role == 'moderator',

why do we set:

role = 'none'

and then make role admin + role moderator?

Just curious because I ended up making the user admin via rake just to be sure but just wondering if it was a mistake or what is the reason.

@hugo I stole that from the old task, it means you can change "none" to either "admin" or "moderator" if you by to create the user as one of those, it's using the == to create a true value to either admin or moderator, should've commented that one, sorry!

@renatolond no, no, this is useful for me :)

It makes sense now that I look at it again.

Thank you so much!

Inicie a sessão para participar na conversa
Mastodon (PT)

Mastodon é uma rede social baseada em protocolos abertos da web e software livre e gratuito. É descentralizado como e-mail.