##// 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 46 from rhodecode.lib.compat import OrderedDict
47 47 from rhodecode.lib.utils import jsonify
48 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 50 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
51 51 from rhodecode.lib.vcs.exceptions import (
52 52 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError,
@@ -150,6 +150,7 b' class PullrequestsController(BaseRepoCon'
150 150
151 151 c.diffset = codeblocks.DiffSet(
152 152 repo_name=c.repo_name,
153 source_repo_name=c.source_repo.repo_name,
153 154 source_node_getter=_node_getter(target_commit),
154 155 target_node_getter=_node_getter(source_commit),
155 156 comments=inline_comments
@@ -714,17 +715,17 b' class PullrequestsController(BaseRepoCon'
714 715 def is_closed(self):
715 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 721 pull_request_obj.author.get_api_data())
721 722 if pull_request_obj.target_repo:
722 attrs.target_repo = UnsafeAttributeDict(
723 attrs.target_repo = StrictAttributeDict(
723 724 pull_request_obj.target_repo.get_api_data())
724 725 attrs.target_repo.clone_url = pull_request_obj.target_repo.clone_url
725 726
726 727 if pull_request_obj.source_repo:
727 attrs.source_repo = UnsafeAttributeDict(
728 attrs.source_repo = StrictAttributeDict(
728 729 pull_request_obj.source_repo.get_api_data())
729 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 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 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 742 @LoginRequired()
742 743 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
743 744 'repository.admin')
744 745 def show(self, repo_name, pull_request_id):
745 746 pull_request_id = safe_int(pull_request_id)
747 version = request.GET.get('version')
746 748
747 version = request.GET.get('version')
748 pull_request_latest, \
749 pull_request, \
750 pull_request_ver, \
751 at_version = self._get_pr_version(pull_request_id, version=version)
749 (pull_request_latest,
750 pull_request_at_ver,
751 pull_request_display_obj,
752 at_version) = self._get_pr_version(pull_request_id, version=version)
752 753
753 754 c.template_context['pull_request_data']['pull_request_id'] = \
754 755 pull_request_id
755 756
756 757 # pull_requests repo_name we opened it against
757 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 760 raise HTTPNotFound
760 761
761 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 766 if at_version:
765 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 772 else:
767 773 c.allowed_to_change_status = PullRequestModel(). \
768 check_user_change_status(pull_request, c.rhodecode_user)
769
770 if at_version:
771 c.allowed_to_update = False
772 else:
774 check_user_change_status(pull_request_at_ver, c.rhodecode_user)
773 775 c.allowed_to_update = PullRequestModel().check_user_update(
774 pull_request, c.rhodecode_user) and not pull_request.is_closed()
775
776 if at_version:
777 c.allowed_to_merge = False
778 else:
776 pull_request_latest, c.rhodecode_user) and not pr_closed
779 777 c.allowed_to_merge = PullRequestModel().check_user_merge(
780 pull_request, c.rhodecode_user) and not pull_request.is_closed()
781
782 if at_version:
783 c.allowed_to_delete = False
784 else:
778 pull_request_latest, c.rhodecode_user) and not pr_closed
785 779 c.allowed_to_delete = PullRequestModel().check_user_delete(
786 pull_request, c.rhodecode_user) and not pull_request.is_closed()
787
788 if at_version:
789 c.allowed_to_comment = False
790 else:
791 c.allowed_to_comment = not pull_request.is_closed()
780 pull_request_latest, c.rhodecode_user) and not pr_closed
781 c.allowed_to_comment = not pr_closed
792 782
793 783 cc_model = ChangesetCommentsModel()
794 784
795 c.pull_request_reviewers = pull_request.reviewers_statuses()
796
797 c.pull_request_review_status = pull_request.calculated_review_status()
785 c.pull_request_reviewers = pull_request_at_ver.reviewers_statuses()
786 c.pull_request_review_status = pull_request_at_ver.calculated_review_status()
798 787 c.pr_merge_status, c.pr_merge_msg = PullRequestModel().merge_status(
799 pull_request)
788 pull_request_at_ver)
800 789 c.approval_msg = None
801 790 if c.pull_request_review_status != ChangesetStatus.STATUS_APPROVED:
802 791 c.approval_msg = _('Reviewer approval is pending.')
803 792 c.pr_merge_status = False
804 # load compare data into template context
805 enable_comments = not pull_request.is_closed()
806 793
807 794 # inline comments
808 795 c.inline_comments = cc_model.get_inline_comments(
@@ -812,17 +799,20 b' class PullrequestsController(BaseRepoCon'
812 799 c.inline_cnt = cc_model.get_inline_comments_count(
813 800 c.inline_comments, version=at_version)
814 801
802 # load compare data into template context
803 enable_comments = not pr_closed
815 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 808 # outdated comments
819 809 c.outdated_comments = {}
820 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 813 c.outdated_comments = cc_model.get_outdated_comments(
824 814 c.rhodecode_db_repo.repo_id,
825 pull_request=pull_request)
815 pull_request=pull_request_at_ver)
826 816
827 817 # Count outdated comments and check for deleted files
828 818 for file_name, lines in c.outdated_comments.iteritems():
@@ -851,7 +841,7 b' class PullrequestsController(BaseRepoCon'
851 841 c.commit_statuses = statuses
852 842
853 843 c.ancestor = None # TODO: add ancestor here
854 c.pull_request = pull_request_ver
844 c.pull_request = pull_request_display_obj
855 845 c.pull_request_latest = pull_request_latest
856 846 c.at_version = at_version
857 847
@@ -353,6 +353,7 b' class DiffSet(object):'
353 353 HL_NONE = 'NONE' # no highlighting, fastest
354 354
355 355 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
356 source_repo_name=None,
356 357 source_node_getter=lambda filename: None,
357 358 target_node_getter=lambda filename: None,
358 359 source_nodes=None, target_nodes=None,
@@ -368,6 +369,7 b' class DiffSet(object):'
368 369 self.source_nodes = source_nodes or {}
369 370 self.target_nodes = target_nodes or {}
370 371 self.repo_name = repo_name
372 self.source_repo_name = source_repo_name or repo_name
371 373 self.comments = comments or {}
372 374 self.max_file_size_limit = max_file_size_limit
373 375
@@ -379,6 +381,7 b' class DiffSet(object):'
379 381 files=[],
380 382 limited_diff=isinstance(patchset, LimitedDiffContainer),
381 383 repo_name=self.repo_name,
384 source_repo_name=self.source_repo_name,
382 385 source_ref=source_ref,
383 386 target_ref=target_ref,
384 387 ))
@@ -656,7 +656,11 b' def extract_mentioned_users(s):'
656 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 664 def __getattr__(self, attr):
661 665 try:
662 666 return self[attr]
@@ -637,4 +637,4 b' var CommentsController = function() { /*'
637 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 341 %if filediff.patch['operation'] in ['A', 'M']:
342 342 <a
343 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 345 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
346 346 >
347 347 ${_('Show file after')}
General Comments 0
You need to be logged in to leave comments. Login now