Changeset - de26de99ac5b
kallithea/controllers/admin/auth_settings.py
Show inline comments
 
@@ -50,25 +50,25 @@ class AuthSettingsController(BaseControl
 
    @HasPermissionAllDecorator('hg.admin')
 
    def __before__(self):
 
        super(AuthSettingsController, self).__before__()
 

	
 
    def __load_defaults(self):
 
        c.available_plugins = [
 
            'kallithea.lib.auth_modules.auth_rhodecode',
 
            'kallithea.lib.auth_modules.auth_internal',
 
            'kallithea.lib.auth_modules.auth_container',
 
            'kallithea.lib.auth_modules.auth_ldap',
 
            'kallithea.lib.auth_modules.auth_crowd',
 
        ]
 
        c.enabled_plugins = Setting.get_auth_plugins()
 

	
 
    def index(self, defaults=None, errors=None, prefix_error=False):
 
        self.__load_defaults()
 
        _defaults = {}
 
        # default plugins loaded
 
        formglobals = {
 
            "auth_plugins": ["kallithea.lib.auth_modules.auth_rhodecode"]
 
            "auth_plugins": ["kallithea.lib.auth_modules.auth_internal"]
 
        }
 
        formglobals.update(Setting.get_auth_settings())
 
        formglobals["plugin_settings"] = {}
 
        formglobals["auth_plugins_shortnames"] = {}
 
        _defaults["auth_plugins"] = formglobals["auth_plugins"]
 

	
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -113,13 +113,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 != "rhodecode":
 
                if c.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
 
@@ -37,13 +37,13 @@ from sqlalchemy.sql.expression import fu
 
import kallithea
 
from kallithea.lib.exceptions import DefaultUserException, \
 
    UserOwnsReposException, UserCreationError
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, HasPermissionAllDecorator, \
 
    AuthUser, generate_api_key
 
import kallithea.lib.auth_modules.auth_rhodecode
 
import kallithea.lib.auth_modules.auth_internal
 
from kallithea.lib import auth_modules
 
from kallithea.lib.base import BaseController, render
 
from kallithea.model.api_key import ApiKeyModel
 

	
 
from kallithea.model.db import User, UserEmailMap, UserIpMap, UserToPerm
 
from kallithea.model.forms import UserForm, CustomDefaultPermissionsForm
 
@@ -118,13 +118,13 @@ class UsersController(BaseController):
 

	
 
        return render('admin/users/users.html')
 

	
 
    def create(self):
 
        """POST /users: Create a new item"""
 
        # url('users')
 
        c.default_extern_type = auth_modules.auth_rhodecode.RhodeCodeAuthPlugin.name
 
        c.default_extern_type = auth_modules.auth_internal.RhodeCodeAuthPlugin.name
 
        user_model = UserModel()
 
        user_form = UserForm()()
 
        try:
 
            form_result = user_form.to_python(dict(request.POST))
 
            user_model.create(form_result)
 
            usr = form_result['username']
 
@@ -148,13 +148,13 @@ class UsersController(BaseController):
 
                    % request.POST.get('username'), category='error')
 
        return redirect(url('users'))
 

	
 
    def new(self, format='html'):
 
        """GET /users/new: Form to create a new item"""
 
        # url('new_user')
 
        c.default_extern_type = auth_modules.auth_rhodecode.RhodeCodeAuthPlugin.name
 
        c.default_extern_type = auth_modules.auth_internal.RhodeCodeAuthPlugin.name
 
        return render('admin/users/user_add.html')
 

	
 
    def update(self, id):
 
        """PUT /users/id: Update an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="PUT" />
 
@@ -172,13 +172,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 != "rhodecode":
 
            if c.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,
kallithea/controllers/api/api.py
Show inline comments
 
@@ -615,14 +615,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('rhodecode'),
 
                    extern_type=Optional('rhodecode')):
 
                    extern_name=Optional('internal'),
 
                    extern_type=Optional('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
 
@@ -302,13 +302,13 @@ class RhodeCodeExternalAuthPlugin(RhodeC
 
        return auth
 

	
 

	
 
def importplugin(plugin):
 
    """
 
    Imports and returns the authentication plugin in the module named by plugin
 
    (e.g., plugin='kallithea.lib.auth_modules.auth_rhodecode'). Returns the
 
    (e.g., plugin='kallithea.lib.auth_modules.auth_internal'). Returns the
 
    RhodeCodeAuthPluginBase subclass on success, raises exceptions on failure.
 

	
 
    raises:
 
        AttributeError -- no RhodeCodeAuthPlugin class in the module
 
        TypeError -- if the RhodeCodeAuthPlugin is not a subclass of ours RhodeCodeAuthPluginBase
 
        ImportError -- if we couldn't import the plugin at all
kallithea/lib/auth_modules/auth_internal.py
Show inline comments
 
file renamed from kallithea/lib/auth_modules/auth_rhodecode.py to kallithea/lib/auth_modules/auth_internal.py
 
@@ -9,13 +9,13 @@
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""
 
kallithea.lib.auth_modules.auth_rhodecode
 
kallithea.lib.auth_modules.auth_internal
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
RhodeCode authentication plugin for built in internal auth
 

	
 
:created_on: Created on Nov 17, 2012
 
:author: marcink
 
@@ -36,13 +36,13 @@ log = logging.getLogger(__name__)
 
class RhodeCodeAuthPlugin(auth_modules.RhodeCodeAuthPluginBase):
 
    def __init__(self):
 
        pass
 

	
 
    @hybrid_property
 
    def name(self):
 
        return "rhodecode"
 
        return "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
 
@@ -371,14 +371,14 @@ class DbManage(object):
 
        """
 
        Create default auth plugin settings, and make it active
 

	
 
        :param skip_existing:
 
        """
 

	
 
        for k, v, t in [('auth_plugins', 'kallithea.lib.auth_modules.auth_rhodecode', 'list'),
 
                     ('auth_rhodecode_enabled', 'True', 'bool')]:
 
        for k, v, t in [('auth_plugins', 'kallithea.lib.auth_modules.auth_internal', 'list'),
 
                     ('auth_internal_enabled', 'True', 'bool')]:
 
            if skip_existing and Setting.get_by_name(k) != None:
 
                log.debug('Skipping option %s' % k)
 
                continue
 
            setting = Setting(k, v, t)
 
            self.sa.add(setting)
 

	
 
@@ -538,13 +538,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='RhodeCode', lastname='Admin',
 
                                     active=True, admin=admin,
 
                                     extern_type="rhodecode")
 
                                     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
 
@@ -60,10 +60,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 = 'rhodecode'
 
            usr.extern_type = 'rhodecode'
 
            usr.extern_name = 'internal'
 
            usr.extern_type = 'internal'
 
        _SESSION().add(usr)
 
        _SESSION().commit()
kallithea/lib/dbmigrate/versions/018_version_2_0_0.py
Show inline comments
 
@@ -34,23 +34,23 @@ def downgrade(migrate_engine):
 
    meta = MetaData()
 
    meta.bind = migrate_engine
 

	
 

	
 
def fixups(models, _SESSION):
 
    notify('Fixing default auth modules')
 
    plugins = 'kallithea.lib.auth_modules.auth_rhodecode'
 
    plugins = 'kallithea.lib.auth_modules.auth_internal'
 
    opts = []
 
    ldap_enabled = str2bool(getattr(
 
        models.Setting.get_by_name('ldap_active'),
 
        'app_settings_value', False))
 
    if ldap_enabled:
 
        plugins += ',kallithea.lib.auth_modules.auth_ldap'
 
        opts.append(('auth_ldap_enabled', 'True', 'bool'))
 

	
 
    opts.append(('auth_plugins', plugins, 'list'),)
 
    opts.append(('auth_rhodecode_enabled', 'True', 'bool'))
 
    opts.append(('auth_internal_enabled', 'True', 'bool'))
 

	
 
    for name, default, type_ in opts:
 
        setting = models.Setting.get_by_name(name)
 
        if not setting:
 
            # if we don't have this option create it
 
            setting = models.Setting(name, default, type_)
kallithea/lib/dbmigrate/versions/020_version_2_0_1.py
Show inline comments
 
@@ -33,13 +33,13 @@ def upgrade(migrate_engine):
 
def downgrade(migrate_engine):
 
    meta = MetaData()
 
    meta.bind = migrate_engine
 

	
 

	
 
def fixups(models, _SESSION):
 
    #fix all empty extern type users to default 'rhodecode'
 
    #fix all empty extern type users to default 'internal'
 
    for usr in models.User.query().all():
 
        if not usr.extern_name:
 
            usr.extern_name = 'rhodecode'
 
            usr.extern_type = 'rhodecode'
 
            usr.extern_name = 'internal'
 
            usr.extern_type = 'internal'
 
            _SESSION().add(usr)
 
            _SESSION().commit()
kallithea/model/user.py
Show inline comments
 
@@ -182,14 +182,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'] = 'rhodecode'
 
            form_data['extern_type'] = 'rhodecode'
 
            form_data['extern_name'] = 'internal'
 
            form_data['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 != 'rhodecode':
 
           %if 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 != 'rhodecode':
 
            %if 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
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -615,13 +615,13 @@ class BaseTestApi(object):
 
    def test_api_create_user_with_extern_name(self):
 
        username = 'test_new_api_user_passwordless'
 
        email = username + "@foo.com"
 

	
 
        id_, params = _build_data(self.apikey, 'create_user',
 
                                  username=username,
 
                                  email=email, extern_name='rhodecode')
 
                                  email=email, extern_name='internal')
 
        response = api_call(self, params)
 

	
 
        usr = UserModel().get_by_username(username)
 
        ret = dict(
 
            msg='created new user `%s`' % username,
 
            user=jsonify(usr.get_api_data())
kallithea/tests/fixture.py
Show inline comments
 
@@ -107,13 +107,13 @@ class Fixture(object):
 
            password='qweqwe',
 
            email='%s+test@example.com' % name,
 
            firstname='TestUser',
 
            lastname='Test',
 
            active=True,
 
            admin=False,
 
            extern_type='rhodecode',
 
            extern_type='internal',
 
            extern_name=None
 
        )
 
        defs.update(custom)
 

	
 
        return defs
 

	
kallithea/tests/functional/test_admin_auth_settings.py
Show inline comments
 
@@ -23,13 +23,13 @@ class TestAuthSettingsController(TestCon
 

	
 
    def test_ldap_save_settings(self):
 
        self.log_user()
 
        if ldap_lib_installed:
 
            raise SkipTest('skipping due to missing ldap lib')
 

	
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_rhodecode,kallithea.lib.auth_modules.auth_ldap')
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
 
        params.update({'auth_ldap_host': u'dc.example.com',
 
                       'auth_ldap_port': '999',
 
                       'auth_ldap_tls_kind': 'PLAIN',
 
                       'auth_ldap_tls_reqcert': 'NEVER',
 
                       'auth_ldap_dn_user': 'test_user',
 
                       'auth_ldap_dn_pass': 'test_pass',
 
@@ -53,13 +53,13 @@ class TestAuthSettingsController(TestCon
 

	
 
    def test_ldap_error_form_wrong_port_number(self):
 
        self.log_user()
 
        if ldap_lib_installed:
 
            raise SkipTest('skipping due to missing ldap lib')
 

	
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_rhodecode,kallithea.lib.auth_modules.auth_ldap')
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
 
        params.update({'auth_ldap_host': '',
 
                       'auth_ldap_port': 'i-should-be-number',  # bad port num
 
                       'auth_ldap_tls_kind': 'PLAIN',
 
                       'auth_ldap_tls_reqcert': 'NEVER',
 
                       'auth_ldap_dn_user': '',
 
                       'auth_ldap_dn_pass': '',
 
@@ -80,13 +80,13 @@ class TestAuthSettingsController(TestCon
 

	
 
    def test_ldap_error_form(self):
 
        self.log_user()
 
        if ldap_lib_installed:
 
            raise SkipTest('skipping due to missing ldap lib')
 

	
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_rhodecode,kallithea.lib.auth_modules.auth_ldap')
 
        params = self._enable_plugins('kallithea.lib.auth_modules.auth_internal,kallithea.lib.auth_modules.auth_ldap')
 
        params.update({'auth_ldap_host': 'Host',
 
                       'auth_ldap_port': '123',
 
                       'auth_ldap_tls_kind': 'PLAIN',
 
                       'auth_ldap_tls_reqcert': 'NEVER',
 
                       'auth_ldap_dn_user': '',
 
                       'auth_ldap_dn_pass': '',
kallithea/tests/functional/test_admin_users.py
Show inline comments
 
@@ -53,14 +53,14 @@ class TestAdminUsersController(TestContr
 
            {'username': username,
 
             'password': password,
 
             'password_confirmation': password_confirmation,
 
             'firstname': name,
 
             'active': True,
 
             'lastname': lastname,
 
             'extern_name': 'rhodecode',
 
             'extern_type': 'rhodecode',
 
             'extern_name': 'internal',
 
             'extern_type': 'internal',
 
             'email': email})
 

	
 
        self.checkSessionFlash(response, '''Created user %s''' % (username))
 

	
 
        new_user = Session().query(User).\
 
            filter(User.username == username).one()
 
@@ -121,25 +121,25 @@ class TestAdminUsersController(TestContr
 
        #                   'password_confirmation': 'foobar123'})
 
        ])
 
    def test_update(self, name, attrs):
 
        self.log_user()
 
        usr = fixture.create_user(self.test_user_1, password='qweqwe',
 
                                  email='testme@example.com',
 
                                  extern_type='rhodecode',
 
                                  extern_type='internal',
 
                                  extern_name=self.test_user_1,
 
                                  skip_if_exists=True)
 
        Session().commit()
 
        params = usr.get_api_data()
 
        params.update({'password_confirmation': ''})
 
        params.update({'new_password': ''})
 
        params.update(attrs)
 
        if name == 'email':
 
            params['emails'] = [attrs['email']]
 
        if name == 'extern_type':
 
            #cannot update this via form, expected value is original one
 
            params['extern_type'] = "rhodecode"
 
            params['extern_type'] = "internal"
 
        if name == 'extern_name':
 
            #cannot update this via form, expected value is original one
 
            params['extern_name'] = self.test_user_1
 
            # special case since this user is not
 
                                          # logged in yet his data is not filled
 
                                          # so we use creation data
kallithea/tests/functional/test_my_account.py
Show inline comments
 
@@ -106,22 +106,22 @@ class TestMyAccountController(TestContro
 
        # ('new_password', {'new_password': 'foobar123',
 
        #                   'password_confirmation': 'foobar123'})
 
        ])
 
    def test_my_account_update(self, name, attrs):
 
        usr = fixture.create_user(self.test_user_1, password='qweqwe',
 
                                  email='testme@example.com',
 
                                  extern_type='rhodecode',
 
                                  extern_type='internal',
 
                                  extern_name=self.test_user_1,
 
                                  skip_if_exists=True)
 
        params = usr.get_api_data()  # current user data
 
        user_id = usr.user_id
 
        self.log_user(username=self.test_user_1, password='qweqwe')
 

	
 
        params.update({'password_confirmation': ''})
 
        params.update({'new_password': ''})
 
        params.update({'extern_type': 'rhodecode'})
 
        params.update({'extern_type': 'internal'})
 
        params.update({'extern_name': self.test_user_1})
 

	
 
        params.update(attrs)
 
        response = self.app.post(url('my_account'), params)
 

	
 
        self.checkSessionFlash(response,
 
@@ -134,13 +134,13 @@ class TestMyAccountController(TestContro
 

	
 
        params['last_login'] = updated_params['last_login']
 
        if name == 'email':
 
            params['emails'] = [attrs['email']]
 
        if name == 'extern_type':
 
            #cannot update this via form, expected value is original one
 
            params['extern_type'] = "rhodecode"
 
            params['extern_type'] = "internal"
 
        if name == 'extern_name':
 
            #cannot update this via form, expected value is original one
 
            params['extern_name'] = str(user_id)
 
        if name == 'active':
 
            #my account cannot deactivate account
 
            params['active'] = True
0 comments (0 inline, 0 general)