-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds organization models, serializer and views
- Update to Django 1.9 for JSONField support + update RandomIDModel tests - Organization model - Organization serializer - Add permissions - API versioning - Basic List and Create API view - All basic API endpoints and views (no permissions yet) - Permissions first - Permissions depending on request method - Org users permissions + clean up - Contact validation first try - Contact validation - Archiving flow - Add django-tutelary to requirements - Makes one of email/phone required for contacts
- Loading branch information
1 parent
592ba20
commit eebfd2b
Showing
39 changed files
with
1,673 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.2 on 2016-02-04 18:38 | ||
from __future__ import unicode_literals | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0002_user_verify_email_by'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='user', | ||
name='username', | ||
field=models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=30, unique=True, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.')], verbose_name='username'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
from django.test import TestCase | ||
from django.core.urlresolvers import reverse, resolve | ||
|
||
from core.tests.url_utils import version_ns, version_url | ||
from .. import views | ||
|
||
|
||
class UserUrlsTest(TestCase): | ||
def test_account_user(self): | ||
self.assertEqual(reverse('accounts:user'), '/account/') | ||
self.assertEqual( | ||
reverse(version_ns('accounts:user')), | ||
version_url('/account/') | ||
) | ||
|
||
resolved = resolve('/account/') | ||
resolved = resolve(version_url('/account/')) | ||
self.assertEqual(resolved.func.__name__, views.AccountUser.__name__) | ||
|
||
def test_account_register(self): | ||
self.assertEqual(reverse('accounts:register'), '/account/register/') | ||
self.assertEqual( | ||
reverse(version_ns('accounts:register')), | ||
version_url('/account/register/') | ||
) | ||
|
||
resolved = resolve('/account/register/') | ||
resolved = resolve(version_url('/account/register/')) | ||
self.assertEqual(resolved.func.__name__, views.AccountRegister.__name__) | ||
|
||
def test_account_login(self): | ||
self.assertEqual(reverse('accounts:login'), '/account/login/') | ||
self.assertEqual( | ||
reverse(version_ns('accounts:login')), | ||
version_url('/account/login/') | ||
) | ||
|
||
resolved = resolve('/account/login/') | ||
resolved = resolve(version_url('/account/login/')) | ||
self.assertEqual(resolved.func.__name__, views.AccountLogin.__name__) | ||
|
||
def test_account_activate(self): | ||
self.assertEqual(reverse('accounts:activate'), '/account/activate/') | ||
self.assertEqual( | ||
reverse(version_ns('accounts:activate')), | ||
version_url('/account/activate/') | ||
) | ||
|
||
resolved = resolve('/account/activate/') | ||
resolved = resolve(version_url('/account/activate/')) | ||
self.assertEqual(resolved.func.__name__, views.AccountVerify.__name__) | ||
|
||
def test_password_reset(self): | ||
self.assertEqual(reverse('accounts:password_reset'), '/account/password/reset/') | ||
self.assertEqual( | ||
reverse(version_ns('accounts:password_reset')), | ||
version_url('/account/password/reset/') | ||
) | ||
|
||
resolved = resolve('/account/password/reset/') | ||
resolved = resolve(version_url('/account/password/reset/')) | ||
self.assertEqual(resolved.func.__name__, views.PasswordReset.__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
from django.conf.urls import patterns, url | ||
from django.conf.urls import url | ||
|
||
from . import views | ||
|
||
urlpatterns = patterns( | ||
'', | ||
urlpatterns = [ | ||
url(r'^$', views.AccountUser.as_view(), name='user'), | ||
url(r'^register/$', views.AccountRegister.as_view(), name='register'), | ||
url(r'^login/$', views.AccountLogin.as_view(), name='login'), | ||
url(r'^activate/$', views.AccountVerify.as_view(), name='activate'), | ||
url(r'^password/reset/$', views.PasswordReset.as_view(), name='password_reset'), | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"clause": [ | ||
{ | ||
"effect": "allow", | ||
"object": ["*"], | ||
"action": ["org.list"] | ||
}, { | ||
"effect": "allow", | ||
"object": ["organization/*"], | ||
"action": ["org.view"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"clause": [ | ||
{ | ||
"effect": "allow", | ||
"object": ["*"], | ||
"action": ["org.*"] | ||
}, { | ||
"effect": "allow", | ||
"object": ["organization/*"], | ||
"action": ["org.*"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"clause": [ | ||
{ | ||
"effect": "allow", | ||
"object": ["organization/*"], | ||
"action": ["org.*"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from tutelary.backends import Backend as TutelaryBackend | ||
from django.contrib.auth.backends import ModelBackend | ||
|
||
|
||
class Auth(TutelaryBackend, ModelBackend): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import json | ||
|
||
|
||
class JsonValidationError(BaseException): | ||
def __init__(self, errors): | ||
self.errors = errors | ||
|
||
def __str__(self): | ||
return json.dumps(self.errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.db.models.query import QuerySet | ||
|
||
|
||
class DetailSerializer: | ||
def __init__(self, *args, **kwargs): | ||
detail = kwargs.pop('detail', False) | ||
super(DetailSerializer, self).__init__(*args, **kwargs) | ||
|
||
is_list = type(self.instance) in [list, QuerySet] | ||
if is_list and not detail: | ||
for field_name in self.Meta.detail_only_fields: | ||
self.fields.pop(field_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.test import TestCase | ||
|
||
from ..exceptions import JsonValidationError | ||
|
||
|
||
class JsonValidationErrorTest(TestCase): | ||
def test_to_string(self): | ||
exc = JsonValidationError({ | ||
'field': "Some error" | ||
}) | ||
|
||
assert str(exc) == '{"field": "Some error"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
from .testcases import AbstractModelTestCase | ||
from django.test import TestCase | ||
from ..models import RandomIDModel | ||
|
||
|
||
class RandomIDModelTest(AbstractModelTestCase): | ||
class MyTestModel(RandomIDModel): | ||
class Meta: | ||
app_label = 'core' | ||
|
||
|
||
class RandomIDModelTest(TestCase): | ||
abstract_model = RandomIDModel | ||
|
||
def test_save(self): | ||
instance = self.model() | ||
instance = MyTestModel() | ||
instance.save() | ||
self.assertIsNotNone(instance.id) |
Oops, something went wrong.