Skip to content

Commit

Permalink
Do not show Build button when user is not project admin (#3309)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
humitos authored and agjohnson committed Nov 27, 2017
1 parent 08a4349 commit ebf9a40
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 15 additions & 2 deletions readthedocs/rtd_tests/tests/test_privacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/templates/builds/build_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load i18n %}

{% load pagination_tags %}
{% load privacy_tags %}
{% load projects_tags %}

{% block title %}Builds{% endblock %}
Expand Down Expand Up @@ -37,7 +38,7 @@
<div class="module-wrapper">

{% block build_versions %}
{% if versions %}
{% if versions and request.user|is_admin:project %}
<div class="module-header">
<div style="float:right;">
<form method="post" action="{% url "builds_project_list" project.slug %}">
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/core/project_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h3>{% trans "Versions" %}</h3>
</div>

{% block build_versions %}
{% if versions %}
{% if versions and request.user|is_admin:project %}
<div class="build_a_version">
<h3>{% trans "Build a version" %}</h3>
<div class="version_right">
Expand Down

0 comments on commit ebf9a40

Please sign in to comment.