# HG changeset patch # User Daniel Dourvaris # Date 2017-07-13 20:40:12 # Node ID 4a76cf6b408ba3b1a122de1c4e4f0abe92a6fc72 # Parent 4edc1a1e0d223f4066c86582fd762ba10f86f2fd users: add additional information why user with pending reviews shouldn't be deleted. diff --git a/rhodecode/controllers/admin/users.py b/rhodecode/controllers/admin/users.py --- a/rhodecode/controllers/admin/users.py +++ b/rhodecode/controllers/admin/users.py @@ -390,13 +390,23 @@ class UsersController(BaseController): # Interim workaround if the user participated on any pull requests as a # reviewer. - has_review = bool(PullRequestReviewers.query().filter( - PullRequestReviewers.user_id == user_id).first()) + has_review = len(user.reviewer_pull_requests) c.can_delete_user = not has_review - c.can_delete_user_message = _( - 'The user participates as reviewer in pull requests and ' - 'cannot be deleted. You can set the user to ' - '"inactive" instead of deleting it.') if has_review else '' + c.can_delete_user_message = '' + inactive_link = h.link_to( + 'inactive', h.url('edit_user', user_id=user_id, anchor='active')) + if has_review == 1: + c.can_delete_user_message = h.literal(_( + 'The user participates as reviewer in {} pull request and ' + 'cannot be deleted. \nYou can set the user to ' + '"{}" instead of deleting it.').format( + has_review, inactive_link)) + elif has_review: + c.can_delete_user_message = h.literal(_( + 'The user participates as reviewer in {} pull requests and ' + 'cannot be deleted. \nYou can set the user to ' + '"{}" instead of deleting it.').format( + has_review, inactive_link)) return htmlfill.render( render('admin/users/user_edit.mako'), diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -606,6 +606,13 @@ class User(Base, BaseModel): self._api_key = None @property + def reviewer_pull_requests(self): + return PullRequestReviewers.query() \ + .options(joinedload(PullRequestReviewers.pull_request)) \ + .filter(PullRequestReviewers.user_id == self.user_id) \ + .all() + + @property def firstname(self): # alias for future return self.name diff --git a/rhodecode/public/css/main.less b/rhodecode/public/css/main.less --- a/rhodecode/public/css/main.less +++ b/rhodecode/public/css/main.less @@ -285,6 +285,9 @@ input.inline[type="file"] { margin: 0 0 @padding; padding:.5em; background-color: @grey6; + &.pre-formatting { + white-space: pre; + } } } @@ -1805,6 +1808,9 @@ BIN_FILENODE = 7 .help-block { margin: @padding 0; color: @text-color; + &.pre-formatting { + white-space: pre; + } } .empty_data { diff --git a/rhodecode/public/css/type.less b/rhodecode/public/css/type.less --- a/rhodecode/public/css/type.less +++ b/rhodecode/public/css/type.less @@ -533,6 +533,9 @@ address { margin: 0 0 @padding; color: @grey4; font-family: @text-light; + &.pre-formatting { + white-space: pre; + } } .error-message { diff --git a/rhodecode/templates/admin/users/user_edit_advanced.mako b/rhodecode/templates/admin/users/user_edit_advanced.mako --- a/rhodecode/templates/admin/users/user_edit_advanced.mako +++ b/rhodecode/templates/admin/users/user_edit_advanced.mako @@ -12,6 +12,7 @@ (_('Repository groups'), len(c.user.repository_groups), '', [x.group_name for x in c.user.repository_groups]), (_('User groups'), len(c.user.user_groups), '', [x.users_group_name for x in c.user.user_groups]), + (_('Reviewer of pull requests'), len(c.user.reviewer_pull_requests), '', ['Pull Request #{}'.format(x.pull_request.pull_request_id) for x in c.user.reviewer_pull_requests]), (_('Member of User groups'), len(c.user.group_member), '', [x.users_group.users_group_name for x in c.user.group_member]), (_('Force password change'), c.user.user_data.get('force_password_change', 'False'), '', ''), ] @@ -142,7 +143,7 @@ % if c.can_delete_user_message: -

${c.can_delete_user_message}

+

${c.can_delete_user_message}

% endif