Added very basic permission system. #71
[zzz-spline-users.git] / splinext / users / __init__.py
index 0e6f44f..f01995d 100644 (file)
@@ -1,12 +1,12 @@
 from pkg_resources import resource_filename
 
-from pylons import c, session
+from pylons import c, config, session
 
-from spline.lib.plugin import PluginBase
 from spline.lib.plugin import PluginBase, PluginLink, Priority
 import spline.model.meta as meta
 
 import splinext.users.controllers.accounts
+import splinext.users.controllers.admin
 import splinext.users.controllers.users
 from splinext.users import model as users_model
 
@@ -36,6 +36,18 @@ def add_routes_hook(map, *args, **kwargs):
     map.connect('/users/{id}', controller='users', action='profile',
         conditions=dict(function=id_is_numeric))
 
+    # Big-boy admin
+    map.connect('/admin/users/permissions', controller='admin_users', action='permissions')
+
+def monkeypatch_user_hook(*args, **kwargs):
+    """Hook to tell the `User` model who the root user is."""
+    try:
+        users_model.User._root_user_id \
+            = int(config['spline-users.root_user_id'])
+    except KeyError:
+        # No config set; oh well!
+        pass
+
 def check_userid_hook(action, **params):
     """Hook to see if a user is logged in and, if so, stick a user object in
     c.
@@ -61,6 +73,7 @@ class UsersPlugin(PluginBase):
     def controllers(self):
         return dict(
             accounts = splinext.users.controllers.accounts.AccountsController,
+            admin_users = splinext.users.controllers.admin.AdminController,
             users = splinext.users.controllers.users.UsersController,
         )
 
@@ -72,6 +85,7 @@ class UsersPlugin(PluginBase):
     def hooks(self):
         return [
             ('routes_mapping',    Priority.NORMAL,      add_routes_hook),
+            ('after_setup',       Priority.NORMAL,      monkeypatch_user_hook),
             ('before_controller', Priority.VERY_FIRST,  check_userid_hook),
         ]