User group names based on username instead of id

27 views
Skip to first unread message

Antonio Salazar

unread,
May 4, 2016, 2:48:49 PM5/4/16
to web2py-users
I've disabled user group creation, but now I need user-specific permissions, so I'm going to re-enable it and create the missing user groups. I'd really like the groups to be user_[username] instead of user_[user_id].
Is there an upgrade-friendly way to base the group name on something other than the user id?

I know it's best practice to use the id because it's unique, but in my case, the username is also unique and invariable. I'd bear the slight risk of inconsistency in exchange for human-readable group names.

Niphlod

unread,
May 4, 2016, 3:01:16 PM5/4/16
to web2py-users
from the source it seems that the setting

create_user_groups

which has a default of 

"user_%(id)s"

can be used. in your case it seems that setting it to user_%(username)s should do the trick.

Antonio Salazar

unread,
May 4, 2016, 3:59:13 PM5/4/16
to web...@googlegroups.com
Thank you!

For some reason I was thinking of this setting as a boolean, and figuring how to use a callback to rename the group :/

P.S. for completeness.

In db.py I changed this:
auth.settings.create_user_groups = None

to this
auth.settings.create_user_groups = 'user_%(username)s'

Niphlod

unread,
May 4, 2016, 4:24:50 PM5/4/16
to web2py-users

Antonio Salazar

unread,
May 4, 2016, 4:45:40 PM5/4/16
to web2py-users
I actually read that section two days ago, when the requirements were still being defined. I don't know why I forgot it.

Probably the ominous warning "The creation of the group can be disabled [...] although we do not suggest doing so." got me thinking why and the rest slipped my mind.
Later I found it wasn't so ominous after all: https://groups.google.com/forum/#!msg/web2py/C5BHvXMyq7s/YZ6Gdx78mesJ
Reply all
Reply to author
Forward
0 new messages