diff --git a/apps/challenge/forms.py b/apps/challenge/forms.py index cbd58974..bb9632bd 100644 --- a/apps/challenge/forms.py +++ b/apps/challenge/forms.py @@ -323,9 +323,9 @@ def __init__(self, *args, **kwargs): label=_('Disponibilités pour :'), queryset=get_user_model().objects.filter( Q(profile__formation__in=FORMATION_KEYS) | - Q(profile__actor_for__isnull=False) | - Q(profile__status=USERSTATUS_DELETED) - ), + Q(profile__actor_for__isnull=False) + ).exclude(profile__status=USERSTATUS_DELETED) + .distinct(), widget=ModelSelect2(url='user-PersonsRelevantForSessions-ac') ) diff --git a/apps/challenge/templates/challenge/session_availability.html b/apps/challenge/templates/challenge/session_availability.html index 5e274446..8d0868f2 100644 --- a/apps/challenge/templates/challenge/session_availability.html +++ b/apps/challenge/templates/challenge/session_availability.html @@ -43,7 +43,7 @@

{{ avail.helper.get_full_name }} - {{ avail.helper.profile.actor_for }} + {{ avail.helper.profile.actor_inline }} {% endfor %} diff --git a/apps/user/models.py b/apps/user/models.py index 87ee0aec..5dc16cb9 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -428,7 +428,7 @@ def get_seasons(self, raise_without_cantons=False): raise PermissionDenied # Ajoute les cantons d'affiliation et mobiles - if self.formation or self.actor_for: + if self.formation or self.actor: if self.affiliation_canton: usercantons += [self.affiliation_canton] if self.activity_cantons: diff --git a/apps/user/templates/auth/user_detail.html b/apps/user/templates/auth/user_detail.html index db1881a9..06d8ea74 100644 --- a/apps/user/templates/auth/user_detail.html +++ b/apps/user/templates/auth/user_detail.html @@ -14,7 +14,7 @@

{% if userprofile.profile.formation %} {{ userprofile.profile.formation_full }} {{ userprofile.profile.formation_icon }} {% endif %} - {% if userprofile.profile.actor_for %} + {% if userprofile.profile.actor %} {{ userprofile.profile.actor_inline }} {{ userprofile.profile.actor_icon }} {% endif %} {% if userprofile.profile.can_login %} @@ -31,7 +31,7 @@

{% endif %} {% endif %} - {% if request.user|can:"user_deletes" and request.user.pk != userprofile.pk and not userprofile.profile.deleted %} + {% if request.user|can:"user_deletions" and request.user.pk != userprofile.pk and not userprofile.profile.deleted %} diff --git a/apps/user/tests/test_profile.py b/apps/user/tests/test_profile.py index 3da6c5e7..465144c9 100644 --- a/apps/user/tests/test_profile.py +++ b/apps/user/tests/test_profile.py @@ -161,7 +161,7 @@ def test_my_profile_access(self): def test_autocompletes(self): # All autocompletes are forbidden for al in profile_autocompletes: - url = reverse('user-%s-ac' % al) + url = '%s?q=test' % reverse('user-%s-ac' % al) response = self.client.get(url) self.assertEqual(response.status_code, 403, url) @@ -270,7 +270,7 @@ def test_other_profile_accesses(self): def test_autocompletes(self): # All autocompletes are permitted for al in profile_autocompletes: - url = reverse('user-%s-ac' % al) + url = '%s?q=test' % reverse('user-%s-ac' % al) response = self.client.get(url) self.assertEqual(response.status_code, 200, url) diff --git a/apps/user/views/autocomplete.py b/apps/user/views/autocomplete.py index f9690103..a1635f52 100644 --- a/apps/user/views/autocomplete.py +++ b/apps/user/views/autocomplete.py @@ -48,7 +48,8 @@ def get_queryset(self): # Only non-deleted qs = qs.exclude(profile__status=USERSTATUS_DELETED) if q: - qs = UserProfileFilterSet.filter_wide(qs, '', q) + upfs = UserProfileFilterSet() + qs = upfs.filter_wide(qs, '', q) return qs else: raise PermissionDenied @@ -64,7 +65,7 @@ def get_queryset(self): return qs.filter( Q(profile__formation__in=FORMATION_KEYS) | Q(profile__actor_for__isnull=False) - ) + ).distinct() class Helpers(PersonAutocomplete): @@ -91,4 +92,4 @@ def get_queryset(self): qs = super(Actors, self).get_queryset() return qs.exclude( profile__actor_for__isnull=True - ) + ).distinct() diff --git a/apps/user/views/standard.py b/apps/user/views/standard.py index 4013ca79..353c71a4 100644 --- a/apps/user/views/standard.py +++ b/apps/user/views/standard.py @@ -112,7 +112,7 @@ def __init__(self, data=None, *args, **kwargs): elif len(cantons) == 1: del(self.filters['profile__activity_cantons']) - def filter_cantons(queryset, name, value): + def filter_cantons(self, queryset, name, value): if value: allcantons_filter = [ Q(profile__activity_cantons__contains=canton) @@ -123,7 +123,7 @@ def filter_cantons(queryset, name, value): return queryset.filter(reduce(operator.or_, allcantons_filter)) return queryset - def filter_wide(queryset, name, value): + def filter_wide(self, queryset, name, value): if value: allfields_filter = [ Q(last_name__icontains=value), diff --git a/defivelo/roles.py b/defivelo/roles.py index 75f3096d..3a2b313e 100644 --- a/defivelo/roles.py +++ b/defivelo/roles.py @@ -26,7 +26,6 @@ @memoize() def user_cantons(user): - if has_permission(user, 'cantons_all'): return DV_STATES elif has_permission(user, 'cantons_mine'):