Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide "edit on" when the version is a tag #4851

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,55 @@
"""Models for the builds app."""

from __future__ import (
absolute_import, division, print_function, unicode_literals)
absolute_import,
division,
print_function,
unicode_literals,
)

import logging
import os.path
import re
from builtins import object
from shutil import rmtree

from builtins import object
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from guardian.shortcuts import assign
from taggit.managers import TaggableManager

from readthedocs.core.utils import broadcast
from readthedocs.projects.constants import (
BITBUCKET_URL, GITHUB_URL, GITLAB_URL, PRIVACY_CHOICES, PRIVATE)
BITBUCKET_URL,
GITHUB_URL,
GITLAB_URL,
PRIVACY_CHOICES,
PRIVATE,
)
from readthedocs.projects.models import APIProject, Project

from .constants import (
BRANCH, BUILD_STATE, BUILD_STATE_FINISHED, BUILD_TYPES, LATEST,
NON_REPOSITORY_VERSIONS, STABLE, TAG, VERSION_TYPES)
BRANCH,
BUILD_STATE,
BUILD_STATE_FINISHED,
BUILD_TYPES,
LATEST,
NON_REPOSITORY_VERSIONS,
STABLE,
TAG,
VERSION_TYPES,
)
from .managers import VersionManager
from .querysets import BuildQuerySet, RelatedBuildQuerySet, VersionQuerySet
from .utils import (
get_bitbucket_username_repo, get_github_username_repo,
get_gitlab_username_repo)
get_bitbucket_username_repo,
get_github_username_repo,
get_gitlab_username_repo,
)
from .version_slug import VersionSlugField

DEFAULT_VERSION_PRIVACY_LEVEL = getattr(
Expand Down Expand Up @@ -193,6 +212,10 @@ def identifier_friendly(self):
return self.identifier[:8]
return self.identifier

@property
def is_editable(self):
return self.type == BRANCH

def get_subdomain_url(self):
private = self.privacy_level == PRIVATE
return self.project.get_docs_url(
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/restapi/templates/restapi/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@
<dd>
<a href="{{ github_view_url }}">View</a>
</dd>
{% if version.is_editable %}
<dd>
<a href="{{ github_edit_url }}">Edit</a>
</dd>
{% endif %}
</dl>
{% elif bitbucket_url %}
<dl>
Expand All @@ -99,9 +101,11 @@
<dd>
<a href="{{ gitlab_view_url }}">View</a>
</dd>
{% if version.is_editable %}
<dd>
<a href="{{ gitlab_edit_url }}">Edit</a>
</dd>
{% endif %}
</dl>
{% endif %}
{% endblock %}
Expand Down
30 changes: 27 additions & 3 deletions readthedocs/rtd_tests/tests/test_footer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import (
absolute_import, division, print_function, unicode_literals)
absolute_import,
division,
print_function,
unicode_literals,
)

import mock
from django.test import TestCase
Expand All @@ -11,13 +15,15 @@
from readthedocs.core.middleware import FooterNoSessionMiddleware
from readthedocs.projects.models import Project
from readthedocs.restapi.views.footer_views import (
footer_html, get_version_compare_data)
footer_html,
get_version_compare_data,
)
from readthedocs.rtd_tests.mocks.paths import fake_paths_by_regex


class Testmaker(APITestCase):
fixtures = ['test_data']
url = '/api/v2/footer_html/?project=pip&version=latest&page=index'
url = '/api/v2/footer_html/?project=pip&version=latest&page=index&docroot=/'
factory = APIRequestFactory()

@classmethod
Expand Down Expand Up @@ -99,6 +105,24 @@ def test_show_version_warning(self):
response = self.render()
self.assertTrue(response.data['show_version_warning'])

def test_show_edit_on_github(self):
version = self.pip.versions.get(slug=LATEST)
version.type = BRANCH
version.save()
response = self.render()
self.assertIn('On GitHub', response.data['html'])
self.assertIn('View', response.data['html'])
self.assertIn('Edit', response.data['html'])

def test_not_show_edit_on_github(self):
version = self.pip.versions.get(slug=LATEST)
version.type = TAG
version.save()
response = self.render()
self.assertIn('On GitHub', response.data['html'])
self.assertIn('View', response.data['html'])
self.assertNotIn('Edit', response.data['html'])


class TestVersionCompareFooter(TestCase):
fixtures = ['test_data']
Expand Down