-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from rdmorganiser/api
Api
- Loading branch information
Showing
93 changed files
with
3,247 additions
and
2,143 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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.6 on 2017-04-21 13:56 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.auth.models | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('auth', '0008_alter_user_username_max_length'), | ||
('accounts', '0008_related_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='ProxyUser', | ||
fields=[ | ||
], | ||
options={ | ||
'default_permissions': (), | ||
'proxy': True, | ||
'permissions': (('view_user', 'Can view user'),), | ||
}, | ||
bases=('auth.user',), | ||
managers=[ | ||
('objects', django.contrib.auth.models.UserManager()), | ||
], | ||
), | ||
] |
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
Empty file.
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,16 @@ | ||
from django.contrib.auth.models import User | ||
|
||
from rest_framework import serializers | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = User | ||
fields = ( | ||
'id', | ||
'username', | ||
'first_name', | ||
'last_name', | ||
'email' | ||
) |
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,103 @@ | ||
GROUPS = ( | ||
('editor', ( | ||
'add_attributeentity', | ||
'change_attributeentity', | ||
'delete_attributeentity', | ||
'view_attributeentity', | ||
'add_range', | ||
'change_range', | ||
'delete_range', | ||
'view_range', | ||
'add_verbosename', | ||
'change_verbosename', | ||
'delete_verbosename', | ||
'view_verbosename', | ||
'add_attribute', | ||
'change_attribute', | ||
'delete_attribute', | ||
'view_attribute', | ||
'add_option', | ||
'change_option', | ||
'delete_option', | ||
'view_option', | ||
'add_optionset', | ||
'change_optionset', | ||
'delete_optionset', | ||
'view_optionset', | ||
'add_condition', | ||
'change_condition', | ||
'delete_condition', | ||
'view_condition', | ||
'add_section', | ||
'change_section', | ||
'delete_section', | ||
'view_section', | ||
'add_catalog', | ||
'change_catalog', | ||
'delete_catalog', | ||
'view_catalog', | ||
'add_questionentity', | ||
'change_questionentity', | ||
'delete_questionentity', | ||
'view_questionentity', | ||
'add_subsection', | ||
'change_subsection', | ||
'delete_subsection', | ||
'view_subsection', | ||
'add_question', | ||
'change_question', | ||
'delete_question', | ||
'view_question', | ||
'add_task', | ||
'change_task', | ||
'delete_task', | ||
'view_task', | ||
'add_timeframe', | ||
'change_timeframe', | ||
'delete_timeframe', | ||
'view_timeframe', | ||
'add_view', | ||
'change_view', | ||
'delete_view', | ||
'view_view', | ||
)), | ||
('reviewer', ( | ||
'view_attributeentity', | ||
'view_range', | ||
'view_verbosename', | ||
'view_attribute', | ||
'view_option', | ||
'view_optionset', | ||
'view_condition', | ||
'view_section', | ||
'view_catalog', | ||
'view_questionentity', | ||
'view_subsection', | ||
'view_question', | ||
'view_task', | ||
'view_timeframe', | ||
'view_view', | ||
)), | ||
('api', ( | ||
'view_user', | ||
'view_attributeentity', | ||
'view_range', | ||
'view_verbosename', | ||
'view_attribute', | ||
'view_option', | ||
'view_optionset', | ||
'view_membership', | ||
'view_project', | ||
'view_snapshot', | ||
'view_value', | ||
'view_condition', | ||
'view_section', | ||
'view_catalog', | ||
'view_questionentity', | ||
'view_subsection', | ||
'view_question', | ||
'view_task', | ||
'view_timeframe', | ||
'view_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
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,5 +1,17 @@ | ||
from django.contrib.auth.models import Group, Permission | ||
|
||
from .settings import GROUPS | ||
|
||
|
||
def get_full_name(user): | ||
if user.first_name and user.last_name: | ||
return '%s %s' % (user.first_name, user.last_name) | ||
else: | ||
return user.username | ||
|
||
|
||
def set_group_permissions(): | ||
for name, permissions in GROUPS: | ||
group = Group.objects.get(name=name) | ||
for codename in permissions: | ||
group.permissions.add(Permission.objects.get(codename=codename)) |
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,25 @@ | ||
from django.contrib.auth.models import User | ||
|
||
from rest_framework.viewsets import ReadOnlyModelViewSet | ||
from rest_framework.filters import DjangoFilterBackend | ||
from rest_framework.authentication import SessionAuthentication, TokenAuthentication | ||
|
||
from apps.core.permissions import HasModelPermission | ||
|
||
from .serializers.api import ( | ||
UserSerializer as UserApiSerializer, | ||
) | ||
|
||
|
||
class UserApiViewSet(ReadOnlyModelViewSet): | ||
permission_classes = (HasModelPermission, ) | ||
authentication_classes = (SessionAuthentication, TokenAuthentication) | ||
queryset = User.objects.all() | ||
serializer_class = UserApiSerializer | ||
|
||
filter_backends = (DjangoFilterBackend,) | ||
filter_fields = ( | ||
'username', | ||
'email', | ||
'project' | ||
) |
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,23 @@ | ||
from rest_framework import serializers | ||
|
||
from ..models import Condition | ||
|
||
|
||
class ConditionSerializer(serializers.ModelSerializer): | ||
|
||
source = serializers.HyperlinkedRelatedField(view_name='api-v1-domain:attribute-detail', read_only=True) | ||
target_option = serializers.HyperlinkedRelatedField(view_name='api-v1-options:option-detail', read_only=True) | ||
|
||
class Meta: | ||
model = Condition | ||
fields = ( | ||
'id', | ||
'uri', | ||
'uri_prefix', | ||
'key', | ||
'comment', | ||
'source', | ||
'relation', | ||
'target_text', | ||
'target_option' | ||
) |
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,20 @@ | ||
from rest_framework import serializers | ||
|
||
from ..models import Condition | ||
|
||
|
||
class ConditionSerializer(serializers.ModelSerializer): | ||
|
||
source = serializers.CharField(source='source.uri') | ||
target_option = serializers.CharField(source='target_option.uri') | ||
|
||
class Meta: | ||
model = Condition | ||
fields = ( | ||
'uri', | ||
'comment', | ||
'source', | ||
'relation', | ||
'target_text', | ||
'target_option' | ||
) |
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
Oops, something went wrong.