User group names based on username instead of id

已查看 27 次
跳至第一个未读帖子

Antonio Salazar

未读,
2016年5月4日 14:48:492016/5/4
收件人 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

未读,
2016年5月4日 15:01:162016/5/4
收件人 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

未读,
2016年5月4日 15:59:132016/5/4
收件人 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

未读,
2016年5月4日 16:24:502016/5/4
收件人 web2py-users

Antonio Salazar

未读,
2016年5月4日 16:45:402016/5/4
收件人 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
回复全部
回复作者
转发
0 个新帖子