From ebf9a40c5bec4f427b526ee3f6eed0a69b8a603a Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 27 Nov 2017 11:50:27 -0500 Subject: [PATCH] Do not show Build button when user is not project admin (#3309) * Do not show Build button when user is not project admin Closes #3303 * Add test to check for Build section * Fix old test to make sure a public branch is listed --- readthedocs/rtd_tests/tests/test_privacy.py | 17 +++++++++++++++-- readthedocs/templates/builds/build_list.html | 3 ++- readthedocs/templates/core/project_details.html | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_privacy.py b/readthedocs/rtd_tests/tests/test_privacy.py index b44353e942e..5a4870e7b5e 100644 --- a/readthedocs/rtd_tests/tests/test_privacy.py +++ b/readthedocs/rtd_tests/tests/test_privacy.py @@ -75,8 +75,12 @@ def test_private_repo(self): self.client.login(username='eric', password='test') r = self.client.get('/projects/django-kong/') self.assertEqual(r.status_code, 200) + # Build button should appear here + self.assertContains(r, 'Build a version') r = self.client.get('/projects/django-kong/builds/') self.assertEqual(r.status_code, 200) + # Build button should appear here + self.assertContains(r, 'Build Version:') r = self.client.get('/projects/django-kong/downloads/') self.assertEqual(r.status_code, 200) @@ -100,16 +104,24 @@ def test_public_repo(self): self.client.login(username='eric', password='test') r = self.client.get('/projects/django-kong/') self.assertEqual(r.status_code, 200) + # Build button should appear here + self.assertContains(r, 'Build a version') r = self.client.get('/projects/django-kong/builds/') self.assertEqual(r.status_code, 200) + # Build button should appear here + self.assertContains(r, 'Build Version:') r = self.client.get('/projects/django-kong/downloads/') self.assertEqual(r.status_code, 200) self.client.login(username='tester', password='test') r = self.client.get('/projects/django-kong/') self.assertEqual(r.status_code, 200) + # Build button shouldn't appear here + self.assertNotContains(r, 'Build a version') r = self.client.get('/projects/django-kong/builds/') self.assertEqual(r.status_code, 200) + # Build button shouldn't appear here + self.assertNotContains(r, 'Build Version:') r = self.client.get('/projects/django-kong/downloads/') self.assertEqual(r.status_code, 200) @@ -138,13 +150,14 @@ def test_public_branch(self): self.client.login(username='eric', password='test') Version.objects.create(project=kong, identifier='test id', - verbose_name='test verbose', slug='test-slug', active=True) + verbose_name='test verbose', slug='test-slug', + active=True, built=True) self.assertEqual(Version.objects.count(), 2) self.assertEqual(Version.objects.all()[0].privacy_level, 'public') r = self.client.get('/projects/django-kong/') self.assertContains(r, 'test-slug') - # Make sure it doesn't show up as tester + # Make sure it does show up as tester self.client.login(username='tester', password='test') r = self.client.get('/projects/django-kong/') self.assertContains(r, 'test-slug') diff --git a/readthedocs/templates/builds/build_list.html b/readthedocs/templates/builds/build_list.html index f5849969210..7f4445c7c9f 100644 --- a/readthedocs/templates/builds/build_list.html +++ b/readthedocs/templates/builds/build_list.html @@ -3,6 +3,7 @@ {% load i18n %} {% load pagination_tags %} +{% load privacy_tags %} {% load projects_tags %} {% block title %}Builds{% endblock %} @@ -37,7 +38,7 @@
{% block build_versions %} - {% if versions %} + {% if versions and request.user|is_admin:project %}
diff --git a/readthedocs/templates/core/project_details.html b/readthedocs/templates/core/project_details.html index eafef979882..76fd92fabe2 100644 --- a/readthedocs/templates/core/project_details.html +++ b/readthedocs/templates/core/project_details.html @@ -55,7 +55,7 @@

{% trans "Versions" %}

{% block build_versions %} -{% if versions %} +{% if versions and request.user|is_admin:project %}

{% trans "Build a version" %}