##// END OF EJS Templates
diffs: fixed other file source when using pull requests. It must use...
marcink -
r1194:f606ad60 default
parent child Browse files
Show More
@@ -46,7 +46,7 b' from rhodecode.lib.channelstream import '
46 from rhodecode.lib.compat import OrderedDict
46 from rhodecode.lib.compat import OrderedDict
47 from rhodecode.lib.utils import jsonify
47 from rhodecode.lib.utils import jsonify
48 from rhodecode.lib.utils2 import (
48 from rhodecode.lib.utils2 import (
49 safe_int, safe_str, str2bool, safe_unicode, UnsafeAttributeDict)
49 safe_int, safe_str, str2bool, safe_unicode, StrictAttributeDict)
50 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
50 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
51 from rhodecode.lib.vcs.exceptions import (
51 from rhodecode.lib.vcs.exceptions import (
52 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError,
52 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError,
@@ -150,6 +150,7 b' class PullrequestsController(BaseRepoCon'
150
150
151 c.diffset = codeblocks.DiffSet(
151 c.diffset = codeblocks.DiffSet(
152 repo_name=c.repo_name,
152 repo_name=c.repo_name,
153 source_repo_name=c.source_repo.repo_name,
153 source_node_getter=_node_getter(target_commit),
154 source_node_getter=_node_getter(target_commit),
154 target_node_getter=_node_getter(source_commit),
155 target_node_getter=_node_getter(source_commit),
155 comments=inline_comments
156 comments=inline_comments
@@ -714,17 +715,17 b' class PullrequestsController(BaseRepoCon'
714 def is_closed(self):
715 def is_closed(self):
715 return pull_request_obj.is_closed()
716 return pull_request_obj.is_closed()
716
717
717 attrs = UnsafeAttributeDict(pull_request_obj.get_api_data())
718 attrs = StrictAttributeDict(pull_request_obj.get_api_data())
718
719
719 attrs.author = UnsafeAttributeDict(
720 attrs.author = StrictAttributeDict(
720 pull_request_obj.author.get_api_data())
721 pull_request_obj.author.get_api_data())
721 if pull_request_obj.target_repo:
722 if pull_request_obj.target_repo:
722 attrs.target_repo = UnsafeAttributeDict(
723 attrs.target_repo = StrictAttributeDict(
723 pull_request_obj.target_repo.get_api_data())
724 pull_request_obj.target_repo.get_api_data())
724 attrs.target_repo.clone_url = pull_request_obj.target_repo.clone_url
725 attrs.target_repo.clone_url = pull_request_obj.target_repo.clone_url
725
726
726 if pull_request_obj.source_repo:
727 if pull_request_obj.source_repo:
727 attrs.source_repo = UnsafeAttributeDict(
728 attrs.source_repo = StrictAttributeDict(
728 pull_request_obj.source_repo.get_api_data())
729 pull_request_obj.source_repo.get_api_data())
729 attrs.source_repo.clone_url = pull_request_obj.source_repo.clone_url
730 attrs.source_repo.clone_url = pull_request_obj.source_repo.clone_url
730
731
@@ -733,76 +734,62 b' class PullrequestsController(BaseRepoCon'
733
734
734 attrs.shadow_merge_ref = _org_pull_request_obj.shadow_merge_ref
735 attrs.shadow_merge_ref = _org_pull_request_obj.shadow_merge_ref
735
736
736 pull_request_ver = PullRequestDisplay(attrs)
737 pull_request_display_obj = PullRequestDisplay(attrs)
737
738
738 return _org_pull_request_obj, pull_request_obj, \
739 return _org_pull_request_obj, pull_request_obj, \
739 pull_request_ver, at_version
740 pull_request_display_obj, at_version
740
741
741 @LoginRequired()
742 @LoginRequired()
742 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
743 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
743 'repository.admin')
744 'repository.admin')
744 def show(self, repo_name, pull_request_id):
745 def show(self, repo_name, pull_request_id):
745 pull_request_id = safe_int(pull_request_id)
746 pull_request_id = safe_int(pull_request_id)
747 version = request.GET.get('version')
746
748
747 version = request.GET.get('version')
749 (pull_request_latest,
748 pull_request_latest, \
750 pull_request_at_ver,
749 pull_request, \
751 pull_request_display_obj,
750 pull_request_ver, \
752 at_version) = self._get_pr_version(pull_request_id, version=version)
751 at_version = self._get_pr_version(pull_request_id, version=version)
752
753
753 c.template_context['pull_request_data']['pull_request_id'] = \
754 c.template_context['pull_request_data']['pull_request_id'] = \
754 pull_request_id
755 pull_request_id
755
756
756 # pull_requests repo_name we opened it against
757 # pull_requests repo_name we opened it against
757 # ie. target_repo must match
758 # ie. target_repo must match
758 if repo_name != pull_request.target_repo.repo_name:
759 if repo_name != pull_request_at_ver.target_repo.repo_name:
759 raise HTTPNotFound
760 raise HTTPNotFound
760
761
761 c.shadow_clone_url = PullRequestModel().get_shadow_clone_url(
762 c.shadow_clone_url = PullRequestModel().get_shadow_clone_url(
762 pull_request)
763 pull_request_at_ver)
763
764
765 pr_closed = pull_request_latest.is_closed()
764 if at_version:
766 if at_version:
765 c.allowed_to_change_status = False
767 c.allowed_to_change_status = False
768 c.allowed_to_update = False
769 c.allowed_to_merge = False
770 c.allowed_to_delete = False
771 c.allowed_to_comment = False
766 else:
772 else:
767 c.allowed_to_change_status = PullRequestModel(). \
773 c.allowed_to_change_status = PullRequestModel(). \
768 check_user_change_status(pull_request, c.rhodecode_user)
774 check_user_change_status(pull_request_at_ver, c.rhodecode_user)
769
770 if at_version:
771 c.allowed_to_update = False
772 else:
773 c.allowed_to_update = PullRequestModel().check_user_update(
775 c.allowed_to_update = PullRequestModel().check_user_update(
774 pull_request, c.rhodecode_user) and not pull_request.is_closed()
776 pull_request_latest, c.rhodecode_user) and not pr_closed
775
776 if at_version:
777 c.allowed_to_merge = False
778 else:
779 c.allowed_to_merge = PullRequestModel().check_user_merge(
777 c.allowed_to_merge = PullRequestModel().check_user_merge(
780 pull_request, c.rhodecode_user) and not pull_request.is_closed()
778 pull_request_latest, c.rhodecode_user) and not pr_closed
781
782 if at_version:
783 c.allowed_to_delete = False
784 else:
785 c.allowed_to_delete = PullRequestModel().check_user_delete(
779 c.allowed_to_delete = PullRequestModel().check_user_delete(
786 pull_request, c.rhodecode_user) and not pull_request.is_closed()
780 pull_request_latest, c.rhodecode_user) and not pr_closed
787
781 c.allowed_to_comment = not pr_closed
788 if at_version:
789 c.allowed_to_comment = False
790 else:
791 c.allowed_to_comment = not pull_request.is_closed()
792
782
793 cc_model = ChangesetCommentsModel()
783 cc_model = ChangesetCommentsModel()
794
784
795 c.pull_request_reviewers = pull_request.reviewers_statuses()
785 c.pull_request_reviewers = pull_request_at_ver.reviewers_statuses()
796
786 c.pull_request_review_status = pull_request_at_ver.calculated_review_status()
797 c.pull_request_review_status = pull_request.calculated_review_status()
798 c.pr_merge_status, c.pr_merge_msg = PullRequestModel().merge_status(
787 c.pr_merge_status, c.pr_merge_msg = PullRequestModel().merge_status(
799 pull_request)
788 pull_request_at_ver)
800 c.approval_msg = None
789 c.approval_msg = None
801 if c.pull_request_review_status != ChangesetStatus.STATUS_APPROVED:
790 if c.pull_request_review_status != ChangesetStatus.STATUS_APPROVED:
802 c.approval_msg = _('Reviewer approval is pending.')
791 c.approval_msg = _('Reviewer approval is pending.')
803 c.pr_merge_status = False
792 c.pr_merge_status = False
804 # load compare data into template context
805 enable_comments = not pull_request.is_closed()
806
793
807 # inline comments
794 # inline comments
808 c.inline_comments = cc_model.get_inline_comments(
795 c.inline_comments = cc_model.get_inline_comments(
@@ -812,17 +799,20 b' class PullrequestsController(BaseRepoCon'
812 c.inline_cnt = cc_model.get_inline_comments_count(
799 c.inline_cnt = cc_model.get_inline_comments_count(
813 c.inline_comments, version=at_version)
800 c.inline_comments, version=at_version)
814
801
802 # load compare data into template context
803 enable_comments = not pr_closed
815 self._load_compare_data(
804 self._load_compare_data(
816 pull_request, c.inline_comments, enable_comments=enable_comments)
805 pull_request_at_ver,
806 c.inline_comments, enable_comments=enable_comments)
817
807
818 # outdated comments
808 # outdated comments
819 c.outdated_comments = {}
809 c.outdated_comments = {}
820 c.outdated_cnt = 0
810 c.outdated_cnt = 0
821
811
822 if ChangesetCommentsModel.use_outdated_comments(pull_request):
812 if ChangesetCommentsModel.use_outdated_comments(pull_request_latest):
823 c.outdated_comments = cc_model.get_outdated_comments(
813 c.outdated_comments = cc_model.get_outdated_comments(
824 c.rhodecode_db_repo.repo_id,
814 c.rhodecode_db_repo.repo_id,
825 pull_request=pull_request)
815 pull_request=pull_request_at_ver)
826
816
827 # Count outdated comments and check for deleted files
817 # Count outdated comments and check for deleted files
828 for file_name, lines in c.outdated_comments.iteritems():
818 for file_name, lines in c.outdated_comments.iteritems():
@@ -851,7 +841,7 b' class PullrequestsController(BaseRepoCon'
851 c.commit_statuses = statuses
841 c.commit_statuses = statuses
852
842
853 c.ancestor = None # TODO: add ancestor here
843 c.ancestor = None # TODO: add ancestor here
854 c.pull_request = pull_request_ver
844 c.pull_request = pull_request_display_obj
855 c.pull_request_latest = pull_request_latest
845 c.pull_request_latest = pull_request_latest
856 c.at_version = at_version
846 c.at_version = at_version
857
847
@@ -353,6 +353,7 b' class DiffSet(object):'
353 HL_NONE = 'NONE' # no highlighting, fastest
353 HL_NONE = 'NONE' # no highlighting, fastest
354
354
355 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
355 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
356 source_repo_name=None,
356 source_node_getter=lambda filename: None,
357 source_node_getter=lambda filename: None,
357 target_node_getter=lambda filename: None,
358 target_node_getter=lambda filename: None,
358 source_nodes=None, target_nodes=None,
359 source_nodes=None, target_nodes=None,
@@ -368,6 +369,7 b' class DiffSet(object):'
368 self.source_nodes = source_nodes or {}
369 self.source_nodes = source_nodes or {}
369 self.target_nodes = target_nodes or {}
370 self.target_nodes = target_nodes or {}
370 self.repo_name = repo_name
371 self.repo_name = repo_name
372 self.source_repo_name = source_repo_name or repo_name
371 self.comments = comments or {}
373 self.comments = comments or {}
372 self.max_file_size_limit = max_file_size_limit
374 self.max_file_size_limit = max_file_size_limit
373
375
@@ -379,6 +381,7 b' class DiffSet(object):'
379 files=[],
381 files=[],
380 limited_diff=isinstance(patchset, LimitedDiffContainer),
382 limited_diff=isinstance(patchset, LimitedDiffContainer),
381 repo_name=self.repo_name,
383 repo_name=self.repo_name,
384 source_repo_name=self.source_repo_name,
382 source_ref=source_ref,
385 source_ref=source_ref,
383 target_ref=target_ref,
386 target_ref=target_ref,
384 ))
387 ))
@@ -656,7 +656,11 b' def extract_mentioned_users(s):'
656 return sorted(list(usrs), key=lambda k: k.lower())
656 return sorted(list(usrs), key=lambda k: k.lower())
657
657
658
658
659 class UnsafeAttributeDict(dict):
659 class StrictAttributeDict(dict):
660 """
661 Strict Version of Attribute dict which raises an Attribute error when
662 requested attribute is not set
663 """
660 def __getattr__(self, attr):
664 def __getattr__(self, attr):
661 try:
665 try:
662 return self[attr]
666 return self[attr]
@@ -637,4 +637,4 b' var CommentsController = function() { /*'
637 firefoxAnchorFix();
637 firefoxAnchorFix();
638 };
638 };
639
639
640 }; No newline at end of file
640 };
@@ -341,7 +341,7 b' from rhodecode.lib.diffs import NEW_FILE'
341 %if filediff.patch['operation'] in ['A', 'M']:
341 %if filediff.patch['operation'] in ['A', 'M']:
342 <a
342 <a
343 class="tooltip"
343 class="tooltip"
344 href="${h.url('files_home',repo_name=filediff.diffset.repo_name,f_path=filediff.target_file_path,revision=filediff.diffset.target_ref)}"
344 href="${h.url('files_home',repo_name=filediff.diffset.source_repo_name,f_path=filediff.target_file_path,revision=filediff.diffset.target_ref)}"
345 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
345 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
346 >
346 >
347 ${_('Show file after')}
347 ${_('Show file after')}
General Comments 0
You need to be logged in to leave comments. Login now