Add APIs for NextCloud user sync

parent bf0846cd
activemembers.api package
=========================
.. automodule:: activemembers.api
:members:
:undoc-members:
:show-inheritance:
Submodules
----------
activemembers.api.permissions module
------------------------------------
.. automodule:: activemembers.api.permissions
:members:
:undoc-members:
:show-inheritance:
activemembers.api.serializers module
------------------------------------
.. automodule:: activemembers.api.serializers
:members:
:undoc-members:
:show-inheritance:
activemembers.api.urls module
-----------------------------
.. automodule:: activemembers.api.urls
:members:
:undoc-members:
:show-inheritance:
activemembers.api.views module
------------------------------
.. automodule:: activemembers.api.views
:members:
:undoc-members:
:show-inheritance:
......@@ -6,6 +6,13 @@ activemembers package
:undoc-members:
:show-inheritance:
Subpackages
-----------
.. toctree::
activemembers.api
Submodules
----------
......
from django.conf import settings
from rest_framework import permissions
class NextCloudPermission(permissions.BasePermission):
"""
Permission check for Nextcloud secret key
"""
def has_permission(self, request, view):
if 'HTTP_AUTHORIZATION' in request.META:
token = request.META['HTTP_AUTHORIZATION']
return token == ('Secret ' +
settings.ACTIVEMEMBERS_NEXTCLOUD_API_SECRET)
return request.user.is_superuser
from rest_framework import serializers
from activemembers.models import MemberGroup
from members.models import Member
class NextCloudMemberSerializer(serializers.ModelSerializer):
class Meta:
model = Member
fields = ('pk', 'username', 'first_name',
'last_name', 'is_superuser', 'email')
class NextCloudGroupSerializer(serializers.ModelSerializer):
class Meta:
model = MemberGroup
fields = ('pk', 'name', 'members')
members = serializers.SlugRelatedField(
many=True,
read_only=True,
slug_field='username'
)
from django.urls import path
from activemembers.api import views
urlpatterns = [
path('activemembers/nextcloud/users', views.NextCloudUsersView.as_view()),
path('activemembers/nextcloud/groups', views.NextCloudGroupsView.as_view()),
]
from rest_framework.generics import ListAPIView
from activemembers.api.permissions import NextCloudPermission
from activemembers.api.serializers import (
NextCloudMemberSerializer,
NextCloudGroupSerializer
)
from activemembers.models import MemberGroupMembership, MemberGroup
from members.models import Member
class NextCloudUsersView(ListAPIView):
permission_classes = [NextCloudPermission]
queryset = Member.objects.filter(
pk__in=MemberGroupMembership.active_objects.values_list(
'member_id', flat=True)
)
serializer_class = NextCloudMemberSerializer
class NextCloudGroupsView(ListAPIView):
permission_classes = [NextCloudPermission]
queryset = MemberGroup.objects.all()
serializer_class = NextCloudGroupSerializer
......@@ -6,5 +6,5 @@ from members.api import viewsets, views
router = routers.SimpleRouter()
router.register(r'members', viewsets.MemberViewset)
urlpatterns = router.urls + [
path('sentry-access/', views.SentryIdentityView.as_view())
path('sentry-access/', views.SentryIdentityView.as_view()),
]
......@@ -79,6 +79,8 @@ WIKI_API_KEY = os.environ.get('WIKI_API_KEY', 'changeme')
MIGRATION_KEY = os.environ.get('MIGRATION_KEY')
MAILINGLIST_API_SECRET = os.environ.get('MAILINGLIST_API_SECRET', '')
MEMBERS_SENTRY_API_SECRET = os.environ.get('MEMBERS_SENTRY_API_SECRET', '')
ACTIVEMEMBERS_NEXTCLOUD_API_SECRET = os.environ.get(
'ACTIVEMEMBERS_NEXTCLOUD_API_SECRET', '')
GOOGLE_MAPS_API_KEY = os.environ.get('GOOGLE_MAPS_API_KEY', '')
GOOGLE_MAPS_API_SECRET = os.environ.get('GOOGLE_MAPS_API_SECRET', '')
......
......@@ -283,6 +283,9 @@ MAILINGLIST_API_SECRET = ''
# Members Sentry API key
MEMBERS_SENTRY_API_SECRET = ''
# Activemembers NextCloud API key
ACTIVEMEMBERS_NEXTCLOUD_API_SECRET = ''
# Google maps API key and secrets
GOOGLE_MAPS_API_KEY = ''
GOOGLE_MAPS_API_SECRET = ''
......
......@@ -104,6 +104,7 @@ urlpatterns = [ # pylint: disable=invalid-name
url(r'wikilogin', views.wiki_login),
url(r'^v1/', include([
url(r'^token-auth', ObtainThaliaAuthToken.as_view()),
url(r'^', include('activemembers.api.urls')),
url(r'^', include('events.api.urls')),
url(r'^', include('members.api.urls')),
url(r'^', include('partners.api.urls')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment