Browse Source

Fix PR view when fork was deleted

Julen Landa Alustiza 4 years ago
parent
commit
38a4ae1dd5

+ 10 - 5
pagure/templates/repo_pull_request.html

@@ -84,7 +84,7 @@
         </div>
         <div class="mt-2">
           <small>
-            {% if pull_request.remote_git or pull_request.project_from.is_fork %}
+            {% if pull_request.remote_git or (pull_request.project_from and pull_request.project_from.is_fork) %}
             <span class="badge badge-light badge-pill border border-secondary font-1em">
               {% if pull_request.remote_git %}
                 <i class="fa fa-globe"></i>
@@ -99,8 +99,7 @@
                 {%- endif -%}
                 {{pull_request.project_from.name}}
               {% endif %}
-              </span>
-            {% endif %}
+            </span>
             <a href="{{ url_for('ui_ns.view_tree',
                     repo=pull_request.project_from.name,
                     username=pull_request.project_from.user.user
@@ -111,7 +110,13 @@
                   class="badge badge-secondary badge-pill border border-secondary font-1em">
                 <span class="fa fa-random"></span>
                 {{ pull_request.branch_from }}
-              </a>
+            </a>
+            {% else %}
+            <span class="badge badge-light badge-pill border border-seconday font-1em">
+              <i class="fa fa-question"></i>
+              Unknown source
+            </span>
+            {% endif %}
           &nbsp;into&nbsp;
             <a href="{{ url_for('ui_ns.view_tree',
                       repo=pull_request.project.name,
@@ -292,7 +297,7 @@
     <div class="list-group">
         {% for commit in diff_commits %}
 
-            {% if pull_request.status and pull_request.project_from.is_fork %}
+            {% if pull_request.status and (pull_request.project_from and pull_request.project_from.is_fork) %}
               {% set commit_link = url_for(
                 'ui_ns.view_commit',
                 repo=pull_request.project_from.name,

+ 1 - 0
pagure/ui/fork.py

@@ -331,6 +331,7 @@ def request_pull(repo, requestid, username=None, namespace=None):
     can_delete_branch = (
         pagure_config.get("ALLOW_DELETE_BRANCH", True)
         and not request.remote_git
+        and request.project_from
         and pagure.utils.is_repo_committer(request.project_from)
     )
     return flask.render_template(

+ 3 - 1
tests/test_pagure_merge_pr_no_fork.py

@@ -205,7 +205,9 @@ class PagureMergePrNoForkTest(tests.Modeltests):
         user = tests.FakeUser(username="pingou")
         with tests.user_set(self.app.application, user):
             data = {"csrf_token": self.get_csrf()}
-
+            # Check the PR view on UI
+            output = self.app.get("/test/pull-request/1")
+            self.assertEqual(output.status_code, 200)
             # Merge PR
             output = self.app.post(
                 "/test/pull-request/1/merge", data=data, follow_redirects=True