1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Fix broken WEI permissions

This commit is contained in:
Yohann D'ANELLO 2020-04-24 14:03:25 +02:00
parent edf2f793e2
commit 16079e3cc5
4 changed files with 232 additions and 46 deletions

View File

@ -118,6 +118,13 @@
"name": "1A"
}
},
{
"model": "member.role",
"pk": 18,
"fields": {
"name": "Adhérent WEI"
}
},
{
"model": "wei.weirole",
"pk": 12,
@ -148,6 +155,11 @@
"pk": 17,
"fields": {}
},
{
"model": "wei.weirole",
"pk": 18,
"fields": {}
},
{
"model": "permission.permissionmask",
"pk": 1,
@ -1320,11 +1332,11 @@
"wei",
"weiclub"
],
"query": "{}",
"query": "{\"pk\": [\"club\", \"pk\"]}",
"type": "view",
"mask": 1,
"field": "",
"description": "View all WEI"
"description": "View my WEI"
}
},
{
@ -1410,7 +1422,7 @@
"wei",
"weiregistration"
],
"query": "{\"user\": [\"user\"], \"wei\": [\"club\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"], \"membership\": null}",
"query": "{\"user\": [\"user\"], \"wei__year\": [\"today\", \"year\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"], \"membership\": null}",
"type": "add",
"mask": 1,
"field": "",
@ -1650,7 +1662,7 @@
"wei",
"weiregistration"
],
"query": "{\"user\": [\"user\"], \"club\": [\"club\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}",
"query": "{\"user\": [\"user\"], \"wei\": [\"club\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "emergency_contact_name",
@ -1680,7 +1692,7 @@
"wei",
"weiregistration"
],
"query": "{\"user\": [\"user\"], \"club\": [\"club\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}",
"query": "{\"user\": [\"user\"], \"wei\": [\"club\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "emergency_contact_phone",
@ -1725,7 +1737,7 @@
"wei",
"bus"
],
"query": "{\"wei\": [\"club\"]}",
"query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
"type": "change",
"mask": 3,
"field": "name",
@ -1785,7 +1797,7 @@
"wei",
"bus"
],
"query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", {\"first_year\": false, \"club__weiclub__end_date__lte\": [\"today\"]}]]",
"query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"wei__date_end__lte\": [\"today\"]}]]",
"type": "view",
"mask": 1,
"field": "",
@ -1800,7 +1812,7 @@
"wei",
"busteam"
],
"query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", {\"first_year\": false, \"club__weiclub__end_date__lte\": [\"today\"]}]]",
"query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"wei__date_end__lte\": [\"today\"]}]]",
"type": "view",
"mask": 1,
"field": "",
@ -1815,7 +1827,7 @@
"wei",
"weimembership"
],
"query": "[\"AND\", {\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}, [\"OR\", {\"registration__soge_credit\": true}, {\"user__note__balance__gte\": [\"F\", \"fee\"]}]]",
"query": "[\"AND\", {\"club\": [\"club\"], \"club__weiclub__membership_end__gte\": [\"today\"]}, [\"OR\", {\"registration__soge_credit\": true}, {\"user__note__balance__gte\": [\"F\", \"fee\"]}]]",
"type": "add",
"mask": 3,
"field": "",
@ -1830,7 +1842,7 @@
"wei",
"weimembership"
],
"query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
"query": "{\"club\": [\"club\"], \"club__weiclub__membership_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "bus",
@ -1845,7 +1857,7 @@
"wei",
"weimembership"
],
"query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
"query": "{\"club\": [\"club\"], \"club__weiclub__membership_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "team",
@ -1860,7 +1872,7 @@
"wei",
"weimembership"
],
"query": "{\"wei\": [\"club\"]}",
"query": "{\"club\": [\"club\"]}",
"type": "view",
"mask": 1,
"field": "",
@ -1875,7 +1887,7 @@
"wei",
"weimembership"
],
"query": "[\"AND\", {\"user\": [\"user\"], \"wei\": [\"club\"]}, [\"OR\", {\"first_year\": false, \"club__weiclub__end_date__lte\": [\"today\"]}]]",
"query": "[\"AND\", {\"user\": [\"user\"], \"club\": [\"club\"]}, [\"OR\", {\"registration__first_year\": false, \"club__weiclub__date_end__lte\": [\"today\"]}]]",
"type": "view",
"mask": 1,
"field": "",
@ -1890,7 +1902,7 @@
"wei",
"weimembership"
],
"query": "{\"wei\": [\"club\"], \"bus\": [\"membership\", \"weimembership\", \"bus\"]}",
"query": "{\"club\": [\"club\"], \"bus\": [\"membership\", \"weimembership\", \"bus\"]}",
"type": "view",
"mask": 1,
"field": "",
@ -1905,13 +1917,148 @@
"wei",
"weimembership"
],
"query": "{\"wei\": [\"club\"], \"team\": [\"membership\", \"weimembership\", \"team\"]}",
"query": "{\"club\": [\"club\"], \"team\": [\"membership\", \"weimembership\", \"team\"]}",
"type": "view",
"mask": 1,
"field": "",
"description": "View the members of the team"
}
},
{
"model": "permission.permission",
"pk": 117,
"fields": {
"model": [
"wei",
"bus"
],
"query": "{\"pk\": [\"membership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "name",
"description": "Update the name of my bus"
}
},
{
"model": "permission.permission",
"pk": 118,
"fields": {
"model": [
"wei",
"bus"
],
"query": "{\"pk\": [\"membership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "description",
"description": "Update the description of my bus"
}
},
{
"model": "permission.permission",
"pk": 119,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "add",
"mask": 1,
"field": "",
"description": "Add a team to my bus"
}
},
{
"model": "permission.permission",
"pk": 120,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "name",
"description": "Update the name of a team of my bus"
}
},
{
"model": "permission.permission",
"pk": 121,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "color",
"description": "Update the color of a team of my bus"
}
},
{
"model": "permission.permission",
"pk": 122,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "description",
"description": "Update the description of a team of my bus"
}
},
{
"model": "permission.permission",
"pk": 123,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "name",
"description": "Update the name of my team"
}
},
{
"model": "permission.permission",
"pk": 124,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "color",
"description": "Update the color of my team"
}
},
{
"model": "permission.permission",
"pk": 125,
"fields": {
"model": [
"wei",
"busteam"
],
"query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change",
"mask": 1,
"field": "description",
"description": "Update the description of my team"
}
},
{
"model": "permission.rolepermissions",
"pk": 1,
@ -1952,21 +2099,12 @@
16,
17,
18,
97,
99,
101,
70,
108,
109,
78,
79,
114,
83,
84,
87,
90,
93,
95
83
]
}
},
@ -2180,7 +2318,18 @@
111,
112,
113,
114
114,
115,
116,
117,
118,
119,
120,
121,
122,
123,
124,
125
]
}
},
@ -2190,15 +2339,6 @@
"fields": {
"role": 10,
"permissions": [
32,
33,
56,
58,
55,
57,
52,
53,
54,
23,
24,
25,
@ -2207,7 +2347,16 @@
28,
29,
30,
31
31,
32,
33,
52,
53,
54,
55,
56,
57,
58
]
}
},
@ -2267,7 +2416,12 @@
"fields": {
"role": 13,
"permissions": [
115
115,
117,
118,
120,
121,
122
]
}
},
@ -2280,5 +2434,26 @@
116
]
}
},
{
"model": "permission.rolepermissions",
"pk": 16,
"fields": {
"role": 18,
"permissions": [
77,
84,
87,
90,
93,
95,
97,
99,
101,
108,
109,
114
]
}
}
]

View File

@ -11,7 +11,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.db.models import Q, Count
from django.db.models.functions import Lower
from django.db.models.functions.text import Lower
from django.forms import HiddenInput
from django.http import HttpResponse
from django.shortcuts import redirect
@ -540,6 +540,9 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
model = WEIRegistration
form_class = WEIRegistrationForm
def get_queryset(self, **kwargs):
return WEIRegistration.objects
def dispatch(self, request, *args, **kwargs):
wei = self.get_object().wei
today = date.today()
@ -702,7 +705,9 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
if "preferred_team_pk" in information and len(information["preferred_team_pk"]) == 1:
form["team"].initial = Bus.objects.get(pk=information["preferred_team_pk"][0])
if "preferred_roles_pk" in information:
form["roles"].initial = WEIRole.objects.filter(pk__in=information["preferred_roles_pk"]).all()
form["roles"].initial = WEIRole.objects.filter(
Q(pk__in=information["preferred_roles_pk"]) | Q(name="Adhérent WEI")
).all()
return form
def form_valid(self, form):
@ -749,7 +754,12 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
membership.roles.set(WEIRole.objects.filter(name="1A").all())
membership.save()
return super().form_valid(form)
ret = super().form_valid(form)
membership.refresh_from_db()
membership.roles.add(WEIRole.objects.get("Adhérent WEI"))
return ret
def get_success_url(self):
self.object.refresh_from_db()
@ -845,10 +855,11 @@ class MemberListRenderView(LoginRequiredMixin, View):
qs = qs.filter(club__pk=self.kwargs["wei_pk"]).order_by(
Lower('bus__name'),
Lower('team__name'),
'roles',
'user__profile__promotion',
Lower('user__last_name'),
Lower('user__first_name'),
).distinct()
'id',
)
if "bus_pk" in self.kwargs:
qs = qs.filter(bus__pk=self.kwargs["bus_pk"])
@ -856,7 +867,7 @@ class MemberListRenderView(LoginRequiredMixin, View):
if "team_pk" in self.kwargs:
qs = qs.filter(team__pk=self.kwargs["team_pk"] if self.kwargs["team_pk"] else None)
return qs
return qs.distinct()
def get(self, request, **kwargs):
qs = self.get_queryset()

View File

@ -106,12 +106,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
<a class="nav-link" href="{% url 'activity:activity_list' %}"><i class="fa fa-calendar"></i> {% trans 'Activities' %}</a>
</li>
{% endif %}
{% if "treasury.invoice"|not_empty_model_change_list %}
{% if "treasury.invoice"|not_empty_model_list %}
<li class="nav-item active">
<a class="nav-link" href="{% url 'treasury:invoice_list' %}"><i class="fa fa-money"></i> {% trans 'Treasury' %}</a>
</li>
{% endif %}
{% if "wei.weiclub"|not_empty_model_change_list %}
{% if "wei.weiclub"|not_empty_model_list %}
<li class="nav-item active">
<a class="nav-link" href="{% url 'wei:current_wei_detail' %}"><i class="fa fa-bus"></i> {% trans 'WEI' %}</a>
</li>

View File

@ -30,7 +30,7 @@
{% for membership in memberships %}
{{ membership.user.last_name|safe }} & {{ membership.user.first_name|safe }} & {{ membership.registration.birth_date|safe }}
& {{ membership.registration.get_gender_display|safe }} & {{ membership.user.profile.section_generated|safe }} & {{ membership.bus.name|safe }}
& {% if membership.team %}{{ membership.team.name|safe }}{% else %}--{% endif %} & {{ membership.roles.all|join:", "|safe }} \\
& {% if membership.team %}{{ membership.team.name|safe }}{% else %}--{% endif %} & {{ membership.roles.first|safe }} \\
{% endfor %}
\end{tabularx}
\end{center}