changeset 4222:f5c9018a5cf0 kallithea-2.2.5-rebrand

db: introduce EXTERN_TYPE_INTERNAL for Users.extern_type and .extern_name value for auth type for internal users
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:08:37 -0400
parents 5b72a0dd966d
children 400fbab35389
files kallithea/__init__.py kallithea/controllers/admin/my_account.py kallithea/controllers/admin/users.py kallithea/controllers/api/api.py kallithea/lib/auth_modules/__init__.py kallithea/lib/auth_modules/auth_internal.py kallithea/lib/db_manage.py kallithea/lib/dbmigrate/versions/016_version_2_0_0.py kallithea/lib/dbmigrate/versions/020_version_2_0_1.py kallithea/model/user.py kallithea/templates/admin/my_account/my_account_profile.html kallithea/templates/admin/users/user_edit_profile.html
diffstat 12 files changed, 35 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/__init__.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/__init__.py	Wed Jul 02 19:08:37 2014 -0400
@@ -61,6 +61,9 @@
 # Prefix for the ui and settings table names
 DB_PREFIX = (BRAND + "_") if BRAND != "kallithea" else ""
 
+# Users.extern_type and .extern_name value for local users
+EXTERN_TYPE_INTERNAL = BRAND if BRAND != 'kallithea' else 'internal'
+
 try:
     from kallithea.lib import get_current_revision
     _rev = get_current_revision(quiet=True)
--- a/kallithea/controllers/admin/my_account.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/controllers/admin/my_account.py	Wed Jul 02 19:08:37 2014 -0400
@@ -36,6 +36,7 @@
 from pylons.controllers.util import redirect
 from pylons.i18n.translation import _
 
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib import helpers as h
 from kallithea.lib.auth import LoginRequired, NotAnonymous, AuthUser
 from kallithea.lib.base import BaseController, render
@@ -70,6 +71,7 @@
             h.flash(_("You can't edit this user since it's"
                       " crucial for entire application"), category='warning')
             return redirect(url('users'))
+        c.EXTERN_TYPE_INTERNAL = EXTERN_TYPE_INTERNAL
 
     def _load_my_repos_data(self, watched=False):
         if watched:
@@ -118,7 +120,7 @@
                 skip_attrs = ['admin', 'active', 'extern_type', 'extern_name',
                               'new_password', 'password_confirmation']
                 #TODO: plugin should define if username can be updated
-                if c.extern_type != "internal":
+                if c.extern_type != EXTERN_TYPE_INTERNAL:
                     # forbid updating username for external accounts
                     skip_attrs.append('username')
 
--- a/kallithea/controllers/admin/users.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/controllers/admin/users.py	Wed Jul 02 19:08:37 2014 -0400
@@ -177,7 +177,7 @@
             form_result = _form.to_python(dict(request.POST))
             skip_attrs = ['extern_type', 'extern_name']
             #TODO: plugin should define if username can be updated
-            if c.extern_type != "internal":
+            if c.extern_type != kallithea.EXTERN_TYPE_INTERNAL:
                 # forbid updating username for external accounts
                 skip_attrs.append('username')
 
@@ -245,6 +245,7 @@
         c.active = 'profile'
         c.extern_type = c.user.extern_type
         c.extern_name = c.user.extern_name
+        c.EXTERN_TYPE_INTERNAL = kallithea.EXTERN_TYPE_INTERNAL
         c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
 
         defaults = c.user.get_dict()
--- a/kallithea/controllers/api/api.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/controllers/api/api.py	Wed Jul 02 19:08:37 2014 -0400
@@ -31,6 +31,7 @@
 import logging
 from sqlalchemy import or_
 
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.controllers.api import JSONRPCController, JSONRPCError
 from kallithea.lib.auth import (
     PasswordGenerator, AuthUser, HasPermissionAllDecorator,
@@ -620,8 +621,8 @@
     def create_user(self, apiuser, username, email, password=Optional(''),
                     firstname=Optional(''), lastname=Optional(''),
                     active=Optional(True), admin=Optional(False),
-                    extern_name=Optional('internal'),
-                    extern_type=Optional('internal')):
+                    extern_name=Optional(EXTERN_TYPE_INTERNAL),
+                    extern_type=Optional(EXTERN_TYPE_INTERNAL)):
         """
         Creates new user. Returns new user object. This command can
         be executed only using api_key belonging to user with admin rights.
--- a/kallithea/lib/auth_modules/__init__.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/lib/auth_modules/__init__.py	Wed Jul 02 19:08:37 2014 -0400
@@ -18,6 +18,7 @@
 import logging
 import traceback
 
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib.compat import importlib
 from kallithea.lib.utils2 import str2bool
 from kallithea.lib.compat import formatted_json, hybrid_property
@@ -314,6 +315,13 @@
         ImportError -- if we couldn't import the plugin at all
     """
     log.debug("Importing %s" % plugin)
+    if not plugin.startswith(u'kallithea.lib.auth_modules.auth_'):
+        parts = plugin.split(u'.lib.auth_modules.auth_', 1)
+        if len(parts) == 2:
+            _module, pn = parts
+            if pn == EXTERN_TYPE_INTERNAL:
+                pn = "internal"
+            plugin = u'kallithea.lib.auth_modules.auth_' + pn
     PLUGIN_CLASS_NAME = "KallitheaAuthPlugin"
     try:
         module = importlib.import_module(plugin)
--- a/kallithea/lib/auth_modules/auth_internal.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/lib/auth_modules/auth_internal.py	Wed Jul 02 19:08:37 2014 -0400
@@ -27,11 +27,12 @@
 
 
 import logging
+
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib import auth_modules
 from kallithea.lib.compat import formatted_json, hybrid_property
 from kallithea.model.db import User
 
-
 log = logging.getLogger(__name__)
 
 
@@ -41,7 +42,7 @@
 
     @hybrid_property
     def name(self):
-        return "internal"
+        return EXTERN_TYPE_INTERNAL
 
     def settings(self):
         return []
--- a/kallithea/lib/db_manage.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/lib/db_manage.py	Wed Jul 02 19:08:37 2014 -0400
@@ -34,8 +34,7 @@
 from os.path import dirname as dn, join as jn
 import datetime
 
-from kallithea import __dbversion__, __py_version__
-
+from kallithea import __dbversion__, __py_version__, EXTERN_TYPE_INTERNAL
 from kallithea.model.user import UserModel
 from kallithea.lib.utils import ask_ok
 from kallithea.model import init_model
@@ -543,7 +542,7 @@
         UserModel().create_or_update(username, password, email,
                                      firstname='Kallithea', lastname='Admin',
                                      active=True, admin=admin,
-                                     extern_type="internal")
+                                     extern_type=EXTERN_TYPE_INTERNAL)
 
     def create_default_user(self):
         log.info('creating default user')
--- a/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py	Wed Jul 02 19:08:37 2014 -0400
@@ -7,6 +7,7 @@
 from sqlalchemy.orm.session import Session
 from sqlalchemy.ext.declarative import declarative_base
 
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib.dbmigrate.migrate import *
 from kallithea.lib.dbmigrate.migrate.changeset import *
 
@@ -63,7 +64,7 @@
             usr.extern_name = ldap_dn
             usr.extern_type = 'ldap'
         else:
-            usr.extern_name = 'internal'
-            usr.extern_type = 'internal'
+            usr.extern_name = EXTERN_TYPE_INTERNAL
+            usr.extern_type = EXTERN_TYPE_INTERNAL
         _SESSION().add(usr)
         _SESSION().commit()
--- a/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py	Wed Jul 02 19:08:37 2014 -0400
@@ -7,6 +7,7 @@
 from sqlalchemy.orm.session import Session
 from sqlalchemy.ext.declarative import declarative_base
 
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib.dbmigrate.migrate import *
 from kallithea.lib.dbmigrate.migrate.changeset import *
 from kallithea.lib.utils2 import str2bool
@@ -39,7 +40,7 @@
     #fix all empty extern type users to default 'internal'
     for usr in models.User.query().all():
         if not usr.extern_name:
-            usr.extern_name = 'internal'
-            usr.extern_type = 'internal'
+            usr.extern_name = EXTERN_TYPE_INTERNAL
+            usr.extern_type = EXTERN_TYPE_INTERNAL
             _SESSION().add(usr)
             _SESSION().commit()
--- a/kallithea/model/user.py	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/model/user.py	Wed Jul 02 19:08:37 2014 -0400
@@ -33,7 +33,7 @@
 
 from sqlalchemy.exc import DatabaseError
 
-
+from kallithea import EXTERN_TYPE_INTERNAL
 from kallithea.lib.utils2 import safe_unicode, generate_api_key, get_current_authuser
 from kallithea.lib.caching_query import FromCache
 from kallithea.model import BaseModel
@@ -187,8 +187,8 @@
 
         try:
             form_data['admin'] = False
-            form_data['extern_name'] = 'internal'
-            form_data['extern_type'] = 'internal'
+            form_data['extern_name'] = EXTERN_TYPE_INTERNAL
+            form_data['extern_type'] = EXTERN_TYPE_INTERNAL
             new_user = self.create(form_data)
 
             self.sa.add(new_user)
--- a/kallithea/templates/admin/my_account/my_account_profile.html	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/templates/admin/my_account/my_account_profile.html	Wed Jul 02 19:08:37 2014 -0400
@@ -20,7 +20,7 @@
         <% readonly = None %>
         <% disabled = "" %>
         <div class="fields">
-           %if c.extern_type != 'internal':
+           %if c.extern_type != c.EXTERN_TYPE_INTERNAL:
                 <% readonly = "readonly" %>
                 <% disabled = " disabled" %>
                 <strong>${_('Your user is in an external Source of Record; some details cannot be managed here')}.</strong>
--- a/kallithea/templates/admin/users/user_edit_profile.html	Wed Jul 02 19:08:37 2014 -0400
+++ b/kallithea/templates/admin/users/user_edit_profile.html	Wed Jul 02 19:08:37 2014 -0400
@@ -20,7 +20,7 @@
         <% readonly = None %>
         <% disabled = "" %>
         <div class="fields">
-            %if c.extern_type != 'internal':
+            %if c.extern_type != c.EXTERN_TYPE_INTERNAL:
              <div class="field">
                <% readonly = "readonly" %>
                <% disabled = " disabled" %>