[PATCH 2 of 2] controllers, lib: reduce log level of flashes

Thomas De Schampheleire patrickdepinguin at gmail.com
Sat Mar 28 17:34:26 EDT 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1427577130 -3600
#      Sat Mar 28 22:12:10 2015 +0100
# Node ID 039f3d14bdd3a07a9a071d3911b07ab2b06328b6
# Parent  2f4d67b8acefc3e85ddb5c165bc4054b0ddab90d
controllers, lib: reduce log level of flashes

Reduce log level of certain flashes: a warning to the user is often not a
warning to the administrator.

diff --git a/kallithea/controllers/admin/repo_groups.py b/kallithea/controllers/admin/repo_groups.py
--- a/kallithea/controllers/admin/repo_groups.py
+++ b/kallithea/controllers/admin/repo_groups.py
@@ -287,13 +287,15 @@
         repos = gr.repositories.all()
         if repos:
             h.flash(_('This group contains %s repositories and cannot be '
-                      'deleted') % len(repos), category='warning')
+                      'deleted') % len(repos), category='warning',
+                      log_category='debug')
             return redirect(url('repos_groups'))
 
         children = gr.children.all()
         if children:
             h.flash(_('This group contains %s subgroups and cannot be deleted'
-                      % (len(children))), category='warning')
+                      % (len(children))), category='warning',
+                      log_category='debug')
             return redirect(url('repos_groups'))
 
         try:
@@ -418,7 +420,7 @@
         if not c.authuser.is_admin:
             if self._revoke_perms_on_yourself(form_result):
                 msg = _('Cannot revoke permission for yourself as admin')
-                h.flash(msg, category='warning')
+                h.flash(msg, category='warning', log_category='debug')
                 return redirect(url('edit_repo_group_perms', group_name=group_name))
         recursive = form_result['recursive']
         # iterate over all members(if in recursive mode) of this groups and
@@ -453,7 +455,7 @@
             if not c.authuser.is_admin:
                 if obj_type == 'user' and c.authuser.user_id == obj_id:
                     msg = _('Cannot revoke permission for yourself as admin')
-                    h.flash(msg, category='warning')
+                    h.flash(msg, category='warning', log_category='debug')
                     raise Exception('revoke admin permission on self')
             recursive = request.POST.get('recursive', 'none')
             if obj_type == 'user':
diff --git a/kallithea/controllers/admin/repos.py b/kallithea/controllers/admin/repos.py
--- a/kallithea/controllers/admin/repos.py
+++ b/kallithea/controllers/admin/repos.py
@@ -345,7 +345,7 @@
             Session().commit()
         except AttachedForksError:
             h.flash(_('Cannot delete %s it still contains attached forks')
-                        % repo_name, category='warning')
+                        % repo_name, category='warning', log_category='debug')
 
         except Exception:
             log.error(traceback.format_exc())
diff --git a/kallithea/controllers/admin/settings.py b/kallithea/controllers/admin/settings.py
--- a/kallithea/controllers/admin/settings.py
+++ b/kallithea/controllers/admin/settings.py
@@ -355,7 +355,8 @@
             test_body = ('Kallithea Email test, '
                                'Kallithea version: %s' % c.kallithea_version)
             if not test_email:
-                h.flash(_('Please enter email address'), category='error')
+                h.flash(_('Please enter email address'), category='error',
+                        log_category='debug')
                 return redirect(url('admin_settings_email'))
 
             test_email_txt_body = EmailNotificationModel()\
diff --git a/kallithea/controllers/admin/user_groups.py b/kallithea/controllers/admin/user_groups.py
--- a/kallithea/controllers/admin/user_groups.py
+++ b/kallithea/controllers/admin/user_groups.py
@@ -311,7 +311,8 @@
             UserGroupModel()._update_permissions(user_group, form['perms_new'],
                                                  form['perms_updates'])
         except RepoGroupAssignmentError:
-            h.flash(_('Target group cannot be the same'), category='error')
+            h.flash(_('Target group cannot be the same'), category='error',
+                    log_category='debug')
             return redirect(url('edit_user_group_perms', id=id))
         #TODO: implement this
         #action_logger(self.authuser, 'admin_changed_repo_permissions',
@@ -338,7 +339,7 @@
             if not c.authuser.is_admin:
                 if obj_type == 'user' and c.authuser.user_id == obj_id:
                     msg = _('Cannot revoke permission for yourself as admin')
-                    h.flash(msg, category='warning')
+                    h.flash(msg, category='warning', log_category='debug')
                     raise Exception('revoke admin permission on self')
             if obj_type == 'user':
                 UserGroupModel().revoke_user_permission(user_group=id,
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,17 @@
         # 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',
+                    log_category='debug')
+            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 +259,7 @@
 
     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 +280,7 @@
 
     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 +303,7 @@
 
     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 +314,7 @@
 
     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 +336,7 @@
 
     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 +397,7 @@
 
     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 +442,7 @@
 
     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()\
diff --git a/kallithea/controllers/changelog.py b/kallithea/controllers/changelog.py
--- a/kallithea/controllers/changelog.py
+++ b/kallithea/controllers/changelog.py
@@ -84,7 +84,7 @@
             return c.db_repo_scm_instance.get_changeset(rev)
         except EmptyRepositoryError, e:
             h.flash(h.literal(_('There are no changesets yet')),
-                    category='error')
+                    category='error', log_category='debug')
         except RepositoryError, e:
             log.error(traceback.format_exc())
             h.flash(safe_str(e), category='error')
@@ -146,7 +146,7 @@
             c.comments = c.db_repo.get_comments(page_revisions)
             c.statuses = c.db_repo.statuses(page_revisions)
         except (EmptyRepositoryError), e:
-            h.flash(safe_str(e), category='warning')
+            h.flash(safe_str(e), category='warning', log_category='debug')
             return redirect(url('summary_home', repo_name=c.repo_name))
         except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
             log.error(traceback.format_exc())
diff --git a/kallithea/controllers/changeset.py b/kallithea/controllers/changeset.py
--- a/kallithea/controllers/changeset.py
+++ b/kallithea/controllers/changeset.py
@@ -378,10 +378,10 @@
                     dont_allow_on_closed_pull_request=True
                 )
             except StatusChangeOnClosedPullRequestError:
-                log.error(traceback.format_exc())
+                log.debug(traceback.format_exc())
                 msg = _('Changing status on a changeset associated with '
                         'a closed pull request is not allowed')
-                h.flash(msg, category='warning')
+                h.flash(msg, category='warning', log_category='debug')
                 return redirect(h.url('changeset_home', repo_name=repo_name,
                                       revision=revision))
         action_logger(self.authuser,
diff --git a/kallithea/controllers/files.py b/kallithea/controllers/files.py
--- a/kallithea/controllers/files.py
+++ b/kallithea/controllers/files.py
@@ -91,7 +91,7 @@
                        revision=0, f_path='', anchor='edit')
             add_new = h.link_to(_('Click here to add new file'), url_, class_="alert-link")
             h.flash(h.literal(_('There are no files yet. %s') % add_new),
-                    category='warning')
+                    category='warning', log_category='debug')
             raise HTTPNotFound()
         except(ChangesetDoesNotExistError, LookupError), e:
             msg = _('Such revision does not exist for this repository')
@@ -306,7 +306,7 @@
             h.flash(_('This repository has been locked by %s on %s')
                 % (h.person_by_id(repo.locked[0]),
                    h.fmt_date(h.time_to_datetime(repo.locked[1]))),
-                'warning')
+                'warning', log_category='debug')
             return redirect(h.url('files_home',
                                   repo_name=repo_name, revision='tip'))
 
@@ -316,7 +316,8 @@
         # check if revision is a branch name or branch hash
         if revision not in _branches.keys() + _branches.values():
             h.flash(_('You can only delete files with revision '
-                      'being a valid branch '), category='warning')
+                      'being a valid branch '), category='warning',
+                      log_category='debug')
             return redirect(h.url('files_home',
                                   repo_name=repo_name, revision='tip',
                                   f_path=f_path))
@@ -366,7 +367,7 @@
             h.flash(_('This repository has been locked by %s on %s')
                 % (h.person_by_id(repo.locked[0]),
                    h.fmt_date(h.time_to_datetime(repo.locked[1]))),
-                'warning')
+                'warning', log_category='debug')
             return redirect(h.url('files_home',
                                   repo_name=repo_name, revision='tip'))
 
@@ -376,7 +377,8 @@
         # check if revision is a branch name or branch hash
         if revision not in _branches.keys() + _branches.values():
             h.flash(_('You can only edit files with revision '
-                      'being a valid branch '), category='warning')
+                      'being a valid branch '), category='warning',
+                      log_category='debug')
             return redirect(h.url('files_home',
                                   repo_name=repo_name, revision='tip',
                                   f_path=f_path))
@@ -405,7 +407,7 @@
             author = self.authuser.full_contact
 
             if content == old_content:
-                h.flash(_('No changes'), category='warning')
+                h.flash(_('No changes'), category='warning', log_category='debug')
                 return redirect(url('changeset_home', repo_name=c.repo_name,
                                     revision='tip'))
             try:
@@ -433,7 +435,7 @@
             h.flash(_('This repository has been locked by %s on %s')
                 % (h.person_by_id(repo.locked[0]),
                    h.fmt_date(h.time_to_datetime(repo.locked[1]))),
-                  'warning')
+                  'warning', log_category='debug')
             return redirect(h.url('files_home',
                                   repo_name=repo_name, revision='tip'))
 
@@ -462,11 +464,11 @@
                     content = content.file
 
             if not content:
-                h.flash(_('No content'), category='warning')
+                h.flash(_('No content'), category='warning', log_category='debug')
                 return redirect(url('changeset_home', repo_name=c.repo_name,
                                     revision='tip'))
             if not filename:
-                h.flash(_('No filename'), category='warning')
+                h.flash(_('No filename'), category='warning', log_category='debug')
                 return redirect(url('changeset_home', repo_name=c.repo_name,
                                     revision='tip'))
             #strip all crap out of file, just leave the basename
@@ -492,7 +494,7 @@
                         category='success')
             except NonRelativePathError, e:
                 h.flash(_('Location must be relative path and must not '
-                          'contain .. in path'), category='warning')
+                          'contain .. in path'), category='warning', log_category='debug')
                 return redirect(url('changeset_home', repo_name=c.repo_name,
                                     revision='tip'))
             except (NodeError, NodeAlreadyExistsError), e:
diff --git a/kallithea/controllers/pullrequests.py b/kallithea/controllers/pullrequests.py
--- a/kallithea/controllers/pullrequests.py
+++ b/kallithea/controllers/pullrequests.py
@@ -245,7 +245,7 @@
             org_scm_instance.get_changeset()
         except EmptyRepositoryError, e:
             h.flash(h.literal(_('There are no changesets yet')),
-                    category='warning')
+                    category='warning', log_category='debug')
             redirect(url('summary_home', repo_name=org_repo.repo_name))
 
         org_rev = request.GET.get('rev_end')
diff --git a/kallithea/lib/auth.py b/kallithea/lib/auth.py
--- a/kallithea/lib/auth.py
+++ b/kallithea/lib/auth.py
@@ -805,7 +805,7 @@
             import kallithea.lib.helpers as h
             h.flash(_('You need to be a registered user to '
                       'perform this action'),
-                    category='warning')
+                    category='warning', log_category='debug')
             return redirect(url('login_home', came_from=p))
         else:
             return func(*fargs, **fkwargs)
@@ -842,7 +842,7 @@
                 import kallithea.lib.helpers as h
                 h.flash(_('You need to be signed in to '
                           'view this page'),
-                        category='warning')
+                        category='warning', log_category='debug')
                 return redirect(url('login_home', came_from=p))
 
             else:
diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py
--- a/kallithea/lib/base.py
+++ b/kallithea/lib/base.py
@@ -447,7 +447,7 @@
             if returnempty:
                 return repo.scm_instance.EMPTY_CHANGESET
             h.flash(h.literal(_('There are no changesets yet')),
-                    category='error')
+                    category='error', log_category='debug')
             raise webob.exc.HTTPNotFound()
         except ChangesetDoesNotExistError as e:
             h.flash(h.literal(_('Changeset not found')),


More information about the kallithea-general mailing list