That's pretty close to what I did.  Since my groups are created once
and never changed I did one check to see if there are ANY groups
created.  If not, I create the ones I care about:

if not db(db.auth_group).count():
    db.auth_group.insert(role='root',description='Exactly what you
think it does')
    db.auth_group.insert(role='super',description='Supervisor access
for team manager')
    db.auth_group.insert(role='user',description='Normal user')

This is in its own file in the "models" section.  It is executed after
the tables are created.  (Model files are executed in alphabetical
order, if you didn't know...)

-- Joe B.


On Apr 1, 11:22 am, Mike <m.she...@gmail.com> wrote:
> Nevermind. I thought there was a builtin web2py way for this but I
> just did this instead (after sifting more through the groups):
>
> def groupadd(check_group):
>     if not db(db.auth_group.role==check_group).count():
>      db.auth_group.insert(role=check_group)
>
> groupadd('Admins')
> groupadd('Maintenance Users')
> groupadd('Download Users')
>
> auth.settings.register_onaccept=lambda form:
> auth.add_membership(auth.id_group('Download Users'),form.vars.id)
> ----------------------------------------------------------------------------------------------
>
> On Apr 1, 12:06 pm, Mike <m.she...@gmail.com> wrote:
>
>
>
>
>
>
>
> > DISCLAIMER: very new to web2py, read book and building first app...
>
> > I'm having some brain cramps trying to add some default groups.
> > Basically I need some default groups set-up when I rollout my
> > application, like Admins, End-Users, Management - when users register
> > one of us will manually filter them into the right group (this is fine
> > for our environment). What's the best way to do that? I just made some
> > add_group lines in my model but it keeps recreating the group role on
> > every launch and I got a bunch of duplicates.
>
> > Thanks in Advance

Reply via email to