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 maybe @dansup knows something about this, as he created reserved spots for pixelfed. I dunno. It's the only one who comes to mind. :blobpeek:

@eloisa @dansup Well, this is a Mastodon specific thing and I am starting to believe that I really dreamed it :P or just got confused while reading something in the past.

@hugo ok, maybe @kemonine knows something!

I'll just keep dialing until we find someone who knows if it's a dream or not. XD

@eloisa @kemonine eheheh! It's no big deal, just something that some admins asked me a couple of times and I never was able to do.

@hugo @eloisa further down the thread is what I remember doing back in the early 2.0 days ;)

@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

@hugo You can do something like:

email = ''
username = 'x'
role = 'none'

u = email, password: SecureRandom.hex, admin: role == 'admin', moderator: role == 'moderator', account_attributes: { username: username }) # try to save to see errors

u.errors # should only contain username reserved error

@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) é uma instância do universo Mastodon que pretende ser uma comunidade de Portugueses no Fediverso.

Lembramos que isto é um projecto feito da boa vontade e não existem garantias de funcionamento.

É obrigatória a leitura e aceitação das regras antes de participar.