Mercurial > kallithea
changeset 4209:de26de99ac5b kallithea-2.2.5-rebrand
Rename auth_rhodecode to auth_internal
line wrap: on
line diff
--- a/kallithea/controllers/admin/auth_settings.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/controllers/admin/auth_settings.py Wed Jul 02 19:05:47 2014 -0400 @@ -53,7 +53,7 @@ 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', @@ -65,7 +65,7 @@ _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"] = {}
--- a/kallithea/controllers/admin/my_account.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/controllers/admin/my_account.py Wed Jul 02 19:05:47 2014 -0400 @@ -116,7 +116,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 != "rhodecode": + if c.extern_type != "internal": # forbid updating username for external accounts skip_attrs.append('username')
--- a/kallithea/controllers/admin/users.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/controllers/admin/users.py Wed Jul 02 19:05:47 2014 -0400 @@ -40,7 +40,7 @@ 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 @@ -121,7 +121,7 @@ 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: @@ -151,7 +151,7 @@ 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): @@ -175,7 +175,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 != "rhodecode": + if c.extern_type != "internal": # forbid updating username for external accounts skip_attrs.append('username')
--- a/kallithea/controllers/api/api.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/controllers/api/api.py Wed Jul 02 19:05:47 2014 -0400 @@ -618,8 +618,8 @@ 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.
--- a/kallithea/lib/auth_modules/__init__.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/lib/auth_modules/__init__.py Wed Jul 02 19:05:47 2014 -0400 @@ -305,7 +305,7 @@ 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:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kallithea/lib/auth_modules/auth_internal.py Wed Jul 02 19:05:47 2014 -0400 @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# 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_internal +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +RhodeCode authentication plugin for built in internal auth + +:created_on: Created on Nov 17, 2012 +:author: marcink +:copyright: (c) 2013 RhodeCode GmbH. +:license: GPLv3, see LICENSE.md for more details. +""" + + +import logging +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 RhodeCodeAuthPlugin(auth_modules.RhodeCodeAuthPluginBase): + def __init__(self): + pass + + @hybrid_property + def name(self): + return "internal" + + def settings(self): + return [] + + def user_activation_state(self): + def_user_perms = User.get_default_user().AuthUser.permissions['global'] + return 'hg.register.auto_activate' in def_user_perms + + def accepts(self, user, accepts_empty=True): + """ + Custom accepts for this auth that doesn't accept empty users. We + know that user exisits in database. + """ + return super(RhodeCodeAuthPlugin, self).accepts(user, + accepts_empty=False) + + def auth(self, userobj, username, password, settings, **kwargs): + if not userobj: + log.debug('userobj was:%s skipping' % (userobj, )) + return None + if userobj.extern_type != self.name: + log.warn("userobj:%s extern_type mismatch got:`%s` expected:`%s`" + % (userobj, userobj.extern_type, self.name)) + return None + + user_attrs = { + "username": userobj.username, + "firstname": userobj.firstname, + "lastname": userobj.lastname, + "groups": [], + "email": userobj.email, + "admin": userobj.admin, + "active": userobj.active, + "active_from_extern": userobj.active, + "extern_name": userobj.user_id, + 'extern_type': userobj.extern_type, + } + + log.debug(formatted_json(user_attrs)) + if userobj.active: + from kallithea.lib import auth + password_match = auth.RhodeCodeCrypto.hash_check(password, userobj.password) + if userobj.username == User.DEFAULT_USER and userobj.active: + log.info('user %s authenticated correctly as anonymous user' % + username) + return user_attrs + + elif userobj.username == username and password_match: + log.info('user %s authenticated correctly' % user_attrs['username']) + return user_attrs + log.error("user %s had a bad password" % username) + return None + else: + log.warning('user %s tried auth but is disabled' % username) + return None
--- a/kallithea/lib/auth_modules/auth_rhodecode.py Wed May 21 16:59:37 2014 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -# -*- coding: utf-8 -*- -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# 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 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -RhodeCode authentication plugin for built in internal auth - -:created_on: Created on Nov 17, 2012 -:author: marcink -:copyright: (c) 2013 RhodeCode GmbH. -:license: GPLv3, see LICENSE.md for more details. -""" - - -import logging -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 RhodeCodeAuthPlugin(auth_modules.RhodeCodeAuthPluginBase): - def __init__(self): - pass - - @hybrid_property - def name(self): - return "rhodecode" - - def settings(self): - return [] - - def user_activation_state(self): - def_user_perms = User.get_default_user().AuthUser.permissions['global'] - return 'hg.register.auto_activate' in def_user_perms - - def accepts(self, user, accepts_empty=True): - """ - Custom accepts for this auth that doesn't accept empty users. We - know that user exisits in database. - """ - return super(RhodeCodeAuthPlugin, self).accepts(user, - accepts_empty=False) - - def auth(self, userobj, username, password, settings, **kwargs): - if not userobj: - log.debug('userobj was:%s skipping' % (userobj, )) - return None - if userobj.extern_type != self.name: - log.warn("userobj:%s extern_type mismatch got:`%s` expected:`%s`" - % (userobj, userobj.extern_type, self.name)) - return None - - user_attrs = { - "username": userobj.username, - "firstname": userobj.firstname, - "lastname": userobj.lastname, - "groups": [], - "email": userobj.email, - "admin": userobj.admin, - "active": userobj.active, - "active_from_extern": userobj.active, - "extern_name": userobj.user_id, - 'extern_type': userobj.extern_type, - } - - log.debug(formatted_json(user_attrs)) - if userobj.active: - from kallithea.lib import auth - password_match = auth.RhodeCodeCrypto.hash_check(password, userobj.password) - if userobj.username == User.DEFAULT_USER and userobj.active: - log.info('user %s authenticated correctly as anonymous user' % - username) - return user_attrs - - elif userobj.username == username and password_match: - log.info('user %s authenticated correctly' % user_attrs['username']) - return user_attrs - log.error("user %s had a bad password" % username) - return None - else: - log.warning('user %s tried auth but is disabled' % username) - return None
--- a/kallithea/lib/db_manage.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/lib/db_manage.py Wed Jul 02 19:05:47 2014 -0400 @@ -374,8 +374,8 @@ :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 @@ -541,7 +541,7 @@ 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')
--- a/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/lib/dbmigrate/versions/016_version_2_0_0.py Wed Jul 02 19:05:47 2014 -0400 @@ -63,7 +63,7 @@ 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()
--- a/kallithea/lib/dbmigrate/versions/018_version_2_0_0.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/lib/dbmigrate/versions/018_version_2_0_0.py Wed Jul 02 19:05:47 2014 -0400 @@ -37,7 +37,7 @@ 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'), @@ -47,7 +47,7 @@ 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)
--- a/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/lib/dbmigrate/versions/020_version_2_0_1.py Wed Jul 02 19:05:47 2014 -0400 @@ -36,10 +36,10 @@ 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()
--- a/kallithea/model/user.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/model/user.py Wed Jul 02 19:05:47 2014 -0400 @@ -185,8 +185,8 @@ 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)
--- a/kallithea/templates/admin/my_account/my_account_profile.html Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/templates/admin/my_account/my_account_profile.html Wed Jul 02 19:05:47 2014 -0400 @@ -20,7 +20,7 @@ <% 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>
--- a/kallithea/templates/admin/users/user_edit_profile.html Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/templates/admin/users/user_edit_profile.html Wed Jul 02 19:05:47 2014 -0400 @@ -20,7 +20,7 @@ <% readonly = None %> <% disabled = "" %> <div class="fields"> - %if c.extern_type != 'rhodecode': + %if c.extern_type != 'internal': <div class="field"> <% readonly = "readonly" %> <% disabled = " disabled" %>
--- a/kallithea/tests/api/api_base.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/tests/api/api_base.py Wed Jul 02 19:05:47 2014 -0400 @@ -618,7 +618,7 @@ 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)
--- a/kallithea/tests/fixture.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/tests/fixture.py Wed Jul 02 19:05:47 2014 -0400 @@ -110,7 +110,7 @@ lastname='Test', active=True, admin=False, - extern_type='rhodecode', + extern_type='internal', extern_name=None ) defs.update(custom)
--- a/kallithea/tests/functional/test_admin_auth_settings.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/tests/functional/test_admin_auth_settings.py Wed Jul 02 19:05:47 2014 -0400 @@ -26,7 +26,7 @@ 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', @@ -56,7 +56,7 @@ 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', @@ -83,7 +83,7 @@ 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',
--- a/kallithea/tests/functional/test_admin_users.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/tests/functional/test_admin_users.py Wed Jul 02 19:05:47 2014 -0400 @@ -56,8 +56,8 @@ '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)) @@ -124,7 +124,7 @@ 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() @@ -136,7 +136,7 @@ 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
--- a/kallithea/tests/functional/test_my_account.py Wed May 21 16:59:37 2014 -0400 +++ b/kallithea/tests/functional/test_my_account.py Wed Jul 02 19:05:47 2014 -0400 @@ -109,7 +109,7 @@ 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 @@ -118,7 +118,7 @@ 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) @@ -137,7 +137,7 @@ 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)