Merge pull request 'master' (#469) from master into Docker
Reviewed-on: #469
This commit is contained in:
		
						commit
						2b84bab1d0
					
				@ -66,7 +66,6 @@ INSTALLED_APPS = [
 | 
			
		||||
    'django.contrib.staticfiles',
 | 
			
		||||
    'django.contrib.gis',
 | 
			
		||||
    'django.contrib.humanize',
 | 
			
		||||
    'simple_sso.sso_server',
 | 
			
		||||
    'django_tables2',
 | 
			
		||||
    'bootstrap_modal_forms',
 | 
			
		||||
    'fontawesome_5',
 | 
			
		||||
 | 
			
		||||
@ -1,78 +0,0 @@
 | 
			
		||||
"""
 | 
			
		||||
Author: Michel Peltriaux
 | 
			
		||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
 | 
			
		||||
Contact: michel.peltriaux@sgdnord.rlp.de
 | 
			
		||||
Created on: 17.08.21
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
from collections import Iterable
 | 
			
		||||
 | 
			
		||||
import requests
 | 
			
		||||
from user.models import User
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
 | 
			
		||||
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY, PROXIES
 | 
			
		||||
from konova.sub_settings.context_settings import BASE_TITLE_SHORT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Messenger:
 | 
			
		||||
    """ Used to send messages to the SSO server.
 | 
			
		||||
 | 
			
		||||
    Messages can be seen by the user the next time they login on their SSO dashboard.
 | 
			
		||||
    Documentation for SSO Server-Client communication can be found here:
 | 
			
		||||
    https://git.naturschutz.rlp.de/SGD-Nord/arnova/wiki/Messages
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    server_url = "{}communication/message/".format(SSO_SERVER_BASE)
 | 
			
		||||
 | 
			
		||||
    def __init__(self, users: Iterable, subject: str = None, body: str = None, type: str = None):
 | 
			
		||||
        self.users = users
 | 
			
		||||
        self.msg_subject = subject
 | 
			
		||||
        self.msg_body = body
 | 
			
		||||
        self.msg_type = type
 | 
			
		||||
 | 
			
		||||
    def send(self):
 | 
			
		||||
        """ Sends a message
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        if self.msg_body is None or len(self.msg_body) == 0:
 | 
			
		||||
            raise AttributeError("No message body set")
 | 
			
		||||
 | 
			
		||||
        headers = {
 | 
			
		||||
            "x-services-public-key": SSO_PUBLIC_KEY
 | 
			
		||||
        }
 | 
			
		||||
        for user in self.users:
 | 
			
		||||
            data = {
 | 
			
		||||
                "type": self.msg_type,
 | 
			
		||||
                "sender": BASE_TITLE_SHORT,
 | 
			
		||||
                "receiver": user.username,
 | 
			
		||||
                "subject": self.msg_subject,
 | 
			
		||||
                "body": self.msg_body,
 | 
			
		||||
            }
 | 
			
		||||
            requests.post(
 | 
			
		||||
                self.server_url,
 | 
			
		||||
                data=data,
 | 
			
		||||
                headers=headers,
 | 
			
		||||
                proxies=PROXIES
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def send_object_checked(self, obj_identifier: str, performing_user: User, detail_view_url: str = ""):
 | 
			
		||||
        """ Wraps sending of a message related to the checking of an object, like an intervention
 | 
			
		||||
 | 
			
		||||
        Args:
 | 
			
		||||
            obj_identifier (str): The object's identifier (e.g. 'EIV-123'
 | 
			
		||||
            performing_user (User): The user who performed the checking
 | 
			
		||||
            detail_view_url (str): If a direct link to the object shall be added to the message, it can be provided here
 | 
			
		||||
 | 
			
		||||
        Returns:
 | 
			
		||||
 | 
			
		||||
        """
 | 
			
		||||
        self.msg_subject = _("{} checked").format(obj_identifier)
 | 
			
		||||
        if len(detail_view_url) > 0:
 | 
			
		||||
            detail_view_url = _('<a href="{}">Check it out</a>').format(detail_view_url)
 | 
			
		||||
        self.msg_body = _("{} has been checked successfully by user {}! {}").format(
 | 
			
		||||
            obj_identifier,
 | 
			
		||||
            performing_user.username,
 | 
			
		||||
            detail_view_url
 | 
			
		||||
        )
 | 
			
		||||
        self.send()
 | 
			
		||||
@ -24,13 +24,11 @@ django-environ==0.11.2
 | 
			
		||||
django-filter==24.3
 | 
			
		||||
django-fontawesome-5==1.0.18
 | 
			
		||||
django-oauth-toolkit==3.0.1
 | 
			
		||||
django-simple-sso==1.2.0
 | 
			
		||||
django-tables2==2.7.1
 | 
			
		||||
et_xmlfile==2.0.0
 | 
			
		||||
gunicorn==23.0.0
 | 
			
		||||
idna==3.10
 | 
			
		||||
importlib_metadata==8.5.0
 | 
			
		||||
itsdangerous==0.24
 | 
			
		||||
jwcrypto==1.5.6
 | 
			
		||||
kombu==5.4.0rc1
 | 
			
		||||
oauthlib==3.2.2
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user