Changeset - f5c9018a5cf0
[Not reviewed]
kallithea/__init__.py
Show inline comments
 
@@ -58,12 +58,15 @@ try:
 
except ImportError:
 
    pass
 

	
 
# 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)
 
    if _rev and len(VERSION) > 3:
 
        VERSION += ('%s' % _rev[0],)
 
except ImportError:
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -33,12 +33,13 @@ import formencode
 
from sqlalchemy import func, or_
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url
 
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
 
from kallithea.lib.utils2 import generate_api_key, safe_int
 
from kallithea.lib.compat import json
 
from kallithea.model.db import Repository, PullRequest, PullRequestReviewers, \
 
@@ -67,12 +68,13 @@ class MyAccountController(BaseController
 
    def __load_data(self):
 
        c.user = User.get(self.authuser.user_id)
 
        if c.user.username == User.DEFAULT_USER:
 
            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:
 
            admin = False
 
            repos_list = [x.follows_repository for x in
 
                          Session().query(UserFollowing).filter(
 
@@ -115,13 +117,13 @@ class MyAccountController(BaseController
 
                post_data['password_confirmation'] = ''
 
                form_result = _form.to_python(post_data)
 
                # skip updating those attrs for my account
 
                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')
 

	
 
                UserModel().update(self.authuser.user_id, form_result,
 
                                   skip_attrs=skip_attrs)
 
                h.flash(_('Your account was updated successfully'),
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -174,13 +174,13 @@ class UsersController(BaseController):
 
                                              'email': c.user.email})()
 
        form_result = {}
 
        try:
 
            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')
 

	
 
            user_model.update(id, form_result, skip_attrs=skip_attrs)
 
            usr = form_result['username']
 
            action_logger(self.authuser, 'admin_updated_user:%s' % usr,
 
@@ -242,12 +242,13 @@ class UsersController(BaseController):
 
            h.flash(_("You can't edit this user"), category='warning')
 
            return redirect(url('users'))
 

	
 
        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()
 
        return htmlfill.render(
 
            render('admin/users/user_edit.html'),
 
            defaults=defaults,
kallithea/controllers/api/api.py
Show inline comments
 
@@ -28,12 +28,13 @@ Original author and date, and relevant c
 

	
 
import time
 
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,
 
    HasPermissionAnyDecorator, HasPermissionAnyApi, HasRepoPermissionAnyApi,
 
    HasRepoGroupPermissionAnyApi, HasUserGroupPermissionAny)
 
from kallithea.lib.utils import map_groups, repo2db_mapper
 
@@ -617,14 +618,14 @@ class ApiController(JSONRPCController):
 
        return result
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    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.
 

	
 
        :param apiuser: filled automatically from apikey
 
        :type apiuser: AuthUser
kallithea/lib/auth_modules/__init__.py
Show inline comments
 
@@ -15,12 +15,13 @@
 
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
 
from kallithea.lib.auth import PasswordGenerator
 
from kallithea.model.user import UserModel
 
from kallithea.model.db import Setting, User, UserGroup
 
@@ -311,12 +312,19 @@ def importplugin(plugin):
 
    raises:
 
        AttributeError -- no KallitheaAuthPlugin class in the module
 
        TypeError -- if the KallitheaAuthPlugin is not a subclass of ours KallitheaAuthPluginBase
 
        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)
 
    except (ImportError, TypeError):
 
        log.error(traceback.format_exc())
 
        # TODO: make this more error prone, if by some accident we screw up
kallithea/lib/auth_modules/auth_internal.py
Show inline comments
 
@@ -24,27 +24,28 @@ Original author and date, and relevant c
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 

	
 
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__)
 

	
 

	
 
class KallitheaAuthPlugin(auth_modules.KallitheaAuthPluginBase):
 
    def __init__(self):
 
        pass
 

	
 
    @hybrid_property
 
    def name(self):
 
        return "internal"
 
        return EXTERN_TYPE_INTERNAL
 

	
 
    def settings(self):
 
        return []
 

	
 
    def user_activation_state(self):
 
        def_user_perms = User.get_default_user().AuthUser.permissions['global']
kallithea/lib/db_manage.py
Show inline comments
 
@@ -31,14 +31,13 @@ import sys
 
import time
 
import uuid
 
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
 
from kallithea.model.db import User, Permission, Ui, \
 
    Setting, UserToPerm, DbMigrateVersion, RepoGroup, \
 
    UserRepoGroupToPerm, CacheInvalidation, UserGroup, Repository
 
@@ -540,13 +539,13 @@ class DbManage(object):
 

	
 
    def create_user(self, username, password, email='', admin=False):
 
        log.info('creating user %s' % username)
 
        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')
 
        # create default user for handling default permissions.
 
        user = UserModel().create_or_update(username=User.DEFAULT_USER,
 
                                            password=str(uuid.uuid1())[:20],
kallithea/lib/dbmigrate/versions/016_version_2_0_0.py
Show inline comments
 
@@ -4,12 +4,13 @@ import datetime
 
from sqlalchemy import *
 
from sqlalchemy.exc import DatabaseError
 
from sqlalchemy.orm import relation, backref, class_mapper, joinedload
 
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.model.meta import Base
 
from kallithea.model import meta
 
from kallithea.lib.dbmigrate.versions import _reset_base, notify
 
@@ -60,10 +61,10 @@ def fixups(models, _SESSION):
 
    for usr in models.User.get_all():
 
        ldap_dn = usr.ldap_dn
 
        if ldap_dn:
 
            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()
kallithea/lib/dbmigrate/versions/020_version_2_0_1.py
Show inline comments
 
@@ -4,12 +4,13 @@ import datetime
 
from sqlalchemy import *
 
from sqlalchemy.exc import DatabaseError
 
from sqlalchemy.orm import relation, backref, class_mapper, joinedload
 
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
 

	
 
from kallithea.model.meta import Base
 
from kallithea.model import meta
 
@@ -36,10 +37,10 @@ def downgrade(migrate_engine):
 

	
 

	
 
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()
kallithea/model/user.py
Show inline comments
 
@@ -30,13 +30,13 @@ import logging
 
import traceback
 
from pylons import url
 
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
 
from kallithea.model.db import User, UserToPerm, Notification, \
 
    UserEmailMap, UserIpMap
 
from kallithea.lib.exceptions import DefaultUserException, \
 
@@ -184,14 +184,14 @@ class UserModel(BaseModel):
 

	
 
    def create_registration(self, form_data):
 
        from kallithea.model.notification import NotificationModel
 

	
 
        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)
 
            self.sa.flush()
 

	
 
            # notification to admins
kallithea/templates/admin/my_account/my_account_profile.html
Show inline comments
 
@@ -17,13 +17,13 @@ ${h.form(url('my_account'), method='post
 
           </div>
 
         </div>
 

	
 
        <% 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>
 
           %endif
 
             <div class="field">
 
                <div class="label">
kallithea/templates/admin/users/user_edit_profile.html
Show inline comments
 
@@ -17,13 +17,13 @@ ${h.form(url('update_user', id=c.user.us
 
                %endif
 
           </div>
 
        </div>
 
        <% 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" %>
 
               <strong>${_('This user is in an external Source of Record (%s); some details cannot be managed here.' % c.extern_type)}.</strong>
 
             </div>
 
            %endif
0 comments (0 inline, 0 general)