Compare commits
3 Commits
ddd6669bbf
...
833483b810
Author | SHA1 | Date | |
---|---|---|---|
|
833483b810 | ||
|
1a4a4a16c6 | ||
|
74f71cfd1c |
@ -19,6 +19,7 @@ from intervention.models import Intervention, Revocation
|
|||||||
from konova.forms import BaseForm, BaseModalForm
|
from konova.forms import BaseForm, BaseModalForm
|
||||||
from konova.models import Document
|
from konova.models import Document
|
||||||
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM, ZB_GROUP, ETS_GROUP
|
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM, ZB_GROUP, ETS_GROUP
|
||||||
|
from konova.utils.messenger import Messenger
|
||||||
from konova.utils.user_checks import in_group
|
from konova.utils.user_checks import in_group
|
||||||
from organisation.models import Organisation
|
from organisation.models import Organisation
|
||||||
from user.models import UserActionLogEntry, UserAction
|
from user.models import UserActionLogEntry, UserAction
|
||||||
@ -429,6 +430,16 @@ class RunCheckForm(BaseModalForm):
|
|||||||
self.instance.log.add(user_action)
|
self.instance.log.add(user_action)
|
||||||
self.instance.save()
|
self.instance.save()
|
||||||
|
|
||||||
|
# Send message to the SSO server
|
||||||
|
messenger = Messenger(
|
||||||
|
self.instance.users.all(),
|
||||||
|
type="INFO",
|
||||||
|
)
|
||||||
|
messenger.send_object_checked(
|
||||||
|
self.instance.identifier,
|
||||||
|
self.user,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NewWithdrawForm(BaseModalForm):
|
class NewWithdrawForm(BaseModalForm):
|
||||||
""" Form for creating new withdraws
|
""" Form for creating new withdraws
|
||||||
|
43
konova/sso/sso.py
Normal file
43
konova/sso/sso.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
"""
|
||||||
|
Author: Michel Peltriaux
|
||||||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||||
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||||
|
Created on: 17.08.21
|
||||||
|
|
||||||
|
"""
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from simple_sso.sso_client.client import Client
|
||||||
|
|
||||||
|
|
||||||
|
class KonovaSSOClient(Client):
|
||||||
|
""" Konova specialized derivate of general sso.Client.
|
||||||
|
|
||||||
|
Adds some custom behaviour for konova usage.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def build_user(self, user_data):
|
||||||
|
""" Creates a user or updates user data
|
||||||
|
|
||||||
|
Args:
|
||||||
|
user_data ():
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
user = User.objects.get(username=user_data['username'])
|
||||||
|
# Update user data, excluding some changes
|
||||||
|
skipable_attrs = {
|
||||||
|
"username",
|
||||||
|
"is_staff",
|
||||||
|
"is_superuser",
|
||||||
|
}
|
||||||
|
for _attr, _val in user_data.items():
|
||||||
|
if _attr in skipable_attrs:
|
||||||
|
continue
|
||||||
|
setattr(user, _attr, _val)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = User(**user_data)
|
||||||
|
user.set_unusable_password()
|
||||||
|
user.save()
|
||||||
|
return user
|
@ -6,6 +6,7 @@ Created on: 16.11.20
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
BASE_TITLE_SHORT = "KSP"
|
||||||
BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal"
|
BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal"
|
||||||
BASE_FRONTEND_TITLE = "Kompensationsverzeichnis Service Portal"
|
BASE_FRONTEND_TITLE = "Kompensationsverzeichnis Service Portal"
|
||||||
WIKI_URL = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start"
|
WIKI_URL = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start"
|
||||||
|
@ -16,14 +16,14 @@ Including another URLconf
|
|||||||
import debug_toolbar
|
import debug_toolbar
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from simple_sso.sso_client.client import Client
|
|
||||||
|
|
||||||
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \
|
from konova.autocompletes import OrganisationAutocomplete, NonOfficialOrganisationAutocomplete, EcoAccountAutocomplete, \
|
||||||
InterventionAutocomplete
|
InterventionAutocomplete
|
||||||
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
|
from konova.settings import SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY, DEBUG
|
||||||
|
from konova.sso.sso import KonovaSSOClient
|
||||||
from konova.views import logout_view, home_view, get_document_view, remove_document_view, remove_deadline_view
|
from konova.views import logout_view, home_view, get_document_view, remove_document_view, remove_deadline_view
|
||||||
|
|
||||||
sso_client = Client(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
|
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('login/', include(sso_client.get_urls())),
|
path('login/', include(sso_client.get_urls())),
|
||||||
|
77
konova/utils/messenger.py
Normal file
77
konova/utils/messenger.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
"""
|
||||||
|
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 django.contrib.auth.models import User
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from konova.settings import SSO_SERVER_BASE, SSO_PUBLIC_KEY
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
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()
|
@ -5,7 +5,6 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 16.11.20
|
Created on: 16.11.20
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib import messages
|
|
||||||
from django.contrib.auth import logout
|
from django.contrib.auth import logout
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.http import HttpRequest, FileResponse
|
from django.http import HttpRequest, FileResponse
|
||||||
|
@ -9,11 +9,10 @@ django-bootstrap4==3.0.1
|
|||||||
django-debug-toolbar==3.1.1
|
django-debug-toolbar==3.1.1
|
||||||
django-filter==2.4.0
|
django-filter==2.4.0
|
||||||
django-fontawesome-5==1.0.18
|
django-fontawesome-5==1.0.18
|
||||||
django-simple-sso==0.14.1
|
django-simple-sso==1.1.0
|
||||||
django-tables2==2.3.4
|
django-tables2==2.3.4
|
||||||
idna==2.10
|
idna==2.10
|
||||||
importlib-metadata==2.1.1
|
importlib-metadata==2.1.1
|
||||||
itsdangerous==1.1.0
|
|
||||||
pkg-resources==0.0.0
|
pkg-resources==0.0.0
|
||||||
psycopg2==2.8.6
|
psycopg2==2.8.6
|
||||||
pytz==2020.4
|
pytz==2020.4
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
|
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
|
||||||
<th scope="row" class="col-sm-3">
|
<th scope="row" class="col-sm-3">
|
||||||
<div>{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></div>
|
<label for="id_{{ field.name }}">{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></label>
|
||||||
<small>{{ field.help_text }}</small>
|
<small>{{ field.help_text }}</small>
|
||||||
</th>
|
</th>
|
||||||
<td class="col-sm-9">
|
<td class="col-sm-9">
|
||||||
|
Loading…
Reference in New Issue
Block a user