#38 User requests
* implements 3) "Extend sharing on direct adding of users"
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user