diff --git a/kallithea/__init__.py b/kallithea/__init__.py --- a/kallithea/__init__.py +++ b/kallithea/__init__.py @@ -61,6 +61,9 @@ except ImportError: # 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) diff --git a/kallithea/controllers/admin/my_account.py b/kallithea/controllers/admin/my_account.py --- a/kallithea/controllers/admin/my_account.py +++ b/kallithea/controllers/admin/my_account.py @@ -36,6 +36,7 @@ from pylons import request, tmpl_context 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 @@ class MyAccountController(BaseController 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 @@ class MyAccountController(BaseController 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') diff --git a/kallithea/controllers/admin/users.py b/kallithea/controllers/admin/users.py --- a/kallithea/controllers/admin/users.py +++ b/kallithea/controllers/admin/users.py @@ -177,7 +177,7 @@ class UsersController(BaseController): 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 @@ class UsersController(BaseController): 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() diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py +++ b/kallithea/controllers/api/api.py @@ -31,6 +31,7 @@ import traceback 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 @@ class ApiController(JSONRPCController): 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. diff --git a/kallithea/lib/auth_modules/__init__.py b/kallithea/lib/auth_modules/__init__.py --- a/kallithea/lib/auth_modules/__init__.py +++ b/kallithea/lib/auth_modules/__init__.py @@ -18,6 +18,7 @@ Authentication modules 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 @@ def importplugin(plugin): 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) diff --git a/kallithea/lib/auth_modules/auth_internal.py b/kallithea/lib/auth_modules/auth_internal.py --- a/kallithea/lib/auth_modules/auth_internal.py +++ b/kallithea/lib/auth_modules/auth_internal.py @@ -27,11 +27,12 @@ Original author and date, and relevant c 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 @@ class KallitheaAuthPlugin(auth_modules.K @hybrid_property def name(self): - return "internal" + return EXTERN_TYPE_INTERNAL def settings(self): return [] diff --git a/kallithea/lib/db_manage.py b/kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py +++ b/kallithea/lib/db_manage.py @@ -34,8 +34,7 @@ import logging 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 @@ class DbManage(object): 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') diff --git a/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py b/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py --- a/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py +++ b/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py @@ -7,6 +7,7 @@ from sqlalchemy.orm import relation, bac 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 @@ def fixups(models, _SESSION): 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() diff --git a/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py b/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py --- a/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py +++ b/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py @@ -7,6 +7,7 @@ from sqlalchemy.orm import relation, bac 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 @@ def fixups(models, _SESSION): #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() diff --git a/kallithea/model/user.py b/kallithea/model/user.py --- a/kallithea/model/user.py +++ b/kallithea/model/user.py @@ -33,7 +33,7 @@ from pylons.i18n.translation import _ 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 @@ class UserModel(BaseModel): 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) diff --git a/kallithea/templates/admin/my_account/my_account_profile.html b/kallithea/templates/admin/my_account/my_account_profile.html --- a/kallithea/templates/admin/my_account/my_account_profile.html +++ b/kallithea/templates/admin/my_account/my_account_profile.html @@ -20,7 +20,7 @@ ${h.form(url('my_account'), method='post <% readonly = None %> <% disabled = "" %>
- %if c.extern_type != 'internal': + %if c.extern_type != c.EXTERN_TYPE_INTERNAL: <% readonly = "readonly" %> <% disabled = " disabled" %> ${_('Your user is in an external Source of Record; some details cannot be managed here')}. diff --git a/kallithea/templates/admin/users/user_edit_profile.html b/kallithea/templates/admin/users/user_edit_profile.html --- a/kallithea/templates/admin/users/user_edit_profile.html +++ b/kallithea/templates/admin/users/user_edit_profile.html @@ -20,7 +20,7 @@ ${h.form(url('update_user', id=c.user.us <% readonly = None %> <% disabled = "" %>
- %if c.extern_type != 'internal': + %if c.extern_type != c.EXTERN_TYPE_INTERNAL:
<% readonly = "readonly" %> <% disabled = " disabled" %>