New Auth and general database management functionality in appadmin

296 views
Skip to first unread message

Anthony

unread,
Jun 14, 2013, 1:27:33 PM6/14/13
to
Trunk now includes some new functionality in appadmin to allow specially designated administrative users of an app to manage specific tables in the database.


First, there is /appadmin/manage/auth, which is a special page specifically for managing Auth users, roles, and permissions (see screenshot above). Just create an Auth group that is to be allowed access to this page and specify the "role" of that group in auth.settings.auth_manager_role. Then anyone assigned to that Auth group will have access to the page.

You can also create any number of custom db management pages much like the /appadmin/manage/auth page via the new auth.settings.manager_actions setting, which is a dict of dicts. An example looks like this:

auth.settings.manager_actions = dict(
    db
=dict(role='Admin', heading='Manage Database', tables=db.tables),
    things
=dict(role='Thing Manager', heading='Manage Things', db=other_db,
                tables
=['things', 'stuff', 'more_stuff']),
    content
=dict(role='Content Manager',
                 tables
=[content_db.articles, content_db.recipes, content_db.comments])
)

The keys of the auth.settings.manager_actions dict are URL args that go after /appadmin/manage -- so the above allows /appadmin/manage/db, /appadmin/manage/things, and /appadmin/manage/content.

Each item in auth.settings.manager_actions is a dict with "role", "heading", "tables", and "db" keys:
  • role: Specifies the "role" of the Auth group that should be allowed to access the page.
  • heading: Specifies the heading to appear on the page, though it is optional -- if there is no "heading", it will use 'Manage %s' % request.args(0).replace('_', ' ').title() instead.
  • tables: A list of DAL tables to include on the page. It can be either a list of table names or actual DAL table objects.
  • db: Specifies the DAL object that contains the tables to be managed (you can specify the DAL object itself, or its variable name, which will be looked up in globals()). The "db" key is optional -- if "tables" is a list of DAL table objects, the table objects themselves determine the db; and if "tables" is a list of table names, auth.db will be used if no "db" key is specified (auth.db is the database used for the Auth tables, which is typically the main app database).
Note, access to these pages is controlled by the app's own Auth system, not by the "admin" app (as with the rest of appadmin).

Try it out and let us know if you run into any problems.

Anthony


Anthony

unread,
Jun 14, 2013, 5:36:03 PM6/14/13
to web...@googlegroups.com
One more thing -- you can override the default /appadmin/manage/auth by providing an "auth" key in auth.settings.manager_actions with a custom dict for that action (this makes it possible to specify a custom heading or limit which Auth tables are included). In that case, you'll still get some special Auth related customizations (re-labeling some columns and links to more user-friendly labels, hiding ID columns, setting default sort order, etc.) -- if you don't want those customizations and instead want complete control, then just create a custom manager_action with a name other than "auth".

Anthony

Loïc

unread,
Jul 3, 2013, 3:13:25 AM7/3/13
to web...@googlegroups.com
Hello Anthony,

I have some questions about the new feature you present here :

"Just create an Auth group that is to be allowed access to this page and specify the "role" of that group in auth.settings.auth_manager_role"
I think the correct spelling is auth.settings.manager_group_role, am I right?

"First, there is /appadmin/manage/auth, which is a special page specifically for managing Auth users, roles, and permissions"
When I add
auth.settings.manager_group_role = 'manager'

on my db.py, and the I log in with a "manager user", when I go on /appadmin/manage/auth I can manage all tables in my database, not only users roles and permissions.
Have I missed something?

Thank you

Anthony

unread,
Jul 3, 2013, 9:32:47 AM7/3/13
to web...@googlegroups.com
"Just create an Auth group that is to be allowed access to this page and specify the "role" of that group in auth.settings.auth_manager_role"
I think the correct spelling is auth.settings.manager_group_role, am I right?
 
No, this was changed in trunk, please read the above posts for the details. 
"First, there is /appadmin/manage/auth, which is a special page specifically for managing Auth users, roles, and permissions"
When I add
auth.settings.manager_group_role = 'manager'

on my db.py, and the I log in with a "manager user", when I go on /appadmin/manage/auth I can manage all tables in my database, not only users roles and permissions.
Have I missed something?
Yes, the new functionality is explained above. You'll need the version in trunk for the newer functionality.
 
Anthony

Loïc

unread,
Jul 3, 2013, 9:43:54 AM7/3/13
to web...@googlegroups.com
Sorry I read too fast...
Thank you Anthony

Anthony

unread,
Jul 8, 2013, 6:03:34 PM7/8/13
to
Added one more feature -- you can now pass any arbitrary arguments to smartgrid to control the display of some or all of the tables being managed. To do this, just include a "smartgrid_args" key in the dictionary of the manager action:

auth.settings.manager_actions = dict(
    things
=dict(
        role='Thing Manager', heading='Manage Things', db=other_db,
        tables=['things', 'stuff', 'more_stuff'],
        smartgrid_args=dict(
            DEFAULT
=dict(maxtextlength=50, paginate=30),
            things
=dict(maxtextlength=100, orderby=~db.things.created_on),
            stuff
=dict(editable=False, csv=False)
       
)
   
),
)

smartgrid_args is a dictionary of dictionaries. The top-level keys are the names of tables, and the dictionary associated with each key includes the arguments to be passed to .smartgrid (most of which get passed to .grid) for that table. One of the keys can also be "DEFAULT" -- those arguments are applied to all tables, unless explicitly overridden by the dictionary specific to the table being displayed.

Anthony

Tim Richardson

unread,
Jul 8, 2013, 5:42:33 PM7/8/13
to web...@googlegroups.com
thanks, I'll update the book patch. 

David Marko

unread,
Jul 9, 2013, 2:46:51 AM7/9/13
to web...@googlegroups.com
Hi Anthony, 
can you help me to make it alive in my app, please? I'm using the latest trunk web2py version. I did necessary setup as described above but when I enter the following URL: http://localhost/test_app/appadmin/manage/auth I'm just getting this in browser 'invalid function (appadmin/manage)' .  Is the URL wrong for my 'test_app' application? Is it working for existing applications or only for newly created after this feature has been introduced? 

Loïc

unread,
Jul 9, 2013, 2:50:30 AM7/9/13
to web...@googlegroups.com
Hi David,

In your existing application, did you copy the new appadmin controller new appadmin.html view  from the welcome app?

David Marko

unread,
Jul 9, 2013, 3:04:10 AM7/9/13
to web...@googlegroups.com
Just got it to work, I copied only appadmin.py controller, but also the appadmin.html  and current web2py.js is required ...
Reply all
Reply to author
Forward
0 new messages