diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -169,7 +169,7 @@ class PullrequestsController(BaseRepoCon return redirect(url('pullrequest_show', repo_name=other_repo, pull_request_id=pull_request.pull_request_id)) - def _load_compare_data(self, pull_request): + def _load_compare_data(self, pull_request, enable_comments=True): """ Load context data needed for generating compare diff @@ -211,7 +211,7 @@ class PullrequestsController(BaseRepoCon for f in _parsed: fid = h.FID('', f['filename']) c.files.append([fid, f['operation'], f['filename'], f['stats']]) - diff = diff_processor.as_html(enable_comments=True, + diff = diff_processor.as_html(enable_comments=enable_comments, diff_lines=[f]) c.changes[fid] = [f['operation'], f['filename'], diff] @@ -246,7 +246,8 @@ class PullrequestsController(BaseRepoCon raise HTTPNotFound # load compare data into template context - self._load_compare_data(c.pull_request) + enable_comments = not c.pull_request.is_closed() + self._load_compare_data(c.pull_request, enable_comments=enable_comments) # inline comments c.inline_cnt = 0 @@ -271,6 +272,9 @@ class PullrequestsController(BaseRepoCon @jsonify def comment(self, repo_name, pull_request_id): + pull_request = PullRequest.get_or_404(pull_request_id) + if pull_request.is_closed(): + raise HTTPForbidden() status = request.POST.get('changeset_status') change_status = request.POST.get('change_changeset_status') @@ -299,6 +303,12 @@ class PullrequestsController(BaseRepoCon 'user_commented_pull_request:%s' % pull_request_id, c.rhodecode_db_repo, self.ip_addr, self.sa) + if request.POST.get('save_close'): + PullRequestModel().close_pull_request(pull_request_id) + action_logger(self.rhodecode_user, + 'user_closed_pull_request:%s' % pull_request_id, + c.rhodecode_db_repo, self.ip_addr, self.sa) + Session().commit() if not request.environ.get('HTTP_X_PARTIAL_XHR'): @@ -319,6 +329,10 @@ class PullrequestsController(BaseRepoCon @jsonify def delete_comment(self, repo_name, comment_id): co = ChangesetComment.get(comment_id) + if co.pull_request.is_closed(): + #don't allow deleting comments on closed pull request + raise HTTPForbidden() + owner = lambda: co.author.user_id == c.rhodecode_user.user_id if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: ChangesetCommentsModel().delete(comment=co) diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -1519,6 +1519,7 @@ class PullRequest(Base, BaseModel): description = Column('description', UnicodeText(10240), nullable=True) status = Column('status', Unicode(256), nullable=False, default=STATUS_NEW) created_on = Column('created_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) + updated_on = Column('updated_on', DateTime(timezone=False), nullable=False, default=datetime.datetime.now) user_id = Column("user_id", Integer(), ForeignKey('users.user_id'), nullable=False, unique=None) _revisions = Column('revisions', UnicodeText(20500)) # 500 revisions max org_repo_id = Column('org_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) @@ -1526,6 +1527,8 @@ class PullRequest(Base, BaseModel): other_repo_id = Column('other_repo_id', Integer(), ForeignKey('repositories.repo_id'), nullable=False) other_ref = Column('other_ref', Unicode(256), nullable=False) + statuses = relationship('ChangesetStatus') + @hybrid_property def revisions(self): return self._revisions.split(':') @@ -1539,6 +1542,9 @@ class PullRequest(Base, BaseModel): org_repo = relationship('Repository', primaryjoin='PullRequest.org_repo_id==Repository.repo_id') other_repo = relationship('Repository', primaryjoin='PullRequest.other_repo_id==Repository.repo_id') + def is_closed(self): + return self.status == self.STATUS_CLOSED + def __json__(self): return dict( revisions=self.revisions diff --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ - rhodecode.model.pull_reuquest - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + rhodecode.model.pull_request + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pull request model for RhodeCode @@ -25,6 +25,7 @@ import logging import binascii +import datetime from pylons.i18n.translation import _ @@ -44,6 +45,9 @@ class PullRequestModel(BaseModel): cls = PullRequest + def __get_pull_request(self, pull_request): + return self._get_instance(PullRequest, pull_request) + def get_all(self, repo): repo = self._get_repo(repo) return PullRequest.query().filter(PullRequest.other_repo == repo).all() @@ -93,6 +97,12 @@ class PullRequestModel(BaseModel): return new + def close_pull_request(self, pull_request): + pull_request = self.__get_pull_request(pull_request) + pull_request.status = PullRequest.STATUS_CLOSED + pull_request.updated_on = datetime.datetime.now() + self.sa.add(pull_request) + def _get_changesets(self, org_repo, org_ref, other_repo, other_ref, discovery_data): """ diff --git a/rhodecode/public/js/rhodecode.js b/rhodecode/public/js/rhodecode.js --- a/rhodecode/public/js/rhodecode.js +++ b/rhodecode/public/js/rhodecode.js @@ -396,7 +396,8 @@ var injectInlineForm = function(tr){ return } var submit_url = AJAX_COMMENT_URL; - if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(tr,'no-comment')){ + var _td = tr.getElementsByClassName('code')[0]; + if(YUD.hasClass(tr,'form-open') || YUD.hasClass(tr,'context') || YUD.hasClass(_td,'no-comment')){ return } YUD.addClass(tr,'form-open'); diff --git a/rhodecode/templates/changeset/changeset.html b/rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html +++ b/rhodecode/templates/changeset/changeset.html @@ -136,7 +136,10 @@ <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form()} - ## render comments main comments form and it status + ## render comments and inlines + ${comment.generate_comments()} + + ## main comment form and it status ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id), h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id))} diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -92,9 +92,8 @@ %def> -## MAIN COMMENT FORM -<%def name="comments(post_url, cur_status)"> - +## generate inline comments and the main ones +<%def name="generate_comments()">