From 1de6c754c6d400f6b44ae659daa9369243a31298 Mon Sep 17 00:00:00 2001
From: Pradeep CE (cep) <breathingcode@gmail.com>
Date: Feb 12 2017 05:57:28 +0000
Subject: [PATCH 1/5] Fix traceback when trying to edit file online


---

diff --git a/pagure/templates/edit_file.html b/pagure/templates/edit_file.html
index 83675d5..9d162d8 100644
--- a/pagure/templates/edit_file.html
+++ b/pagure/templates/edit_file.html
@@ -21,9 +21,8 @@
             identifier=branchname)
       }}"><span class="oi" data-glyph="random"></span>&nbsp; {{ branchname }}</a></li>{%
     for file in filename.split('/') %}
-      {% if loop.first %}
       {% set path = file %}
-      {% else %}
+      {% if not loop.first %}
       {% set path = path + '/' + file %}
       {% endif %}
       {% if loop.index != loop.length %}<li><a

From 3e527ed1ad0be5796a9fb9bfeef6e85b95fa249d Mon Sep 17 00:00:00 2001
From: Pradeep CE (cep) <breathingcode@gmail.com>
Date: Feb 12 2017 05:57:29 +0000
Subject: [PATCH 2/5] Fix path not defined in file.html


---

diff --git a/pagure/templates/file.html b/pagure/templates/file.html
index 1268461..54a31a4 100644
--- a/pagure/templates/file.html
+++ b/pagure/templates/file.html
@@ -74,6 +74,10 @@
             </a>
           </li>
         {% for file in filename.split('/') %}
+          {% set path = file %}
+          {% if not loop.first %}
+          {% set path = path + '/' + file %}
+          {% endif %}
           {% if loop.index != loop.length
         %}<li><a href="{{ url_for('view_file',
                 repo=repo.name,

From c32d16de698be2a12699a8b45f9d335747327495 Mon Sep 17 00:00:00 2001
From: Pradeep CE (cep) <breathingcode@gmail.com>
Date: Feb 12 2017 05:57:29 +0000
Subject: [PATCH 3/5] Fix incorrect value for variable 'path'


Something like `{% set path = path + '/' + file %}` doesn't seem to
work because in Jinja2, because the variables set inside loops
don't seem to persist between iterations.

This approach works around that limitation.

---

diff --git a/pagure/templates/edit_file.html b/pagure/templates/edit_file.html
index 9d162d8..62b67e0 100644
--- a/pagure/templates/edit_file.html
+++ b/pagure/templates/edit_file.html
@@ -21,10 +21,7 @@
             identifier=branchname)
       }}"><span class="oi" data-glyph="random"></span>&nbsp; {{ branchname }}</a></li>{%
     for file in filename.split('/') %}
-      {% set path = file %}
-      {% if not loop.first %}
-      {% set path = path + '/' + file %}
-      {% endif %}
+      {% set path = '/'.join(filename.split('/')[:loop.index]) %}
       {% if loop.index != loop.length %}<li><a
       href="{{ url_for('view_file',
             repo=repo.name,
diff --git a/pagure/templates/file.html b/pagure/templates/file.html
index 54a31a4..c2c6595 100644
--- a/pagure/templates/file.html
+++ b/pagure/templates/file.html
@@ -74,10 +74,7 @@
             </a>
           </li>
         {% for file in filename.split('/') %}
-          {% set path = file %}
-          {% if not loop.first %}
-          {% set path = path + '/' + file %}
-          {% endif %}
+          {% set path = '/'.join(filename.split('/')[:loop.index]) %}
           {% if loop.index != loop.length
         %}<li><a href="{{ url_for('view_file',
                 repo=repo.name,

From f732d4fceb0bb1cb6366d0e95d596ff90088642f Mon Sep 17 00:00:00 2001
From: Pradeep CE (cep) <breathingcode@gmail.com>
Date: Feb 12 2017 05:57:29 +0000
Subject: [PATCH 4/5] Add tests for nav links when viewing or editing a file online


---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 68f0902..8b02b82 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -1683,6 +1683,15 @@ class PagureFlaskRepotests(tests.Modeltests):
         self.assertIn(
             '<a href="/test/blob/master/f/folder1/folder2">', output.data)
 
+        # Verify the nav links correctly when viewing a nested folder/file.
+        output = self.app.get('/test/blob/master/f/folder1/folder2')
+        self.assertEqual(output.status_code, 200)
+        self.assertIn(
+            '<li><a href="/test/blob/master/f/folder1">\n'
+            '            <span class="oi" data-glyph="folder">'
+            '</span>&nbsp; folder1</a>\n'
+            '          </li>', output.data)
+
         # View by image name -- with a non-existant file
         output = self.app.get('/test/blob/sources/f/testfoo.jpg')
         self.assertEqual(output.status_code, 404)
@@ -1729,6 +1738,16 @@ class PagureFlaskRepotests(tests.Modeltests):
             os.path.join(self.path, 'forks', 'pingou', 'test3.git'),
             ncommits=10)
 
+        # Verify the nav links correctly when viewing a file/folder in a fork.
+        output = self.app.get(
+            '/fork/pingou/test3/blob/master/f/folder1/folder2/file')
+        self.assertEqual(output.status_code, 200)
+        self.assertIn(
+            '<li><a href="/fork/pingou/test3/blob/master/f/folder1">\n'
+            '            <span class="oi" data-glyph="folder"></span>&nbsp; '
+            'folder1</a>\n          </li>', output.data)
+
+
         output = self.app.get('/fork/pingou/test3/blob/master/f/sources')
         self.assertEqual(output.status_code, 200)
         self.assertIn('<table class="code_table">', output.data)
@@ -3033,6 +3052,15 @@ index 0000000..fb7093d
                 '<textarea id="textareaCode" name="content">foo\n bar</textarea>',
                 output.data)
 
+            # Verify the nav links correctly when editing a file.
+            output = self.app.get('/test/blob/master/f/folder1/folder2/file')
+            self.assertEqual(output.status_code, 200)
+            self.assertIn(
+                '<li><a href="/test/blob/master/f/folder1">\n'
+                '            <span class="oi" data-glyph="folder">'
+                '</span>&nbsp; folder1</a>\n'
+                '          </li>', output.data)
+
             csrf_token = output.data.split(
                 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
 
@@ -3113,6 +3141,16 @@ index 0000000..fb7093d
                 os.path.join(self.path, 'forks', 'pingou', 'test3.git'),
                 ncommits=10)
 
+            # Verify the nav links correctly when editing a file in a fork.
+            output = self.app.get(
+                '/fork/pingou/test3/edit/master/f/folder1/folder2/file')
+            self.assertEqual(output.status_code, 200)
+            self.assertIn(
+                '<li><a\n      '
+                'href="/fork/pingou/test3/blob/master/f/folder1"\n        >'
+                '<span class="oi" data-glyph="folder"></span>&nbsp; folder1'
+                '</a>\n        </li>', output.data)
+
             output = self.app.get('/fork/pingou/test3/edit/master/f/sources')
             self.assertEqual(output.status_code, 200)
             self.assertIn(

From 1cd6b998970e504496b585013e8774f81b24f38f Mon Sep 17 00:00:00 2001
From: Pradeep CE (cep) <breathingcode@gmail.com>
Date: Feb 12 2017 05:57:29 +0000
Subject: [PATCH 5/5] Make tests fail if nav links are incorrect for edit_file and view_file


This ensures that we will know if the links break in the future.

---

diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py
index 8b02b82..2454ef5 100644
--- a/tests/test_pagure_flask_ui_repo.py
+++ b/tests/test_pagure_flask_ui_repo.py
@@ -1684,12 +1684,12 @@ class PagureFlaskRepotests(tests.Modeltests):
             '<a href="/test/blob/master/f/folder1/folder2">', output.data)
 
         # Verify the nav links correctly when viewing a nested folder/file.
-        output = self.app.get('/test/blob/master/f/folder1/folder2')
+        output = self.app.get('/test/blob/master/f/folder1/folder2/file')
         self.assertEqual(output.status_code, 200)
         self.assertIn(
-            '<li><a href="/test/blob/master/f/folder1">\n'
+            '<li><a href="/test/blob/master/f/folder1/folder2">\n'
             '            <span class="oi" data-glyph="folder">'
-            '</span>&nbsp; folder1</a>\n'
+            '</span>&nbsp; folder2</a>\n'
             '          </li>', output.data)
 
         # View by image name -- with a non-existant file
@@ -1743,9 +1743,9 @@ class PagureFlaskRepotests(tests.Modeltests):
             '/fork/pingou/test3/blob/master/f/folder1/folder2/file')
         self.assertEqual(output.status_code, 200)
         self.assertIn(
-            '<li><a href="/fork/pingou/test3/blob/master/f/folder1">\n'
+            '<li><a href="/fork/pingou/test3/blob/master/f/folder1/folder2">\n'
             '            <span class="oi" data-glyph="folder"></span>&nbsp; '
-            'folder1</a>\n          </li>', output.data)
+            'folder2</a>\n          </li>', output.data)
 
 
         output = self.app.get('/fork/pingou/test3/blob/master/f/sources')
@@ -3056,9 +3056,9 @@ index 0000000..fb7093d
             output = self.app.get('/test/blob/master/f/folder1/folder2/file')
             self.assertEqual(output.status_code, 200)
             self.assertIn(
-                '<li><a href="/test/blob/master/f/folder1">\n'
+                '<li><a href="/test/blob/master/f/folder1/folder2">\n'
                 '            <span class="oi" data-glyph="folder">'
-                '</span>&nbsp; folder1</a>\n'
+                '</span>&nbsp; folder2</a>\n'
                 '          </li>', output.data)
 
             csrf_token = output.data.split(
@@ -3147,9 +3147,9 @@ index 0000000..fb7093d
             self.assertEqual(output.status_code, 200)
             self.assertIn(
                 '<li><a\n      '
-                'href="/fork/pingou/test3/blob/master/f/folder1"\n        >'
-                '<span class="oi" data-glyph="folder"></span>&nbsp; folder1'
-                '</a>\n        </li>', output.data)
+                'href="/fork/pingou/test3/blob/master/f/folder1/folder2"\n'
+                '        ><span class="oi" data-glyph="folder"></span>&nbsp; '
+                'folder2</a>\n        </li>', output.data)
 
             output = self.app.get('/fork/pingou/test3/edit/master/f/sources')
             self.assertEqual(output.status_code, 200)

