Compare commits

..

No commits in common. "518de596bb0999f1cac7c2c748ae5ae9a12e2d5c" and "a9ccf4601045333ac5d5a0401475684c83482cbf" have entirely different histories.

6 changed files with 24 additions and 117 deletions

View File

@ -1,12 +1,13 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import datetime
from django.conf import settings from django.conf import settings
from django.contrib.auth.backends import ModelBackend from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db.models import Q, F from django.db.models import Q, F
from django.utils import timezone
from note.models import Note, NoteUser, NoteClub, NoteSpecial from note.models import Note, NoteUser, NoteClub, NoteSpecial
from note_kfet.middlewares import get_current_session from note_kfet.middlewares import get_current_session
from member.models import Membership, Club from member.models import Membership, Club
@ -42,8 +43,8 @@ class PermissionBackend(ModelBackend):
).filter( ).filter(
( (
Q( Q(
rolepermissions__role__membership__date_start__lte=timezone.now().today(), rolepermissions__role__membership__date_start__lte=datetime.date.today(),
rolepermissions__role__membership__date_end__gte=timezone.now().today(), rolepermissions__role__membership__date_end__gte=datetime.date.today(),
) )
| Q(permanent=True) | Q(permanent=True)
) )
@ -97,8 +98,8 @@ class PermissionBackend(ModelBackend):
NoteSpecial=NoteSpecial, NoteSpecial=NoteSpecial,
F=F, F=F,
Q=Q, Q=Q,
now=timezone.now(), now=datetime.datetime.now(),
today=timezone.now().date(), today=datetime.date.today(),
) )
yield permission yield permission

View File

@ -272,7 +272,7 @@
"note", "note",
"alias" "alias"
], ],
"query": "[\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__memberships__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}]", "query": "[\"OR\", {\"note__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club__name\": \"Kfet\"}], [\"all\"]]}, {\"note__in\": [\"NoteClub\", \"objects\", [\"all\"]]}]",
"type": "view", "type": "view",
"mask": 1, "mask": 1,
"field": "", "field": "",
@ -480,7 +480,7 @@
"note", "note",
"note" "note"
], ],
"query": "[\"OR\", {\"pk\": [\"club\", \"note\", \"pk\"]}, {\"pk__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__memberships__club\": [\"club\"]}], [\"all\"]]}]", "query": "[\"OR\", {\"pk\": [\"club\", \"note\", \"pk\"]}, {\"pk__in\": [\"NoteUser\", \"objects\", [\"filter\", {\"user__membership__club\": [\"club\"]}], [\"all\"]]}]",
"type": "view", "type": "view",
"mask": 2, "mask": 2,
"field": "", "field": "",
@ -1872,7 +1872,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus__wei\": [\"club\"], \"bus__wei__membership_end__gte\": [\"today\"]}", "query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
"type": "add", "type": "add",
"mask": 3, "mask": 3,
"field": "", "field": "",
@ -1888,7 +1888,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus__wei\": [\"club\"], \"bus__wei__membership_end__gte\": [\"today\"]}", "query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 3, "mask": 3,
"field": "", "field": "",
@ -1920,7 +1920,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "[\"AND\", {\"bus__wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"bus__wei__date_end__lte\": [\"today\"]}]]", "query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"wei__date_end__lte\": [\"today\"]}]]",
"type": "view", "type": "view",
"mask": 1, "mask": 1,
"field": "", "field": "",
@ -1936,7 +1936,7 @@
"wei", "wei",
"weimembership" "weimembership"
], ],
"query": "[\"AND\", {\"club\": [\"club\"], \"club__weiclub__membership_end__gte\": [\"today\"]}, [\"OR\", {\"registration__soge_credit\": true}, {\"user__note__balance__gte\": {\"F\": [\"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", "type": "add",
"mask": 3, "mask": 3,
"field": "", "field": "",
@ -2048,7 +2048,7 @@
"wei", "wei",
"bus" "bus"
], ],
"query": "{\"pk\": [\"membership\", \"weimembership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}", "query": "{\"pk\": [\"membership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "name", "field": "name",
@ -2064,7 +2064,7 @@
"wei", "wei",
"bus" "bus"
], ],
"query": "{\"pk\": [\"membership\", \"weimembership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}", "query": "{\"pk\": [\"membership\", \"bus\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "description", "field": "description",
@ -2080,7 +2080,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus\": [\"membership\", \"weimembership\", \"bus\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "add", "type": "add",
"mask": 1, "mask": 1,
"field": "", "field": "",
@ -2096,7 +2096,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus\": [\"membership\", \"weimembership\", \"bus\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "name", "field": "name",
@ -2112,7 +2112,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus\": [\"membership\", \"weimembership\", \"bus\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "color", "field": "color",
@ -2128,7 +2128,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"bus\": [\"membership\", \"weimembership\", \"bus\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"bus\": [\"membership\", \"bus\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "description", "field": "description",
@ -2144,7 +2144,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"pk\": [\"membership\", \"weimembership\", \"team\", \"pk\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "name", "field": "name",
@ -2160,7 +2160,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"pk\": [\"membership\", \"weimembership\", \"team\", \"pk\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "color", "field": "color",
@ -2176,7 +2176,7 @@
"wei", "wei",
"busteam" "busteam"
], ],
"query": "{\"pk\": [\"membership\", \"weimembership\", \"team\", \"pk\"], \"bus__wei__date_end__gte\": [\"today\"]}", "query": "{\"pk\": [\"membership\", \"team\", \"pk\"], \"wei__date_end__gte\": [\"today\"]}",
"type": "change", "type": "change",
"mask": 1, "mask": 1,
"field": "description", "field": "description",

View File

@ -1,86 +0,0 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.models import User
from django.core.exceptions import FieldError
from django.db.models import F, Q
from django.test import TestCase
from django.utils import timezone
from member.models import Club, Membership
from note.models import NoteUser, Note, NoteClub, NoteSpecial
from wei.models import WEIMembership, WEIRegistration, WEIClub, Bus, BusTeam
from .models import Permission
class PermissionQueryTestCase(TestCase):
fixtures = ('initial', )
@classmethod
def setUpTestData(cls):
user = User.objects.create(username="user")
NoteUser.objects.create(user=user)
wei = WEIClub.objects.create(
name="wei",
date_start=timezone.now().date(),
date_end=timezone.now().date(),
)
NoteClub.objects.create(club=wei)
weiregistration = WEIRegistration.objects.create(
user=user,
wei=wei,
birth_date=timezone.now().date(),
)
bus = Bus.objects.create(
name="bus",
wei=wei,
)
team = BusTeam.objects.create(
name="team",
bus=bus,
color=0xFFFFFF,
)
WEIMembership.objects.create(
user=user,
club=wei,
registration=weiregistration,
bus=bus,
team=team,
)
def test_permission_queries(self):
"""
Check for all permissions that the query is compilable and that the database can parse the query.
We use a random user with a random WEIClub (to use permissions for the WEI) in a random team in a random bus.
"""
for perm in Permission.objects.all():
instanced = perm.about(
user=User.objects.get(),
club=WEIClub.objects.get(),
membership=Membership.objects.get(),
User=User,
Club=Club,
Membership=Membership,
Note=Note,
NoteUser=NoteUser,
NoteClub=NoteClub,
NoteSpecial=NoteSpecial,
F=F,
Q=Q,
now=timezone.now(),
today=timezone.now().date(),
)
try:
instanced.update_query()
query = instanced.query
model = perm.model.model_class()
model.objects.filter(query).all()
# print("Good query for permission", perm)
except (FieldError, AttributeError, ValueError):
print("Query error for permission", perm)
print("Query:", perm.query)
if instanced.query:
print("Compiled query:", instanced.query)
raise
print("All permission queries are well formed")

View File

@ -1739,7 +1739,7 @@ msgstr "Consommer"
#: templates/note/conso_form.html:39 templates/note/transaction_form.html:61 #: templates/note/conso_form.html:39 templates/note/transaction_form.html:61
#: templates/note/transaction_form.html:76 #: templates/note/transaction_form.html:76
msgid "Name or alias..." msgid "Name or alias..."
msgstr "Pseudo ou alias ..." msgstr ""
#: templates/note/conso_form.html:48 #: templates/note/conso_form.html:48
msgid "Select consumptions" msgid "Select consumptions"

View File

@ -335,15 +335,7 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr
}) })
}); });
});// end getJSON alias $("#validate_" + id).html("<i class='fa fa-spinner'></i>");
});
}// end function autocomplete
// When a validate button is clicked, we switch the validation status
function de_validate(id, validated) {
let invalidity_reason = $("#invalidity_reason_" + id).val();
$("#validate_" + id).html("<strong style=\"font-size: 16pt;\">⟳ ...</strong>");
// Perform a PATCH request to the API in order to update the transaction // Perform a PATCH request to the API in order to update the transaction
// If the user has insufficient rights, an error message will appear // If the user has insufficient rights, an error message will appear

View File

@ -63,7 +63,7 @@
{% if not activity.open and ".change__valid"|has_perm:activity %} {% if not activity.open and ".change__valid"|has_perm:activity %}
<a class="btn btn-success btn-sm my-1" id="validate_activity"> {% if activity.valid %}{% trans "invalidate"|capfirst %}{% else %}{% trans "validate"|capfirst %}{% endif %}</a> <a class="btn btn-success btn-sm my-1" id="validate_activity"> {% if activity.valid %}{% trans "invalidate"|capfirst %}{% else %}{% trans "validate"|capfirst %}{% endif %}</a>
{% endif %} {% endif %}
{% if ".change_"|has_perm:activity %} {% if ".view_"|has_perm:activity %}
<a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_update' pk=activity.pk %}"> {% trans "edit"|capfirst %}</a> <a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_update' pk=activity.pk %}"> {% trans "edit"|capfirst %}</a>
{% endif %} {% endif %}
{% if activity.activity_type.can_invite and not activity_started %} {% if activity.activity_type.can_invite and not activity_started %}