Commit fec53980 authored by Joren Vrancken's avatar Joren Vrancken
Browse files

Merge branch 'feature/admin-group-nextcloud' into 'master'

Add admin group to NextCloud api

See merge request !1107
parents 54be451b 977e9254
......@@ -3,6 +3,8 @@ 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()),
path('activemembers/nextcloud/users/',
views.NextCloudUsersView.as_view()),
path('activemembers/nextcloud/groups/',
views.NextCloudGroupsView.as_view()),
]
from django.contrib.auth.models import Permission
from django.db.models import Q
from django.utils import timezone
from rest_framework.generics import ListAPIView
from activemembers.api.permissions import NextCloudPermission
......@@ -11,14 +14,48 @@ from members.models import Member
class NextCloudUsersView(ListAPIView):
permission_classes = [NextCloudPermission]
queryset = Member.current_members.filter(
pk__in=MemberGroupMembership.active_objects.values_list(
'member_id', flat=True)
)
queryset = Member.current_members.all()
serializer_class = NextCloudMemberSerializer
def get_queryset(self):
perm = Permission.objects.get(content_type__app_label='auth',
codename='nextcloud_admin')
return super().get_queryset().filter(
Q(pk__in=MemberGroupMembership.active_objects.values_list(
'member_id', flat=True)) |
Q(is_superuser=True) |
Q(groups__permissions=perm) |
Q(user_permissions=perm) |
(Q(membergroup__permissions=perm) &
(Q(membergroupmembership__until=None) |
Q(membergroupmembership__until__gte=timezone.now())))
).distinct()
class NextCloudGroupsView(ListAPIView):
permission_classes = [NextCloudPermission]
queryset = MemberGroup.objects.all()
serializer_class = NextCloudGroupSerializer
def list(self, request, *args, **kwargs):
response = super().list(request, *args, **kwargs)
perm = Permission.objects.get(content_type__app_label='auth',
codename='nextcloud_admin')
users = Member.current_members.filter(
Q(is_superuser=True) |
Q(groups__permissions=perm) |
Q(user_permissions=perm) |
(Q(membergroup__permissions=perm) &
(Q(membergroupmembership__until=None) |
Q(membergroupmembership__until__gte=timezone.now())))
).distinct().values_list('username', flat=True)
if users.count() > 0:
response.data = list(response.data) + [
{
'pk': -1,
'name': 'admin',
'members': users
}
]
return response
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-14 19:57+0100\n"
"PO-Revision-Date: 2018-11-14 19:58+0100\n"
"POT-Creation-Date: 2018-12-17 15:31+0100\n"
"PO-Revision-Date: 2018-12-17 15:32+0100\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -150,6 +150,10 @@ msgstr "E-mailadres"
msgid "Access the Sentry backend"
msgstr "Toegang tot the Sentry backend"
#: models.py
msgid "Access NextCloud as admin"
msgstr "Toegang tot NextCloud als admin"
#: models.py
msgid "Is this user currently active"
msgstr "Is deze user op dit moment actief"
......
# Generated by Django 2.1.4 on 2018-12-17 14:18
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('members', '0027_auto_20181024_2000'),
]
operations = [
migrations.AlterModelOptions(
name='member',
options={'ordering': ('first_name', 'last_name'), 'permissions': (('sentry_access', 'Access the Sentry backend'), ('nextcloud_admin', 'Access NextCloud as admin'))},
),
]
......@@ -2,8 +2,10 @@ import logging
import operator
import os
import uuid
from PIL import Image
from datetime import timedelta
from functools import reduce
from PIL import Image
from django.conf import settings
from django.contrib.auth.models import User, UserManager
from django.core import validators
......@@ -13,7 +15,6 @@ from django.db.models import Q
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import pgettext_lazy, gettext_lazy as _
from functools import reduce
from localflavor.generic.countries.sepa import IBAN_SEPA_COUNTRIES
from localflavor.generic.models import IBANField
......@@ -97,6 +98,7 @@ class Member(User):
ordering = ('first_name', 'last_name')
permissions = (
('sentry_access', _("Access the Sentry backend")),
('nextcloud_admin', _("Access NextCloud as admin")),
)
objects = MemberManager()
......
Supports Markdown
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