Skip to content

Commit 937e8f8

Browse files
authored
Merge pull request #4851 from stsewd/hide-edit-on-when-tags
Hide "edit on" when the version is a tag
2 parents f9a839d + 48ac0f4 commit 937e8f8

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

readthedocs/builds/models.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,55 @@
22
"""Models for the builds app."""
33

44
from __future__ import (
5-
absolute_import, division, print_function, unicode_literals)
5+
absolute_import,
6+
division,
7+
print_function,
8+
unicode_literals,
9+
)
610

711
import logging
812
import os.path
913
import re
10-
from builtins import object
1114
from shutil import rmtree
1215

16+
from builtins import object
1317
from django.conf import settings
1418
from django.core.urlresolvers import reverse
1519
from django.db import models
1620
from django.utils.encoding import python_2_unicode_compatible
17-
from django.utils.translation import ugettext_lazy as _
1821
from django.utils.translation import ugettext
22+
from django.utils.translation import ugettext_lazy as _
1923
from guardian.shortcuts import assign
2024
from taggit.managers import TaggableManager
2125

2226
from readthedocs.core.utils import broadcast
2327
from readthedocs.projects.constants import (
24-
BITBUCKET_URL, GITHUB_URL, GITLAB_URL, PRIVACY_CHOICES, PRIVATE)
28+
BITBUCKET_URL,
29+
GITHUB_URL,
30+
GITLAB_URL,
31+
PRIVACY_CHOICES,
32+
PRIVATE,
33+
)
2534
from readthedocs.projects.models import APIProject, Project
2635

2736
from .constants import (
28-
BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, BUILD_TYPES, LATEST,
29-
NON_REPOSITORY_VERSIONS, STABLE, TAG, VERSION_TYPES)
37+
BRANCH,
38+
BUILD_STATE,
39+
BUILD_STATE_FINISHED,
40+
BUILD_TYPES,
41+
LATEST,
42+
NON_REPOSITORY_VERSIONS,
43+
STABLE,
44+
TAG,
45+
VERSION_TYPES,
46+
)
3047
from .managers import VersionManager
3148
from .querysets import BuildQuerySet, RelatedBuildQuerySet, VersionQuerySet
3249
from .utils import (
33-
get_bitbucket_username_repo, get_github_username_repo,
34-
get_gitlab_username_repo)
50+
get_bitbucket_username_repo,
51+
get_github_username_repo,
52+
get_gitlab_username_repo,
53+
)
3554
from .version_slug import VersionSlugField
3655

3756
DEFAULT_VERSION_PRIVACY_LEVEL = getattr(
@@ -193,6 +212,10 @@ def identifier_friendly(self):
193212
return self.identifier[:8]
194213
return self.identifier
195214

215+
@property
216+
def is_editable(self):
217+
return self.type == BRANCH
218+
196219
def get_subdomain_url(self):
197220
private = self.privacy_level == PRIVATE
198221
return self.project.get_docs_url(

readthedocs/restapi/templates/restapi/footer.html

+4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@
8282
<dd>
8383
<a href="{{ github_view_url }}">View</a>
8484
</dd>
85+
{% if version.is_editable %}
8586
<dd>
8687
<a href="{{ github_edit_url }}">Edit</a>
8788
</dd>
89+
{% endif %}
8890
</dl>
8991
{% elif bitbucket_url %}
9092
<dl>
@@ -99,9 +101,11 @@
99101
<dd>
100102
<a href="{{ gitlab_view_url }}">View</a>
101103
</dd>
104+
{% if version.is_editable %}
102105
<dd>
103106
<a href="{{ gitlab_edit_url }}">Edit</a>
104107
</dd>
108+
{% endif %}
105109
</dl>
106110
{% endif %}
107111
{% endblock %}

readthedocs/rtd_tests/tests/test_footer.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import (
3-
absolute_import, division, print_function, unicode_literals)
3+
absolute_import,
4+
division,
5+
print_function,
6+
unicode_literals,
7+
)
48

59
import mock
610
from django.test import TestCase
@@ -11,13 +15,15 @@
1115
from readthedocs.core.middleware import FooterNoSessionMiddleware
1216
from readthedocs.projects.models import Project
1317
from readthedocs.restapi.views.footer_views import (
14-
footer_html, get_version_compare_data)
18+
footer_html,
19+
get_version_compare_data,
20+
)
1521
from readthedocs.rtd_tests.mocks.paths import fake_paths_by_regex
1622

1723

1824
class Testmaker(APITestCase):
1925
fixtures = ['test_data']
20-
url = '/api/v2/footer_html/?project=pip&version=latest&page=index'
26+
url = '/api/v2/footer_html/?project=pip&version=latest&page=index&docroot=/'
2127
factory = APIRequestFactory()
2228

2329
@classmethod
@@ -99,6 +105,24 @@ def test_show_version_warning(self):
99105
response = self.render()
100106
self.assertTrue(response.data['show_version_warning'])
101107

108+
def test_show_edit_on_github(self):
109+
version = self.pip.versions.get(slug=LATEST)
110+
version.type = BRANCH
111+
version.save()
112+
response = self.render()
113+
self.assertIn('On GitHub', response.data['html'])
114+
self.assertIn('View', response.data['html'])
115+
self.assertIn('Edit', response.data['html'])
116+
117+
def test_not_show_edit_on_github(self):
118+
version = self.pip.versions.get(slug=LATEST)
119+
version.type = TAG
120+
version.save()
121+
response = self.render()
122+
self.assertIn('On GitHub', response.data['html'])
123+
self.assertIn('View', response.data['html'])
124+
self.assertNotIn('Edit', response.data['html'])
125+
102126

103127
class TestVersionCompareFooter(TestCase):
104128
fixtures = ['test_data']

0 commit comments

Comments
 (0)