mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Add club manager acl for user search
This commit is contained in:
parent
303531fed3
commit
331a75d77a
3 changed files with 46 additions and 1 deletions
|
@ -184,8 +184,11 @@ class AutocompleteViewMixin(LoginRequiredMixin, autocomplete.Select2QuerySetView
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
||||||
can, reason, _permission, query_set = self.obj_type.can_list(self.request.user)
|
can, reason, _permission, query_set = self.obj_type.can_list(self.request.user)
|
||||||
|
if query_set:
|
||||||
|
self.query_set = query_set
|
||||||
|
else:
|
||||||
|
self.query_set = self.obj_type.objects.none()
|
||||||
|
|
||||||
self.query_set = query_set
|
|
||||||
if hasattr(self, "filter_results"):
|
if hasattr(self, "filter_results"):
|
||||||
self.filter_results()
|
self.filter_results()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2065,6 +2065,33 @@ class Adherent(User):
|
||||||
("users.add_user",),
|
("users.add_user",),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def can_list(cls, user_request, *_args, **_kwargs):
|
||||||
|
"""Users can list adherent only if they are :
|
||||||
|
- Members of view acl,
|
||||||
|
- Club administrator.
|
||||||
|
|
||||||
|
:param user_request: The user who wants to view the list.
|
||||||
|
:return: True if the user can view the list and an explanation
|
||||||
|
message.
|
||||||
|
|
||||||
|
"""
|
||||||
|
can, _message, _group = Club.can_view_all(user_request)
|
||||||
|
if user_request.has_perm("users.view_user") or can:
|
||||||
|
return (
|
||||||
|
True,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
cls.objects.all()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return (
|
||||||
|
False,
|
||||||
|
_("You don't have the right to list all adherents."),
|
||||||
|
("users.view_user",),
|
||||||
|
cls.objects.none(),
|
||||||
|
)
|
||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
"""Method, clean and validate the gpgfp value.
|
"""Method, clean and validate the gpgfp value.
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,21 @@ class UserAutocomplete(AutocompleteViewMixin):
|
||||||
class AdherentAutocomplete(AutocompleteViewMixin):
|
class AdherentAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = Adherent
|
obj_type = Adherent
|
||||||
|
|
||||||
|
# Precision on search to add annotations so search behaves more like users expect it to
|
||||||
|
def filter_results(self):
|
||||||
|
# Comments explain what we try to match
|
||||||
|
self.query_set = self.query_set.annotate(
|
||||||
|
full_name=Concat("name", Value(" "), "surname"), # Match when the user searches "Toto Passoir"
|
||||||
|
full_name_reverse=Concat("surname", Value(" "), "name"), # Match when the user searches "Passoir Toto"
|
||||||
|
).all()
|
||||||
|
|
||||||
|
if self.q:
|
||||||
|
self.query_set = self.query_set.filter(
|
||||||
|
Q(pseudo__icontains=self.q)
|
||||||
|
| Q(full_name__icontains=self.q)
|
||||||
|
| Q(full_name_reverse__icontains=self.q)
|
||||||
|
)
|
||||||
|
|
||||||
#@can_view_all(Club)
|
#@can_view_all(Club)
|
||||||
class ClubAutocomplete(AutocompleteViewMixin):
|
class ClubAutocomplete(AutocompleteViewMixin):
|
||||||
obj_type = Club
|
obj_type = Club
|
||||||
|
|
Loading…
Reference in a new issue