Changeset - 7b780f5f5cab
[Not reviewed]
default
0 1 0
Søren Løvborg - 10 years ago 2015-08-24 16:50:43
sorenl@unity3d.com
auth: avoid random auth_internal failures - add explicit import of auth_internal to user admin

auth_internal would often have been loaded by the custom auth module loader and
available as auth_modules.auth_internal ... but sometimes it wasn't and
navigating to Add User would fail with:

File '.../kallithea/controllers/admin/users.py', line 155 in new
c.default_extern_type = auth_modules.auth_internal.KallitheaAuthPlugin.name
AttributeError: 'module' object has no attribute 'auth_internal'
1 file changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -34,24 +34,25 @@ from pylons import request, tmpl_context
 
from pylons.controllers.util import redirect
 
from pylons.i18n.translation import _
 
from sqlalchemy.sql.expression import func
 
from webob.exc import HTTPNotFound
 

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

	
 
from kallithea.model.db import User, UserEmailMap, UserIpMap, UserToPerm
 
from kallithea.model.forms import UserForm, CustomDefaultPermissionsForm
 
from kallithea.model.user import UserModel
 
from kallithea.model.meta import Session
 
from kallithea.lib.utils import action_logger
 
from kallithea.lib.compat import json
 
from kallithea.lib.utils2 import datetime_to_time, safe_int, generate_api_key
 

	
 
log = logging.getLogger(__name__)
 
@@ -111,26 +112,26 @@ class UsersController(BaseController):
 
            "totalRecords": total_records,
 
            "startIndex": 0,
 
            "sort": None,
 
            "dir": "asc",
 
            "records": users_data
 
        })
 

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

	
 
    def create(self):
 
        """POST /users: Create a new item"""
 
        # url('users')
 
        c.default_extern_type = auth_modules.auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_modules.auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_type = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_internal.KallitheaAuthPlugin.name
 
        user_model = UserModel()
 
        user_form = UserForm()()
 
        try:
 
            form_result = user_form.to_python(dict(request.POST))
 
            user = user_model.create(form_result)
 
            usr = form_result['username']
 
            action_logger(self.authuser, 'admin_created_user:%s' % usr,
 
                          None, self.ip_addr, self.sa)
 
            h.flash(h.literal(_('Created user %s') % h.link_to(h.escape(usr), url('edit_user', id=user.user_id))),
 
                    category='success')
 
            Session().commit()
 
        except formencode.Invalid as errors:
 
@@ -143,26 +144,26 @@ class UsersController(BaseController):
 
                force_defaults=False)
 
        except UserCreationError as e:
 
            h.flash(e, 'error')
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            h.flash(_('Error occurred during creation of user %s') \
 
                    % 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_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_modules.auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_type = auth_internal.KallitheaAuthPlugin.name
 
        c.default_extern_name = auth_internal.KallitheaAuthPlugin.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" />
 
        # Or using helpers:
 
        #    h.form(url('update_user', id=ID),
 
        #           method='put')
 
        # url('user', id=ID)
 
        user_model = UserModel()
 
        user = user_model.get(id)
0 comments (0 inline, 0 general)