#38 User requests

* implements 3) "Extend sharing on direct adding of users"
pull/42/head
mpeltriaux 3 years ago
parent 36470f819c
commit 7ed114a858

@ -16,10 +16,9 @@ from compensation.models import EcoAccount, EcoAccountDeduction
from intervention.inputs import TextToClipboardInput
from intervention.models import Revocation, RevocationDocument, Intervention
from konova.forms import BaseModalForm
from konova.settings import ZB_GROUP, ETS_GROUP
from konova.utils.general import format_german_float
from konova.utils.messenger import Messenger
from konova.utils.user_checks import in_group
from konova.utils.user_checks import is_default_group_only
from user.models import UserActionLogEntry, UserAction
@ -36,6 +35,21 @@ class ShareInterventionModalForm(BaseModalForm):
}
)
)
user_select = forms.ModelMultipleChoiceField(
label=_("Add user to share with"),
label_suffix="",
help_text=_("Multiple selection possible - You can only select users which do not already have access"),
required=False,
queryset=User.objects.all(),
widget=autocomplete.ModelSelect2Multiple(
url="share-user-autocomplete",
attrs={
"data-placeholder": _("Click for selection"),
"data-minimum-input-length": 3,
},
forward=["users"]
),
)
users = forms.MultipleChoiceField(
label=_("Shared with"),
label_suffix="",
@ -78,10 +92,18 @@ class ShareInterventionModalForm(BaseModalForm):
)
# Initialize users field
# Remove field if user is not in registration or conservation group
if not in_group(self.request.user, ZB_GROUP) and not in_group(self.request.user, ETS_GROUP):
del self.fields["users"]
else:
# Disable field if user is not in registration or conservation group
if is_default_group_only(self.request.user):
self.disable_form_field("users")
self._add_user_choices_to_field()
def _add_user_choices_to_field(self):
""" Transforms the instance's sharing users into a list for the form field
Returns:
"""
users = self.instance.users.all()
choices = []
for n in users:
@ -96,10 +118,13 @@ class ShareInterventionModalForm(BaseModalForm):
)
def save(self):
accessing_users = User.objects.filter(
id__in=self.cleaned_data["users"]
still_accessing_users = self.cleaned_data["users"]
new_accessing_users = list(self.cleaned_data["user_select"].values_list("id", flat=True))
accessing_users = still_accessing_users + new_accessing_users
users = User.objects.filter(
id__in=accessing_users
)
self.instance.share_with_list(accessing_users)
self.instance.share_with_list(users)
class NewRevocationModalForm(BaseModalForm):

@ -11,7 +11,6 @@ from intervention.tables import InterventionTable
from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordModalForm
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
from konova.utils.documents import remove_document, get_document
from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED, \
@ -403,7 +402,7 @@ def create_share_view(request: HttpRequest, id: str):
"""
intervention = get_object_or_404(Intervention, id=id)
form = ShareInterventionModalForm(request.POST or None, instance=intervention, request=request)
form = ShareInterventionModalForm(request.POST or None, instance=intervention, request=request, user=request.user)
return form.process_request(
request,
msg_success=_("Share settings updated")

@ -6,6 +6,7 @@ Created on: 07.12.20
"""
from dal_select2.views import Select2QuerySetView
from django.contrib.auth.models import User
from django.db.models import Q
from codelist.models import KonovaCode
@ -60,6 +61,29 @@ class InterventionAutocomplete(Select2QuerySetView):
return qs
class ShareUserAutocomplete(Select2QuerySetView):
""" Autocomplete for intervention entries
Only returns entries that are accessible for the requesting user
"""
def get_queryset(self):
if self.request.user.is_anonymous:
return User.objects.none()
exclude_user_ids = self.forwarded.get("users", [None])
_exclude = {"id__in": exclude_user_ids}
qs = User.objects.all().exclude(
**_exclude
).order_by(
"username"
)
if self.q:
qs = qs.filter(
username__istartswith=self.q
)
return qs
class KonovaCodeAutocomplete(Select2QuerySetView):
"""
Provides simple autocomplete functionality for codes

@ -19,7 +19,8 @@ from django.urls import path, include
from konova.autocompletes import EcoAccountAutocomplete, \
InterventionAutocomplete, CompensationActionCodeAutocomplete, BiotopeCodeAutocomplete, LawCodeAutocomplete, \
RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete
RegistrationOfficeCodeAutocomplete, ConservationOfficeCodeAutocomplete, ProcessTypeCodeAutocomplete, \
ShareUserAutocomplete
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, remove_deadline_view
@ -50,6 +51,7 @@ urlpatterns = [
path("atcmplt/codes/prc-type", ProcessTypeCodeAutocomplete.as_view(), name="codes-process-type-autocomplete"),
path("atcmplt/codes/reg-off", RegistrationOfficeCodeAutocomplete.as_view(), name="codes-registration-office-autocomplete"),
path("atcmplt/codes/cons-off", ConservationOfficeCodeAutocomplete.as_view(), name="codes-conservation-office-autocomplete"),
path("atcmplt/share/u", ShareUserAutocomplete.as_view(), name="share-user-autocomplete"),
]
if DEBUG:

@ -7,6 +7,8 @@ Created on: 02.07.21
"""
from django.contrib.auth.models import User
from konova.settings import ETS_GROUP, ZB_GROUP
def in_group(user: User, group: str) -> bool:
""" Checks if the user is part of a group
@ -21,3 +23,15 @@ def in_group(user: User, group: str) -> bool:
return user.groups.filter(
name=group
)
def is_default_group_only(user: User) -> bool:
""" Checks if the user is only part of the default group
Args:
user (User): The user object
Returns:
bool
"""
return not in_group(user, ZB_GROUP) and not in_group(user, ETS_GROUP)

Binary file not shown.

@ -9,8 +9,8 @@
#: intervention/filters.py:26 intervention/filters.py:40
#: intervention/filters.py:47 intervention/filters.py:48
#: intervention/forms/forms.py:53 intervention/forms/forms.py:155
#: intervention/forms/forms.py:167 intervention/forms/modalForms.py:108
#: intervention/forms/modalForms.py:121 intervention/forms/modalForms.py:134
#: intervention/forms/forms.py:167 intervention/forms/modalForms.py:123
#: intervention/forms/modalForms.py:136 intervention/forms/modalForms.py:149
#: konova/forms.py:142 konova/forms.py:247 konova/forms.py:313
#: konova/forms.py:340 konova/forms.py:350 konova/forms.py:363
#: konova/forms.py:375 konova/forms.py:396 user/forms.py:38
@ -19,7 +19,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-11-15 11:46+0100\n"
"POT-Creation-Date: 2021-11-15 13:40+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -56,7 +56,7 @@ msgstr "Verantwortliche Stelle"
#: analysis/forms.py:58 compensation/forms/forms.py:87
#: compensation/forms/forms.py:138 intervention/forms/forms.py:63
#: intervention/forms/forms.py:80 intervention/forms/forms.py:96
#: intervention/forms/forms.py:112
#: intervention/forms/forms.py:112 intervention/forms/modalForms.py:48
msgid "Click for selection"
msgstr "Auswählen..."
@ -210,7 +210,7 @@ msgstr "Abbuchungen"
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:36
#: ema/templates/ema/detail/includes/states-after.html:36
#: ema/templates/ema/detail/includes/states-before.html:36
#: intervention/forms/modalForms.py:276
#: intervention/forms/modalForms.py:291
msgid "Surface"
msgstr "Fläche"
@ -273,7 +273,7 @@ msgid "Type"
msgstr "Typ"
#: analysis/templates/analysis/reports/includes/old_data/amount.html:24
#: intervention/forms/modalForms.py:287 intervention/forms/modalForms.py:294
#: intervention/forms/modalForms.py:302 intervention/forms/modalForms.py:309
#: intervention/tables.py:88
#: intervention/templates/intervention/detail/view.html:19
#: konova/templates/konova/home.html:11 templates/navbars/navbar.html:22
@ -283,7 +283,7 @@ msgstr "Eingriff"
#: analysis/templates/analysis/reports/includes/old_data/amount.html:34
#: compensation/tables.py:224
#: compensation/templates/compensation/detail/eco_account/view.html:19
#: intervention/forms/modalForms.py:260 intervention/forms/modalForms.py:267
#: intervention/forms/modalForms.py:275 intervention/forms/modalForms.py:282
#: konova/templates/konova/home.html:88 templates/navbars/navbar.html:34
msgid "Eco-account"
msgstr "Ökokonto"
@ -350,7 +350,7 @@ msgstr "Kompensation XY; Flur ABC"
#: ema/templates/ema/detail/includes/actions.html:34
#: ema/templates/ema/detail/includes/deadlines.html:34
#: ema/templates/ema/detail/includes/documents.html:31
#: intervention/forms/forms.py:179 intervention/forms/modalForms.py:133
#: intervention/forms/forms.py:179 intervention/forms/modalForms.py:148
#: intervention/templates/intervention/detail/includes/documents.html:31
#: intervention/templates/intervention/detail/includes/payments.html:34
#: intervention/templates/intervention/detail/includes/revocation.html:38
@ -452,7 +452,7 @@ msgid "Due on which date"
msgstr "Zahlung wird an diesem Datum erwartet"
#: compensation/forms/modalForms.py:63 compensation/forms/modalForms.py:274
#: compensation/forms/modalForms.py:369 intervention/forms/modalForms.py:135
#: compensation/forms/modalForms.py:369 intervention/forms/modalForms.py:150
#: konova/forms.py:376
msgid "Additional comment, maximum {} letters"
msgstr "Zusätzlicher Kommentar, maximal {} Zeichen"
@ -477,7 +477,7 @@ msgstr "Biotoptyp"
msgid "Select the biotope type"
msgstr "Biotoptyp wählen"
#: compensation/forms/modalForms.py:155 intervention/forms/modalForms.py:278
#: compensation/forms/modalForms.py:155 intervention/forms/modalForms.py:293
msgid "in m²"
msgstr ""
@ -509,7 +509,7 @@ msgstr "Fristart wählen"
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:31
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:31
#: ema/templates/ema/detail/includes/deadlines.html:31
#: intervention/forms/modalForms.py:107
#: intervention/forms/modalForms.py:122
msgid "Date"
msgstr "Datum"
@ -888,14 +888,14 @@ msgstr "Zuletzt bearbeitet"
#: compensation/templates/compensation/detail/compensation/view.html:79
#: compensation/templates/compensation/detail/eco_account/view.html:82
#: ema/templates/ema/detail/view.html:69 intervention/forms/modalForms.py:40
#: ema/templates/ema/detail/view.html:69 intervention/forms/modalForms.py:55
#: intervention/templates/intervention/detail/view.html:116
msgid "Shared with"
msgstr "Freigegeben für"
#: compensation/templates/compensation/detail/eco_account/includes/controls.html:15
#: ema/templates/ema/detail/includes/controls.html:15
#: intervention/forms/modalForms.py:54
#: intervention/forms/modalForms.py:69
#: intervention/templates/intervention/detail/includes/controls.html:15
msgid "Share"
msgstr "Freigabe"
@ -1031,7 +1031,7 @@ msgstr "Kompensation {} bearbeitet"
#: compensation/views/compensation_views.py:220
#: compensation/views/eco_account_views.py:307 ema/views.py:182
#: intervention/views.py:476
#: intervention/views.py:475
msgid "Log"
msgstr "Log"
@ -1041,7 +1041,7 @@ msgstr "Kompensation entfernt"
#: compensation/views/compensation_views.py:264
#: compensation/views/eco_account_views.py:459 ema/views.py:349
#: intervention/views.py:130
#: intervention/views.py:129
msgid "Document added"
msgstr "Dokument hinzugefügt"
@ -1087,36 +1087,36 @@ msgid "Deduction removed"
msgstr "Abbuchung entfernt"
#: compensation/views/eco_account_views.py:328 ema/views.py:262
#: intervention/views.py:518
#: intervention/views.py:517
msgid "{} unrecorded"
msgstr "{} entzeichnet"
#: compensation/views/eco_account_views.py:328 ema/views.py:262
#: intervention/views.py:518
#: intervention/views.py:517
msgid "{} recorded"
msgstr "{} verzeichnet"
#: compensation/views/eco_account_views.py:529 intervention/views.py:499
#: compensation/views/eco_account_views.py:529 intervention/views.py:498
msgid "Deduction added"
msgstr "Abbuchung hinzugefügt"
#: compensation/views/eco_account_views.py:612 ema/views.py:517
#: intervention/views.py:374
#: intervention/views.py:373
msgid "{} has already been shared with you"
msgstr "{} wurde bereits für Sie freigegeben"
#: compensation/views/eco_account_views.py:617 ema/views.py:522
#: intervention/views.py:379
#: intervention/views.py:378
msgid "{} has been shared with you"
msgstr "{} ist nun für Sie freigegeben"
#: compensation/views/eco_account_views.py:624 ema/views.py:529
#: intervention/views.py:386
#: intervention/views.py:385
msgid "Share link invalid"
msgstr "Freigabelink ungültig"
#: compensation/views/eco_account_views.py:647 ema/views.py:552
#: intervention/views.py:409
#: intervention/views.py:408
msgid "Share settings updated"
msgstr "Freigabe Einstellungen aktualisiert"
@ -1257,46 +1257,57 @@ msgstr "Freigabelink"
msgid "Send this link to users who you want to have writing access on the data"
msgstr "Andere Nutzer erhalten über diesen Link Zugriff auf die Daten"
#: intervention/forms/modalForms.py:43
#: intervention/forms/modalForms.py:40
msgid "Add user to share with"
msgstr "Nutzer direkt hinzufügen"
#: intervention/forms/modalForms.py:42
msgid ""
"Multiple selection possible - You can only select users which do not already "
"have access"
msgstr ""
"Mehrfachauswahl möglich - Sie können nur Nutzer wählen, für die der Eintrag noch nicht freigegeben wurde"
#: intervention/forms/modalForms.py:58
msgid "Remove check to remove access for this user"
msgstr "Wählen Sie die Nutzer ab, die keinen Zugriff mehr haben sollen"
#: intervention/forms/modalForms.py:55
#: intervention/forms/modalForms.py:70
msgid "Share settings for {}"
msgstr "Freigabe Einstellungen für {}"
#: intervention/forms/modalForms.py:109
#: intervention/forms/modalForms.py:124
msgid "Date of revocation"
msgstr "Datum des Widerspruchs"
#: intervention/forms/modalForms.py:120
#: intervention/forms/modalForms.py:135
#: intervention/templates/intervention/detail/includes/revocation.html:35
msgid "Document"
msgstr "Dokument"
#: intervention/forms/modalForms.py:123 konova/forms.py:364
#: intervention/forms/modalForms.py:138 konova/forms.py:364
msgid "Must be smaller than 15 Mb"
msgstr "Muss kleiner als 15 Mb sein"
#: intervention/forms/modalForms.py:147
#: intervention/forms/modalForms.py:162
#: intervention/templates/intervention/detail/includes/revocation.html:18
msgid "Add revocation"
msgstr "Widerspruch hinzufügen"
#: intervention/forms/modalForms.py:189
#: intervention/forms/modalForms.py:204
msgid "Checked intervention data"
msgstr "Eingriffsdaten geprüft"
#: intervention/forms/modalForms.py:195
#: intervention/forms/modalForms.py:210
msgid "Checked compensations data and payments"
msgstr "Kompensationen und Zahlungen geprüft"
#: intervention/forms/modalForms.py:203
#: intervention/forms/modalForms.py:218
#: intervention/templates/intervention/detail/includes/controls.html:19
msgid "Run check"
msgstr "Prüfung vornehmen"
#: intervention/forms/modalForms.py:204 konova/forms.py:449
#: intervention/forms/modalForms.py:219 konova/forms.py:449
msgid ""
"I, {} {}, confirm that all necessary control steps have been performed by "
"myself."
@ -1304,23 +1315,23 @@ msgstr ""
"Ich, {} {}, bestätige, dass die notwendigen Kontrollschritte durchgeführt "
"wurden:"
#: intervention/forms/modalForms.py:262
#: intervention/forms/modalForms.py:277
msgid "Only recorded accounts can be selected for deductions"
msgstr "Nur verzeichnete Ökokonten können für Abbuchungen verwendet werden."
#: intervention/forms/modalForms.py:289
#: intervention/forms/modalForms.py:304
msgid "Only shared interventions can be selected"
msgstr "Nur freigegebene Eingriffe können gewählt werden"
#: intervention/forms/modalForms.py:302
#: intervention/forms/modalForms.py:317
msgid "New Deduction"
msgstr "Neue Abbuchung"
#: intervention/forms/modalForms.py:303
#: intervention/forms/modalForms.py:318
msgid "Enter the information for a new deduction from a chosen eco-account"
msgstr "Geben Sie die Informationen für eine neue Abbuchung ein."
#: intervention/forms/modalForms.py:336
#: intervention/forms/modalForms.py:351
msgid ""
"Eco-account {} is not recorded yet. You can only deduct from recorded "
"accounts."
@ -1328,7 +1339,7 @@ msgstr ""
"Ökokonto {} ist noch nicht verzeichnet. Abbuchungen können nur von "
"verzeichneten Ökokonten erfolgen."
#: intervention/forms/modalForms.py:349
#: intervention/forms/modalForms.py:364
msgid ""
"The account {} has not enough surface for a deduction of {} m². There are "
"only {} m² left"
@ -1431,35 +1442,35 @@ msgstr ""
"Kein Ausgleich jeglicher Art gefunden (Kompensation, Ersatzzahlung, "
"Abbuchung)"
#: intervention/views.py:80
#: intervention/views.py:79
msgid "Intervention {} added"
msgstr "Eingriff {} hinzugefügt"
#: intervention/views.py:244
#: intervention/views.py:243
msgid "This intervention has {} revocations"
msgstr "Dem Eingriff liegen {} Widersprüche vor"
#: intervention/views.py:292
#: intervention/views.py:291
msgid "Intervention {} edited"
msgstr "Eingriff {} bearbeitet"
#: intervention/views.py:327
#: intervention/views.py:326
msgid "{} removed"
msgstr "{} entfernt"
#: intervention/views.py:348
#: intervention/views.py:347
msgid "Revocation removed"
msgstr "Widerspruch entfernt"
#: intervention/views.py:430
#: intervention/views.py:429
msgid "Check performed"
msgstr "Prüfung durchgeführt"
#: intervention/views.py:452
#: intervention/views.py:451
msgid "Revocation added"
msgstr "Widerspruch hinzugefügt"
#: intervention/views.py:523
#: intervention/views.py:522
msgid "There are errors on this intervention:"
msgstr "Es liegen Fehler in diesem Eingriff vor:"
@ -3141,6 +3152,9 @@ msgstr ""
msgid "A fontawesome icon field"
msgstr ""
#~ msgid "Share with user"
#~ msgstr "Freigeben für Nutzer"
#~ msgid "Fundings"
#~ msgstr "Förderungen"

Loading…
Cancel
Save