From c36bf35373573a12b248a45a057fb67f9f3cd5ce Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 14 Oct 2020 17:40:38 +0000 Subject: [PATCH] update authentication --- fet2020/authentications/decorators.py | 20 ++++++++++++++++++++ fet2020/documents/api.py | 16 +++++++--------- fet2020/documents/etherpadlib.py | 6 ++++-- fet2020/templates/posts/show.html | 3 ++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/fet2020/authentications/decorators.py b/fet2020/authentications/decorators.py index d3af1cae..812721fd 100644 --- a/fet2020/authentications/decorators.py +++ b/fet2020/authentications/decorators.py @@ -19,3 +19,23 @@ def authenticated_user(view_func): return redirect('home') return wrapper_func + + +def ep_unauthenticated_user(view_func): + def wrapper_func(request, *args, **kwargs): + if request.user.is_authenticated: + return None, None + else: + return view_func(request, *args, **kwargs) + + return wrapper_func + + +def ep_authenticated_user(view_func): + def wrapper_func(request, *args, **kwargs): + if request.user.is_authenticated: + return view_func(request, *args, **kwargs) + else: + return None, None + + return wrapper_func diff --git a/fet2020/documents/api.py b/fet2020/documents/api.py index 942619c3..4555c58b 100644 --- a/fet2020/documents/api.py +++ b/fet2020/documents/api.py @@ -5,6 +5,9 @@ import urllib.parse from etherpad_lite import EtherpadLiteClient, EtherpadException +import logging +logger = logging.getLogger(__name__) + SERVER_URL = settings.ETHERPAD_CLIENT["exturl"] @@ -22,7 +25,8 @@ def get_ep_client(): ) group = epc.createGroupIfNotExistsFor(groupMapper="fet") except Exception as e: - raise e + logger.info("Can't get connection to Etherpad Server. Error: {}".format(e)) + return None, None return epc, group @@ -32,7 +36,7 @@ def __checkPadExists(padID=None): return False epc, group = get_ep_client() - if not epc: + if not epc or not group: return None try: @@ -64,12 +68,6 @@ def createPadifNotExists(padID): return padID -def getReadOnlyID(padID): - epc, group = get_ep_client() - url = epc.getReadOnlyID(padID=group["groupID"] + "$" + padID)['readOnlyID'] - return url - - def getPadHTML(padID): epc, group = get_ep_client() text = epc.getHTML(padID=group["groupID"] + "$" + padID)["html"] @@ -87,7 +85,7 @@ def get_pad_link(padID): return "#" epc, group = get_ep_client() - if epc: return urllib.parse.urljoin(SERVER_URL, 'p/' + group["groupID"] + '$' + str(padID)) + return "" diff --git a/fet2020/documents/etherpadlib.py b/fet2020/documents/etherpadlib.py index 3e83ef7f..5ae69c66 100644 --- a/fet2020/documents/etherpadlib.py +++ b/fet2020/documents/etherpadlib.py @@ -1,12 +1,14 @@ from datetime import datetime, timedelta from .api import get_ep_client -from authentications.decorators import authenticated_user +from authentications.decorators import ep_authenticated_user -@authenticated_user +@ep_authenticated_user def __get_ep_sessionid(request): epc, group = get_ep_client() + if not epc or not group: + return None, None author = epc.createAuthorIfNotExistsFor( name=str(request.user), diff --git a/fet2020/templates/posts/show.html b/fet2020/templates/posts/show.html index 4394a2f0..450710f5 100644 --- a/fet2020/templates/posts/show.html +++ b/fet2020/templates/posts/show.html @@ -49,6 +49,8 @@ Start: {{ post.event_start }}
Ende: {{ post.event_end }}
+ {% if request.user.is_authenticated %} + {% if post.has_agenda %} Agenda
{% endif %} @@ -57,7 +59,6 @@ Protokoll {% endif %} - {% if request.user.is_authenticated %}
------
Bearbeiten {% endif %}