Skip to content

Commit 6886e4a

Browse files
authored
Merge branch 'master' into master
2 parents f0fea19 + 58d5ae7 commit 6886e4a

5 files changed

Lines changed: 25 additions & 12 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ commit-hook:
4242
full-clean: check-docker
4343
docker images -q $(IMAGE_PREFIX)$(COMPONENT) | xargs docker rmi -f
4444

45-
postgres:
45+
postgres: check-docker
4646
docker start postgres || docker run --restart="always" -d -p 5432:5432 --name postgres postgres:9.3
4747
docker exec postgres createdb -U postgres deis 2>/dev/null || true
4848
@echo "To use postgres for local development:"

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ helmc install workflow-dev
5050

5151
### Postgresql
5252

53-
Postgresql can be installed via `homebrew`:
54-
55-
```
56-
brew install postgresql
57-
```
58-
59-
Or via your package manager. For example, on Debian Jessie:
60-
53+
The application and tests use PostgreSQL. To start a local instance via Docker, run `make postgres` and set the following in your shell:
6154
```
62-
apt-get install postgresql libpq-dev
55+
export PGHOST=`docker-machine ip $(docker-machine active) 2>/dev/null || echo 127.0.0.1`
56+
export PGPORT=5432
57+
export PGUSER=postgres
6358
```
6459

6560
### Python

rootfs/api/permissions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from rest_framework import exceptions
33
from rest_framework import permissions
44
from django.conf import settings
5-
from django.contrib.auth.models import AnonymousUser
5+
from django.contrib.auth.models import AnonymousUser, User
66

77
from api import models
88

@@ -109,6 +109,8 @@ def has_permission(self, request, view):
109109
if settings.REGISTRATION_MODE == 'enabled':
110110
return True
111111
elif settings.REGISTRATION_MODE == 'admin_only':
112+
if not User.objects.filter(is_superuser=True).exists():
113+
return True
112114
return request.user.is_superuser
113115
else:
114116
raise Exception("{} is not a valid registation mode"

rootfs/api/tests/test_perm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.contrib.auth.models import User
22
from rest_framework.authtoken.models import Token
3+
from django.test.utils import override_settings
34
from api.tests import DeisTestCase
45

56

@@ -32,6 +33,21 @@ def test_first_signup(self):
3233
self.assertEqual(response.status_code, 201, response.data)
3334
self.assertFalse(response.data['is_superuser'])
3435

36+
@override_settings(REGISTRATION_MODE="admin_only")
37+
def test_first_signup_admin_only(self):
38+
# register a first user
39+
username, password = 'firstuser', 'password'
40+
email = 'autotest@deis.io'
41+
submit = {
42+
'username': username,
43+
'password': password,
44+
'email': email,
45+
}
46+
url = '/v2/auth/register'
47+
response = self.client.post(url, submit)
48+
self.assertEqual(response.status_code, 201, response.data)
49+
self.assertTrue(response.data['is_superuser'])
50+
3551
def test_list(self):
3652
submit = {
3753
'username': 'firstuser',

rootfs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Django==1.10.2
44
django-cors-middleware==1.3.1
55
django-guardian==1.4.6
66
djangorestframework==3.4.7
7-
docker-py==1.10.3
7+
docker-py==1.10.4
88
gunicorn==19.6.0
99
jmespath==0.9.0
1010
jsonfield==1.0.3

0 commit comments

Comments
 (0)