[PATCH 1 of 6 v2] admin: users: factorize check for default user
Thomas De Schampheleire
patrickdepinguin at gmail.com
Sun May 10 14:22:53 EDT 2015
# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1430943590 -7200
# Wed May 06 22:19:50 2015 +0200
# Node ID 877fa67247ecfe9cb01a6b70bfaeee265bb65b9e
# Parent 196c46444d9881b8f8955159d198c7a6e455b88c
admin: users: factorize check for default user
diff --git a/kallithea/controllers/admin/users.py b/kallithea/controllers/admin/users.py
--- a/kallithea/controllers/admin/users.py
+++ b/kallithea/controllers/admin/users.py
@@ -233,13 +233,16 @@ class UsersController(BaseController):
# url('user', id=ID)
User.get_or_404(-1)
+ def _check_default_user(self, user):
+ if user.username == User.DEFAULT_USER:
+ h.flash(_("You can't edit this user"), category='warning')
+ return redirect(url('users'))
+
def edit(self, id, format='html'):
"""GET /users/id/edit: Form to edit an existing item"""
# url('edit_user', id=ID)
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'profile'
c.extern_type = c.user.extern_type
@@ -255,9 +258,7 @@ class UsersController(BaseController):
def edit_advanced(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'advanced'
c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
@@ -278,9 +279,7 @@ class UsersController(BaseController):
def edit_api_keys(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'api_keys'
show_expired = True
@@ -303,9 +302,7 @@ class UsersController(BaseController):
def add_api_key(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
lifetime = safe_int(request.POST.get('lifetime'), -1)
description = request.POST.get('description')
@@ -316,9 +313,7 @@ class UsersController(BaseController):
def delete_api_key(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
api_key = request.POST.get('del_api_key')
if request.POST.get('del_api_key_builtin'):
@@ -340,9 +335,7 @@ class UsersController(BaseController):
def edit_perms(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'perms'
c.perm_user = AuthUser(user_id=id, ip_addr=self.ip_addr)
@@ -403,9 +396,7 @@ class UsersController(BaseController):
def edit_emails(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'emails'
c.user_email_map = UserEmailMap.query()\
@@ -450,9 +441,7 @@ class UsersController(BaseController):
def edit_ips(self, id):
c.user = User.get_or_404(id)
- if c.user.username == User.DEFAULT_USER:
- h.flash(_("You can't edit this user"), category='warning')
- return redirect(url('users'))
+ self._check_default_user(c.user)
c.active = 'ips'
c.user_ip_map = UserIpMap.query()\
More information about the kallithea-general
mailing list