In this commit I made it so that each deployment can have custom settings for
authortilly-Q <nattilypigeonfowl@gmail.com>
Fri, 29 Nov 2013 19:29:56 +0000 (14:29 -0500)
committertilly-Q <nattilypigeonfowl@gmail.com>
Mon, 28 Apr 2014 20:37:46 +0000 (16:37 -0400)
which privileges are given to users when they are intiated. These settings are
modified in mediagoblin.ini.

mediagoblin.ini
mediagoblin/auth/__init__.py
mediagoblin/auth/tools.py
mediagoblin/config_spec.ini

index fe9d5cd2942d9d545c395ece888b653ae50a6d3e..216cfc439adee550a346a77d5e366a046b6d99cc 100644 (file)
@@ -35,6 +35,7 @@ allow_reporting = true
 ## If you want the terms of service displayed, you can uncomment this
 # show_tos = true
 
+user_privilege_scheme= "uploader,commenter,reporter"
 [storage:queuestore]
 base_dir = %(here)s/user_dev/media/queue
 
index be5d0eede22d204f76ade4119aa94ea53d3b6826..f518a09d5ed9a75d9c42eee73d20accfe77a21a4 100644 (file)
@@ -25,7 +25,6 @@ def create_user(register_form):
     results = hook_runall("auth_create_user", register_form)
     return results[0]
 
-
 def extra_validation(register_form):
     from mediagoblin.auth.tools import basic_extra_validation
 
index 88716e1c0fc0a6e5333e681104805172b41efefc..191a2b9d32aa1f50e604d8fb3b7a66f9488da373 100644 (file)
@@ -132,11 +132,7 @@ def register_user(request, register_form):
         user = auth.create_user(register_form)
 
         # give the user the default privileges
-        default_privileges = [
-            Privilege.query.filter(Privilege.privilege_name==u'commenter').first(),
-            Privilege.query.filter(Privilege.privilege_name==u'uploader').first(),
-            Privilege.query.filter(Privilege.privilege_name==u'reporter').first()]
-        user.all_privileges += default_privileges
+        user.all_privileges += get_default_privileges(user)
         user.save()
 
         # log the user in
@@ -151,6 +147,14 @@ def register_user(request, register_form):
 
     return None
 
+def get_default_privileges(user):
+    instance_privilege_scheme = mg_globals.app_config['user_privilege_scheme']
+    default_privileges = [Privilege.query.filter(
+        Privilege.privilege_name==privilege_name).first() 
+        for privilege_name in instance_privilege_scheme.split(',')]
+    default_privileges = [privilege for privilege in default_privileges if not privilege == None]
+
+    return default_privileges
 
 def check_login_simple(username, password):
     user = auth.get_user(username=username)
index cc1ac6374b20f0930d63e6f8ac088c04aa27339d..a29b481e7031b1fe77331d1f1e5b15f6f5e0f60d 100644 (file)
@@ -89,6 +89,9 @@ upload_limit = integer(default=None)
 # Max file size (in Mb)
 max_file_size = integer(default=None)
 
+# Privilege scheme
+user_privilege_scheme = string(default="")
+
 [jinja2]
 # Jinja2 supports more directives than the minimum required by mediagoblin. 
 # This setting allows users creating custom templates to specify a list of