Commit af86abab authored by Joren Vrancken's avatar Joren Vrancken Committed by Sébastiaan Versteeg
Browse files

Merge branch 'feature/sentry-access' into 'master'

Access Sentry access permission and API call to provide necessary auth info

See merge request !866

(cherry picked from commit 7be36758)

57cfb072 Access Sentry access permission and API call to provide necessary auth info
parent 5e954eca
......@@ -9,6 +9,14 @@ members\.api package
Submodules
----------
members\.api\.permissions module
--------------------------------
.. automodule:: members.api.permissions
:members:
:undoc-members:
:show-inheritance:
members\.api\.serializers module
--------------------------------
......@@ -25,6 +33,14 @@ members\.api\.urls module
:undoc-members:
:show-inheritance:
members\.api\.views module
--------------------------
.. automodule:: members.api.views
:members:
:undoc-members:
:show-inheritance:
members\.api\.viewsets module
-----------------------------
......
from django.conf import settings
from rest_framework import permissions
class SentryIdentityPermission(permissions.BasePermission):
"""
Permission check for Sentry secret key and access permission
"""
def has_permission(self, request, view):
if 'secret' in request.GET:
return (request.GET['secret'] == settings.MEMBERS_SENTRY_API_SECRET
and request.user.has_perm('auth.sentry_access'))
return False
......@@ -150,3 +150,9 @@ class MemberListSerializer(serializers.ModelSerializer):
return create_image_thumbnail_dict(
self.context['request'], file, placeholder=placeholder,
size_large='800x800')
class SentryIdentitySerializer(serializers.ModelSerializer):
class Meta:
model = Member
fields = ('pk', 'first_name', 'last_name', 'email', 'is_superuser')
from django.urls import path
from rest_framework import routers
from members.api import viewsets
from members.api import viewsets, views
router = routers.SimpleRouter()
router.register(r'members', viewsets.MemberViewset)
urlpatterns = router.urls
urlpatterns = router.urls + [
path('sentry-access/', views.SentryIdentityView.as_view())
]
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from members.api.permissions import SentryIdentityPermission
from members.api.serializers import SentryIdentitySerializer
class SentryIdentityView(APIView):
permission_classes = (IsAuthenticated, SentryIdentityPermission)
def get(self, request, format=None):
serializer = SentryIdentitySerializer(request.user)
return Response(serializer.data)
# Generated by Django 2.0.2 on 2018-07-08 16:02
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('members', '0021_emailchange'),
]
operations = [
migrations.AlterModelOptions(
name='member',
options={'ordering': ('first_name', 'last_name'), 'permissions': (('sentry_access', 'Access the Sentry backend'),)},
),
]
......@@ -78,6 +78,9 @@ class Member(User):
class Meta:
proxy = True
ordering = ('first_name', 'last_name')
permissions = (
('sentry_access', _("Access the Sentry backend")),
)
objects = MemberManager()
current_members = CurrentMemberManager()
......
......@@ -77,6 +77,7 @@ WIKI_API_KEY = os.environ.get('WIKI_API_KEY', 'changeme')
MIGRATION_KEY = os.environ.get('MIGRATION_KEY')
PUSH_NOTIFICATIONS_API_KEY = os.environ.get('PUSH_NOTIFICATIONS_API_KEY', '')
MAILINGLIST_API_SECRET = os.environ.get('MAILINGLIST_API_SECRET', '')
MEMBERS_SENTRY_API_SECRET = os.environ.get('MEMBERS_SENTRY_API_SECRET', '')
if os.environ.get('DJANGO_SSLONLY'):
SECURE_SSL_REDIRECT = True
......
......@@ -268,6 +268,9 @@ PUSH_NOTIFICATIONS_API_KEY = ''
# Mailinglist API key
MAILINGLIST_API_SECRET = ''
# Members Sentry API key
MEMBERS_SENTRY_API_SECRET = ''
# Photos settings
PHOTO_UPLOAD_SIZE = 1920, 1080
......
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