aboutsummaryrefslogtreecommitdiff
path: root/rhodecode
diff options
context:
space:
mode:
authorMarcin Kuzminski <marcin@python-works.com>2012-07-30 23:29:03 +0200
committerMarcin Kuzminski <marcin@python-works.com>2012-07-30 23:29:03 +0200
commit65e47700670acb8c63243f3848d0483049f61752 (patch)
tree8a8da6e31e4af57019c2cd33909ae6512bedb6e8 /rhodecode
parent32f6df90ad29f33800ebbffa311cd9085f1373b3 (diff)
Forbid changing changset status when it is associated with a closed pull request
- fixed some issues with cascade deleting repos with changeset statuses attached --HG-- branch : beta
Diffstat (limited to 'rhodecode')
-rw-r--r--rhodecode/controllers/changeset.py32
-rw-r--r--rhodecode/lib/exceptions.py4
-rw-r--r--rhodecode/model/changeset_status.py14
-rwxr-xr-xrhodecode/model/db.py2
-rw-r--r--rhodecode/templates/changeset/changeset_file_comment.html4
5 files changed, 43 insertions, 13 deletions
diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py
index c85173d1..e39739b8 100644
--- a/rhodecode/controllers/changeset.py
+++ b/rhodecode/controllers/changeset.py
@@ -49,6 +49,7 @@ from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.meta import Session
from rhodecode.lib.diffs import wrapped_diff
from rhodecode.model.repo import RepoModel
+from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
log = logging.getLogger(__name__)
@@ -388,18 +389,31 @@ class ChangesetController(BaseRepoController):
# get status if set !
if status and change_status:
- ChangesetStatusModel().set_status(
- c.rhodecode_db_repo.repo_id,
- status,
- c.rhodecode_user.user_id,
- comm,
- revision=revision,
- )
+ # if latest status was from pull request and it's closed
+ # disallow changing status !
+ # dont_allow_on_closed_pull_request = True !
+
+ try:
+ ChangesetStatusModel().set_status(
+ c.rhodecode_db_repo.repo_id,
+ status,
+ c.rhodecode_user.user_id,
+ comm,
+ revision=revision,
+ dont_allow_on_closed_pull_request=True
+ )
+ except StatusChangeOnClosedPullRequestError:
+ log.error(traceback.format_exc())
+ msg = _('Changing status on a changeset associated with'
+ 'a closed pull request is not allowed')
+ h.flash(msg, category='warning')
+ return redirect(h.url('changeset_home', repo_name=repo_name,
+ revision=revision))
action_logger(self.rhodecode_user,
'user_commented_revision:%s' % revision,
c.rhodecode_db_repo, self.ip_addr, self.sa)
- Session.commit()
+ Session().commit()
if not request.environ.get('HTTP_X_PARTIAL_XHR'):
return redirect(h.url('changeset_home', repo_name=repo_name,
@@ -422,7 +436,7 @@ class ChangesetController(BaseRepoController):
owner = lambda: co.author.user_id == c.rhodecode_user.user_id
if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
ChangesetCommentsModel().delete(comment=co)
- Session.commit()
+ Session().commit()
return True
else:
raise HTTPForbidden()
diff --git a/rhodecode/lib/exceptions.py b/rhodecode/lib/exceptions.py
index 3339c14c..0e09bf62 100644
--- a/rhodecode/lib/exceptions.py
+++ b/rhodecode/lib/exceptions.py
@@ -50,3 +50,7 @@ class UserOwnsReposException(Exception):
class UsersGroupsAssignedException(Exception):
pass
+
+
+class StatusChangeOnClosedPullRequestError(Exception):
+ pass \ No newline at end of file
diff --git a/rhodecode/model/changeset_status.py b/rhodecode/model/changeset_status.py
index 6a14c0a3..46fc9710 100644
--- a/rhodecode/model/changeset_status.py
+++ b/rhodecode/model/changeset_status.py
@@ -28,6 +28,7 @@ from collections import defaultdict
from rhodecode.model import BaseModel
from rhodecode.model.db import ChangesetStatus, PullRequest
+from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError
log = logging.getLogger(__name__)
@@ -111,7 +112,7 @@ class ChangesetStatusModel(BaseModel):
return str(st)
def set_status(self, repo, status, user, comment, revision=None,
- pull_request=None):
+ pull_request=None, dont_allow_on_closed_pull_request=False):
"""
Creates new status for changeset or updates the old ones bumping their
version, leaving the current status at
@@ -126,6 +127,9 @@ class ChangesetStatusModel(BaseModel):
:type user:
:param comment:
:type comment:
+ :param dont_allow_on_closed_pull_request: don't allow a status change
+ if last status was for pull request and it's closed. We shouldn't
+ mess around this manually
"""
repo = self._get_repo(repo)
@@ -140,6 +144,14 @@ class ChangesetStatusModel(BaseModel):
q = q.filter(ChangesetStatus.pull_request == pull_request)
cur_statuses = q.all()
+ #if statuses exists and last is associated with a closed pull request
+ # we need to check if we can allow this status change
+ if (dont_allow_on_closed_pull_request and cur_statuses
+ and cur_statuses[0].pull_request.status == PullRequest.STATUS_CLOSED):
+ raise StatusChangeOnClosedPullRequestError(
+ 'Changing status on closed pull request is not allowed'
+ )
+
if cur_statuses:
for st in cur_statuses:
st.version += 1
diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py
index e7d04877..5fbddc3a 100755
--- a/rhodecode/model/db.py
+++ b/rhodecode/model/db.py
@@ -1449,7 +1449,7 @@ class ChangesetComment(Base, BaseModel):
author = relationship('User', lazy='joined')
repo = relationship('Repository')
- status_change = relationship('ChangesetStatus', uselist=False)
+ status_change = relationship('ChangesetStatus', cascade="all, delete, delete-orphan")
pull_request = relationship('PullRequest', lazy='joined')
@classmethod
diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html
index ab1efd7e..283e0ce1 100644
--- a/rhodecode/templates/changeset/changeset_file_comment.html
+++ b/rhodecode/templates/changeset/changeset_file_comment.html
@@ -17,8 +17,8 @@
%if co.status_change:
<div style="float:left" class="changeset-status-container">
<div style="float:left;padding:0px 2px 0px 2px"><span style="font-size: 18px;">&rsaquo;</span></div>
- <div title="${_('Changeset status')}" class="changeset-status-lbl"> ${co.status_change.status_lbl}</div>
- <div class="changeset-status-ico"><img src="${h.url(str('/images/icons/flag_status_%s.png' % co.status_change.status))}" /></div>
+ <div title="${_('Changeset status')}" class="changeset-status-lbl"> ${co.status_change[0].status_lbl}</div>
+ <div class="changeset-status-ico"><img src="${h.url(str('/images/icons/flag_status_%s.png' % co.status_change[0].status))}" /></div>
</div>
%endif
%if h.HasPermissionAny('hg.admin', 'repository.admin')() or co.author.user_id == c.rhodecode_user.user_id: