Changeset - 12bc5b6057a7
[Not reviewed]
default
0 9 0
Mads Kiilerich - 9 years ago 2016-09-12 17:41:19
madski@unity3d.com
auth: cleanup of EXTERN_TYPE_INTERNAL

Don't set it in top level namespace - it is a weak link between the database
and the actual implementation. Don't make it more than that.

Don't hardcode in that many places that 'internal' is the default - just call
it DEFAULT_AUTH_TYPE.

Don't use it for extern_name - it is only intended for use as extern_type.

Remove unused uses.
9 files changed with 14 insertions and 23 deletions:
0 comments (0 inline, 0 general)
kallithea/__init__.py
Show inline comments
 
@@ -51,8 +51,6 @@ except ImportError:
 
else:
 
    assert False, 'Database rebranding is no longer supported; see README.'
 

	
 
# Users.extern_type and .extern_name value for local users
 
EXTERN_TYPE_INTERNAL = 'internal'
 

	
 
__version__ = '.'.join(str(each) for each in VERSION)
 
__dbversion__ = 31  # defines current db version for migrations
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -35,7 +35,6 @@ from pylons import request, tmpl_context
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea import EXTERN_TYPE_INTERNAL
 
from kallithea.lib import helpers as h
 
from kallithea.lib import auth_modules
 
from kallithea.lib.auth import LoginRequired, NotAnonymous, AuthUser
 
@@ -70,7 +69,6 @@ class MyAccountController(BaseController
 
            h.flash(_("You can't edit this user since it's"
 
                      " crucial for entire application"), category='warning')
 
            raise HTTPFound(location=url('users'))
 
        c.EXTERN_TYPE_INTERNAL = EXTERN_TYPE_INTERNAL
 

	
 
    def _load_my_repos_data(self, watched=False):
 
        if watched:
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -42,7 +42,6 @@ from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, HasPermissionAnyDecorator, \
 
    AuthUser
 
from kallithea.lib import auth_modules
 
from kallithea.lib.auth_modules import auth_internal
 
from kallithea.lib.base import BaseController, render
 
from kallithea.model.api_key import ApiKeyModel
 

	
 
@@ -65,7 +64,6 @@ class UsersController(BaseController):
 
    def __before__(self):
 
        super(UsersController, self).__before__()
 
        c.available_permissions = config['available_permissions']
 
        c.EXTERN_TYPE_INTERNAL = kallithea.EXTERN_TYPE_INTERNAL
 

	
 
    def index(self, format='html'):
 
        c.users_list = User.query().order_by(User.username) \
 
@@ -115,8 +113,8 @@ class UsersController(BaseController):
 
        return render('admin/users/users.html')
 

	
 
    def create(self):
 
        c.default_extern_type = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_type = User.DEFAULT_AUTH_TYPE
 
        c.default_extern_name = ''
 
        user_model = UserModel()
 
        user_form = UserForm()()
 
        try:
 
@@ -144,8 +142,8 @@ class UsersController(BaseController):
 
        raise HTTPFound(location=url('edit_user', id=user.user_id))
 

	
 
    def new(self, format='html'):
 
        c.default_extern_type = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_type = User.DEFAULT_AUTH_TYPE
 
        c.default_extern_name = ''
 
        return render('admin/users/user_add.html')
 

	
 
    def update(self, id):
kallithea/controllers/api/api.py
Show inline comments
 
@@ -30,7 +30,6 @@ 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, HasPermissionAnyDecorator,
 
@@ -620,8 +619,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(EXTERN_TYPE_INTERNAL),
 
                    extern_type=Optional(EXTERN_TYPE_INTERNAL)):
 
                    extern_type=Optional(User.DEFAULT_AUTH_TYPE),
 
                    extern_name=Optional('')):
 
        """
 
        Creates new user. Returns new user object. This command can
 
        be executed only using api_key belonging to user with admin rights.
kallithea/lib/auth_modules/__init__.py
Show inline comments
 
@@ -18,7 +18,6 @@ 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,8 +313,6 @@ def importplugin(plugin):
 
        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:
kallithea/lib/auth_modules/auth_internal.py
Show inline comments
 
@@ -28,7 +28,6 @@ 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
 
@@ -42,7 +41,8 @@ class KallitheaAuthPlugin(auth_modules.K
 

	
 
    @hybrid_property
 
    def name(self):
 
        return EXTERN_TYPE_INTERNAL
 
        # Also found as kallithea.lib.model.db.User.DEFAULT_AUTH_TYPE
 
        return 'internal'
 

	
 
    def settings(self):
 
        return []
kallithea/lib/db_manage.py
Show inline comments
 
@@ -36,7 +36,7 @@ from os.path import dirname
 
import alembic.config
 
import alembic.command
 

	
 
from kallithea import __dbversion__, __py_version__, EXTERN_TYPE_INTERNAL
 
from kallithea import __dbversion__, __py_version__
 
from kallithea.lib.paster_commands.common import ask_ok
 
from kallithea.model.user import UserModel
 
from kallithea.model import init_model
 
@@ -464,7 +464,7 @@ class DbManage(object):
 
        UserModel().create_or_update(username, password, email,
 
                                     firstname=u'Kallithea', lastname=u'Admin',
 
                                     active=True, admin=admin,
 
                                     extern_type=EXTERN_TYPE_INTERNAL)
 
                                     extern_type=User.DEFAULT_AUTH_TYPE)
 

	
 
    def create_default_user(self):
 
        log.info('creating default user')
kallithea/model/db.py
Show inline comments
 
@@ -427,6 +427,8 @@ class User(Base, BaseModel):
 

	
 
    DEFAULT_USER = 'default'
 
    DEFAULT_GRAVATAR_URL = 'https://secure.gravatar.com/avatar/{md5email}?d=identicon&s={size}'
 
    # The name of the default auth type in extern_type, 'internal' lives in auth_internal.py
 
    DEFAULT_AUTH_TYPE = 'internal'
 

	
 
    user_id = Column(Integer(), primary_key=True)
 
    username = Column(String(255), nullable=False, unique=True)
kallithea/model/user.py
Show inline comments
 
@@ -37,7 +37,6 @@ from pylons.i18n.translation import _
 

	
 
from sqlalchemy.exc import DatabaseError
 

	
 
from kallithea import EXTERN_TYPE_INTERNAL
 
from kallithea.lib.utils2 import safe_str, generate_api_key, get_current_authuser
 
from kallithea.lib.caching_query import FromCache
 
from kallithea.model import BaseModel
 
@@ -179,8 +178,8 @@ class UserModel(BaseModel):
 
        import kallithea.lib.helpers as h
 

	
 
        form_data['admin'] = False
 
        form_data['extern_name'] = EXTERN_TYPE_INTERNAL
 
        form_data['extern_type'] = EXTERN_TYPE_INTERNAL
 
        form_data['extern_type'] = User.DEFAULT_AUTH_TYPE
 
        form_data['extern_name'] = ''
 
        new_user = self.create(form_data)
 

	
 
        self.sa.add(new_user)
0 comments (0 inline, 0 general)