Added api viewset for users.

This commit is contained in:
Norman Jäckel 2015-01-06 00:11:22 +01:00
parent 7644cb9a09
commit 8cb70017da
3 changed files with 40 additions and 0 deletions

View File

@ -15,7 +15,9 @@ class UsersAppConfig(AppConfig):
from openslides.config.signals import config_signal
from openslides.core.signals import post_database_setup
from openslides.projector.api import register_slide_model
from openslides.utils.rest_api import router
from .signals import create_builtin_groups_and_admin, setup_users_config, user_post_save
from .views import UserViewSet
# Load User model.
User = self.get_model('User')
@ -27,3 +29,6 @@ class UsersAppConfig(AppConfig):
# Register slides.
register_slide_model(User, 'participant/user_slide.html')
# Register viewset.
router.register('users/user', UserViewSet)

View File

@ -0,0 +1,15 @@
from rest_framework import serializers
from .models import User
class UserSerializer(serializers.ModelSerializer):
"""
Serializer for a users.models.User objects.
"""
class Meta:
model = User
fields = (
'username',
'first_name',
'last_name')

View File

@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _, ugettext_lazy, activate
from openslides.config.api import config
from openslides.utils import rest_api
from openslides.utils.utils import delete_default_permissions, html_strong
from openslides.utils.views import (
CreateView, CSVImportView, DeleteView, DetailView, FormView, ListView,
@ -19,6 +20,7 @@ from .forms import (GroupForm, UserCreateForm, UserMultipleCreateForm,
UsersettingsForm, UserUpdateForm)
from .models import Group, User
from .pdf import users_to_pdf, users_passwords_to_pdf
from .serializers import UserSerializer
class UserListView(ListView):
@ -259,6 +261,24 @@ class ResetPasswordView(SingleObjectMixin, QuestionView):
return _('The Password for %s was successfully reset.') % html_strong(self.get_object())
class UserViewSet(rest_api.viewsets.ModelViewSet):
"""
API endpoint to view, edit and delete users.
"""
model = User
queryset = User.objects.all()
serializer_class = UserSerializer
def check_permissions(self, request):
"""
Calls self.permission_denied() if the requesting user has not the
permission to manage.
"""
# TODO: More work on this required.
if not request.user.has_perm('users.can_manage'):
self.permission_denied(request)
class GroupListView(ListView):
"""
Overview over all groups.