Add initial WEI permissions

This commit is contained in:
Yohann D'ANELLO 2020-04-22 13:28:52 +02:00
parent 640f0f9a31
commit a85a5bf8fe
7 changed files with 2351 additions and 1248 deletions

View File

@ -75,7 +75,9 @@ class PermissionBackend(ModelBackend):
NoteClub=NoteClub, NoteClub=NoteClub,
NoteSpecial=NoteSpecial, NoteSpecial=NoteSpecial,
F=F, F=F,
Q=Q Q=Q,
now=datetime.datetime.now(),
today=datetime.date.today(),
) )
yield permission yield permission

File diff suppressed because it is too large Load Diff

View File

@ -120,7 +120,12 @@ class Permission(models.Model):
('delete', 'delete') ('delete', 'delete')
] ]
model = models.ForeignKey(ContentType, on_delete=models.CASCADE, related_name='+') model = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
related_name='+',
verbose_name=_("model"),
)
# A json encoded Q object with the following grammar # A json encoded Q object with the following grammar
# query -> [] | {} (the empty query representing all objects) # query -> [] | {} (the empty query representing all objects)
@ -142,18 +147,34 @@ class Permission(models.Model):
# Examples: # Examples:
# Q(is_superuser=True) := {"is_superuser": true} # Q(is_superuser=True) := {"is_superuser": true}
# ~Q(is_superuser=True) := ["NOT", {"is_superuser": true}] # ~Q(is_superuser=True) := ["NOT", {"is_superuser": true}]
query = models.TextField() query = models.TextField(
verbose_name=_("query"),
)
type = models.CharField(max_length=15, choices=PERMISSION_TYPES) type = models.CharField(
max_length=15,
choices=PERMISSION_TYPES,
verbose_name=_("type"),
)
mask = models.ForeignKey( mask = models.ForeignKey(
PermissionMask, PermissionMask,
on_delete=models.PROTECT, on_delete=models.PROTECT,
related_name="permissions",
verbose_name=_("mask"),
) )
field = models.CharField(max_length=255, blank=True) field = models.CharField(
max_length=255,
blank=True,
verbose_name=_("field"),
)
description = models.CharField(max_length=255, blank=True) description = models.CharField(
max_length=255,
blank=True,
verbose_name=_("description"),
)
class Meta: class Meta:
unique_together = ('model', 'query', 'type', 'field') unique_together = ('model', 'query', 'type', 'field')
@ -277,10 +298,7 @@ class Permission(models.Model):
return InstancedPermission(self.model, query, self.type, self.field, self.mask, **kwargs) return InstancedPermission(self.model, query, self.type, self.field, self.mask, **kwargs)
def __str__(self): def __str__(self):
if self.field: return self.description
return _("Can {type} {model}.{field} in {query}").format(type=self.type, model=self.model, field=self.field, query=self.query)
else:
return _("Can {type} {model} in {query}").format(type=self.type, model=self.model, query=self.query)
class RolePermissions(models.Model): class RolePermissions(models.Model):

View File

@ -34,7 +34,6 @@ class WEISurveyInformation:
Store the data of the survey into the database, with the information of the registration. Store the data of the survey into the database, with the information of the registration.
""" """
registration.information = self.__dict__ registration.information = self.__dict__
registration.save()
class WEISurveyAlgorithm: class WEISurveyAlgorithm:
@ -140,6 +139,10 @@ class WEISurvey:
Store the information of the survey into the database. Store the information of the survey into the database.
""" """
self.information.save(self.registration) self.information.save(self.registration)
# The information is forced-saved.
# We don't want that anyone can update manually the information, so since most users don't have the
# right to save the information of a registration, we force save.
self.registration._force_save = True
self.registration.save() self.registration.save()
@classmethod @classmethod

View File

@ -28,8 +28,12 @@ from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIM
class CurrentWEIDetailView(LoginRequiredMixin, RedirectView): class CurrentWEIDetailView(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs): def get_redirect_url(self, *args, **kwargs):
wei = WEIClub.objects.filter(membership_start__lte=date.today()).order_by('date_start').last() wei = WEIClub.objects.filter(membership_start__lte=date.today()).order_by('date_start')
return reverse_lazy('wei:wei_detail', args=(wei.pk,)) if wei.exists():
wei = wei.last()
return reverse_lazy('wei:wei_detail', args=(wei.pk,))
else:
return reverse_lazy('wei:wei_list')
class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-22 03:51+0200\n" "POT-Creation-Date: 2020-04-22 13:28+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -71,13 +71,14 @@ msgid "activity types"
msgstr "" msgstr ""
#: apps/activity/models.py:53 apps/note/models/transactions.py:75 #: apps/activity/models.py:53 apps/note/models/transactions.py:75
#: apps/permission/models.py:103 apps/wei/models.py:68 apps/wei/models.py:124 #: apps/permission/models.py:103 apps/permission/models.py:176
#: apps/wei/models.py:68 apps/wei/models.py:124
#: templates/activity/activity_detail.html:16 #: templates/activity/activity_detail.html:16
msgid "description" msgid "description"
msgstr "" msgstr ""
#: apps/activity/models.py:60 apps/note/models/notes.py:164 #: apps/activity/models.py:60 apps/note/models/notes.py:164
#: apps/note/models/transactions.py:65 #: apps/note/models/transactions.py:65 apps/permission/models.py:157
#: templates/activity/activity_detail.html:19 #: templates/activity/activity_detail.html:19
msgid "type" msgid "type"
msgstr "" msgstr ""
@ -224,7 +225,7 @@ msgstr ""
msgid "IP Address" msgid "IP Address"
msgstr "" msgstr ""
#: apps/logs/models.py:35 #: apps/logs/models.py:35 apps/permission/models.py:127
msgid "model" msgid "model"
msgstr "" msgstr ""
@ -412,7 +413,7 @@ msgstr ""
msgid "clubs" msgid "clubs"
msgstr "" msgstr ""
#: apps/member/models.py:210 apps/permission/models.py:294 #: apps/member/models.py:210 apps/permission/models.py:312
msgid "role" msgid "role"
msgstr "" msgstr ""
@ -432,7 +433,7 @@ msgstr ""
msgid "fee" msgid "fee"
msgstr "" msgstr ""
#: apps/member/models.py:268 apps/member/views.py:505 apps/wei/views.py:727 #: apps/member/models.py:268 apps/member/views.py:505 apps/wei/views.py:731
msgid "User is not a member of the parent club" msgid "User is not a member of the parent club"
msgstr "" msgstr ""
@ -475,7 +476,7 @@ msgstr ""
msgid "Search user" msgid "Search user"
msgstr "" msgstr ""
#: apps/member/views.py:500 apps/wei/views.py:718 #: apps/member/views.py:500 apps/wei/views.py:722
msgid "" msgid ""
"This user don't have enough money to join this club, and can't have a " "This user don't have enough money to join this club, and can't have a "
"negative balance." "negative balance."
@ -741,12 +742,12 @@ msgstr ""
msgid "Consumptions" msgid "Consumptions"
msgstr "" msgstr ""
#: apps/permission/models.py:82 apps/permission/models.py:281 #: apps/permission/models.py:82
#, python-brace-format #, python-brace-format
msgid "Can {type} {model}.{field} in {query}" msgid "Can {type} {model}.{field} in {query}"
msgstr "" msgstr ""
#: apps/permission/models.py:84 apps/permission/models.py:283 #: apps/permission/models.py:84
#, python-brace-format #, python-brace-format
msgid "Can {type} {model} in {query}" msgid "Can {type} {model} in {query}"
msgstr "" msgstr ""
@ -763,19 +764,31 @@ msgstr ""
msgid "permission masks" msgid "permission masks"
msgstr "" msgstr ""
#: apps/permission/models.py:160 #: apps/permission/models.py:151
msgid "query"
msgstr ""
#: apps/permission/models.py:164
msgid "mask"
msgstr ""
#: apps/permission/models.py:170
msgid "field"
msgstr ""
#: apps/permission/models.py:181
msgid "permission" msgid "permission"
msgstr "" msgstr ""
#: apps/permission/models.py:161 #: apps/permission/models.py:182
msgid "permissions" msgid "permissions"
msgstr "" msgstr ""
#: apps/permission/models.py:166 #: apps/permission/models.py:187
msgid "Specifying field applies only to view and change permission types." msgid "Specifying field applies only to view and change permission types."
msgstr "" msgstr ""
#: apps/permission/models.py:304 apps/permission/models.py:305 #: apps/permission/models.py:322 apps/permission/models.py:323
msgid "role permissions" msgid "role permissions"
msgstr "" msgstr ""
@ -974,17 +987,17 @@ msgstr ""
msgid "credit transaction" msgid "credit transaction"
msgstr "" msgstr ""
#: apps/treasury/models.py:292 #: apps/treasury/models.py:296
msgid "" msgid ""
"This user doesn't have enough money to pay the memberships with its note. " "This user doesn't have enough money to pay the memberships with its note. "
"Please ask her/him to credit the note before invalidating this credit." "Please ask her/him to credit the note before invalidating this credit."
msgstr "" msgstr ""
#: apps/treasury/models.py:303 templates/treasury/sogecredit_detail.html:10 #: apps/treasury/models.py:308 templates/treasury/sogecredit_detail.html:10
msgid "Credit from the Société générale" msgid "Credit from the Société générale"
msgstr "" msgstr ""
#: apps/treasury/models.py:304 #: apps/treasury/models.py:309
msgid "Credits from the Société générale" msgid "Credits from the Société générale"
msgstr "" msgstr ""
@ -1227,41 +1240,41 @@ msgstr ""
msgid "Teams" msgid "Teams"
msgstr "" msgstr ""
#: apps/wei/views.py:166 #: apps/wei/views.py:170
msgid "Find WEI Membership" msgid "Find WEI Membership"
msgstr "" msgstr ""
#: apps/wei/views.py:201 #: apps/wei/views.py:205
msgid "Find WEI Registration" msgid "Find WEI Registration"
msgstr "" msgstr ""
#: apps/wei/views.py:410 templates/wei/weiclub_info.html:62 #: apps/wei/views.py:414 templates/wei/weiclub_info.html:62
msgid "Register 1A" msgid "Register 1A"
msgstr "" msgstr ""
#: apps/wei/views.py:431 apps/wei/views.py:499 #: apps/wei/views.py:435 apps/wei/views.py:503
msgid "This user is already registered to this WEI." msgid "This user is already registered to this WEI."
msgstr "" msgstr ""
#: apps/wei/views.py:436 #: apps/wei/views.py:440
msgid "" msgid ""
"This user can't be in her/his first year since he/she has already participed " "This user can't be in her/his first year since he/she has already participed "
"to a WEI." "to a WEI."
msgstr "" msgstr ""
#: apps/wei/views.py:464 templates/wei/weiclub_info.html:63 #: apps/wei/views.py:468 templates/wei/weiclub_info.html:63
msgid "Register 2A+" msgid "Register 2A+"
msgstr "" msgstr ""
#: apps/wei/views.py:482 apps/wei/views.py:565 #: apps/wei/views.py:486 apps/wei/views.py:569
msgid "You already opened an account in the Société générale." msgid "You already opened an account in the Société générale."
msgstr "" msgstr ""
#: apps/wei/views.py:722 #: apps/wei/views.py:726
msgid "This user didn't give her/his caution check." msgid "This user didn't give her/his caution check."
msgstr "" msgstr ""
#: apps/wei/views.py:791 apps/wei/views.py:811 apps/wei/views.py:821 #: apps/wei/views.py:795 apps/wei/views.py:815 apps/wei/views.py:825
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12 #: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
#: templates/wei/survey_end.html:12 #: templates/wei/survey_end.html:12
msgid "Survey WEI" msgid "Survey WEI"

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-22 03:51+0200\n" "POT-Creation-Date: 2020-04-22 13:28+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -67,13 +67,14 @@ msgid "activity types"
msgstr "types d'activité" msgstr "types d'activité"
#: apps/activity/models.py:53 apps/note/models/transactions.py:75 #: apps/activity/models.py:53 apps/note/models/transactions.py:75
#: apps/permission/models.py:103 apps/wei/models.py:68 apps/wei/models.py:124 #: apps/permission/models.py:103 apps/permission/models.py:176
#: apps/wei/models.py:68 apps/wei/models.py:124
#: templates/activity/activity_detail.html:16 #: templates/activity/activity_detail.html:16
msgid "description" msgid "description"
msgstr "description" msgstr "description"
#: apps/activity/models.py:60 apps/note/models/notes.py:164 #: apps/activity/models.py:60 apps/note/models/notes.py:164
#: apps/note/models/transactions.py:65 #: apps/note/models/transactions.py:65 apps/permission/models.py:157
#: templates/activity/activity_detail.html:19 #: templates/activity/activity_detail.html:19
msgid "type" msgid "type"
msgstr "type" msgstr "type"
@ -220,7 +221,7 @@ msgstr "Logs"
msgid "IP Address" msgid "IP Address"
msgstr "Adresse IP" msgstr "Adresse IP"
#: apps/logs/models.py:35 #: apps/logs/models.py:35 apps/permission/models.py:127
msgid "model" msgid "model"
msgstr "Modèle" msgstr "Modèle"
@ -412,7 +413,7 @@ msgstr "club"
msgid "clubs" msgid "clubs"
msgstr "clubs" msgstr "clubs"
#: apps/member/models.py:210 apps/permission/models.py:294 #: apps/member/models.py:210 apps/permission/models.py:312
msgid "role" msgid "role"
msgstr "rôle" msgstr "rôle"
@ -432,7 +433,7 @@ msgstr "l'adhésion finit le"
msgid "fee" msgid "fee"
msgstr "cotisation" msgstr "cotisation"
#: apps/member/models.py:268 apps/member/views.py:505 apps/wei/views.py:727 #: apps/member/models.py:268 apps/member/views.py:505 apps/wei/views.py:731
msgid "User is not a member of the parent club" msgid "User is not a member of the parent club"
msgstr "L'utilisateur n'est pas membre du club parent" msgstr "L'utilisateur n'est pas membre du club parent"
@ -475,7 +476,7 @@ msgstr "Un alias avec un nom similaire existe déjà."
msgid "Search user" msgid "Search user"
msgstr "Chercher un utilisateur" msgstr "Chercher un utilisateur"
#: apps/member/views.py:500 apps/wei/views.py:718 #: apps/member/views.py:500 apps/wei/views.py:722
msgid "" msgid ""
"This user don't have enough money to join this club, and can't have a " "This user don't have enough money to join this club, and can't have a "
"negative balance." "negative balance."
@ -744,12 +745,12 @@ msgstr "Transférer de l'argent"
msgid "Consumptions" msgid "Consumptions"
msgstr "Consommations" msgstr "Consommations"
#: apps/permission/models.py:82 apps/permission/models.py:281 #: apps/permission/models.py:82
#, python-brace-format #, python-brace-format
msgid "Can {type} {model}.{field} in {query}" msgid "Can {type} {model}.{field} in {query}"
msgstr "" msgstr ""
#: apps/permission/models.py:84 apps/permission/models.py:283 #: apps/permission/models.py:84
#, python-brace-format #, python-brace-format
msgid "Can {type} {model} in {query}" msgid "Can {type} {model} in {query}"
msgstr "" msgstr ""
@ -766,19 +767,31 @@ msgstr "masque de permissions"
msgid "permission masks" msgid "permission masks"
msgstr "masques de permissions" msgstr "masques de permissions"
#: apps/permission/models.py:160 #: apps/permission/models.py:151
msgid "query"
msgstr "requête"
#: apps/permission/models.py:164
msgid "mask"
msgstr "masque"
#: apps/permission/models.py:170
msgid "field"
msgstr "champ"
#: apps/permission/models.py:181
msgid "permission" msgid "permission"
msgstr "permission" msgstr "permission"
#: apps/permission/models.py:161 #: apps/permission/models.py:182
msgid "permissions" msgid "permissions"
msgstr "permissions" msgstr "permissions"
#: apps/permission/models.py:166 #: apps/permission/models.py:187
msgid "Specifying field applies only to view and change permission types." msgid "Specifying field applies only to view and change permission types."
msgstr "" msgstr ""
#: apps/permission/models.py:304 apps/permission/models.py:305 #: apps/permission/models.py:322 apps/permission/models.py:323
msgid "role permissions" msgid "role permissions"
msgstr "Permissions par rôles" msgstr "Permissions par rôles"
@ -982,7 +995,7 @@ msgstr "Proxys de transactions spéciales"
msgid "credit transaction" msgid "credit transaction"
msgstr "transaction de crédit" msgstr "transaction de crédit"
#: apps/treasury/models.py:292 #: apps/treasury/models.py:296
msgid "" msgid ""
"This user doesn't have enough money to pay the memberships with its note. " "This user doesn't have enough money to pay the memberships with its note. "
"Please ask her/him to credit the note before invalidating this credit." "Please ask her/him to credit the note before invalidating this credit."
@ -990,11 +1003,11 @@ msgstr ""
"Cet utilisateur n'a pas assez d'argent pour payer les adhésions avec sa " "Cet utilisateur n'a pas assez d'argent pour payer les adhésions avec sa "
"note. Merci de lui demander de recharger sa note avant d'invalider ce crédit." "note. Merci de lui demander de recharger sa note avant d'invalider ce crédit."
#: apps/treasury/models.py:303 templates/treasury/sogecredit_detail.html:10 #: apps/treasury/models.py:308 templates/treasury/sogecredit_detail.html:10
msgid "Credit from the Société générale" msgid "Credit from the Société générale"
msgstr "Crédit de la Société générale" msgstr "Crédit de la Société générale"
#: apps/treasury/models.py:304 #: apps/treasury/models.py:309
msgid "Credits from the Société générale" msgid "Credits from the Société générale"
msgstr "Crédits de la Société générale" msgstr "Crédits de la Société générale"
@ -1252,23 +1265,23 @@ msgstr "Valider"
msgid "Teams" msgid "Teams"
msgstr "Équipes" msgstr "Équipes"
#: apps/wei/views.py:166 #: apps/wei/views.py:170
msgid "Find WEI Membership" msgid "Find WEI Membership"
msgstr "Trouver une adhésion au WEI" msgstr "Trouver une adhésion au WEI"
#: apps/wei/views.py:201 #: apps/wei/views.py:205
msgid "Find WEI Registration" msgid "Find WEI Registration"
msgstr "Trouver une inscription au WEI" msgstr "Trouver une inscription au WEI"
#: apps/wei/views.py:410 templates/wei/weiclub_info.html:62 #: apps/wei/views.py:414 templates/wei/weiclub_info.html:62
msgid "Register 1A" msgid "Register 1A"
msgstr "Inscrire un 1A" msgstr "Inscrire un 1A"
#: apps/wei/views.py:431 apps/wei/views.py:499 #: apps/wei/views.py:435 apps/wei/views.py:503
msgid "This user is already registered to this WEI." msgid "This user is already registered to this WEI."
msgstr "Cette personne est déjà inscrite au WEI." msgstr "Cette personne est déjà inscrite au WEI."
#: apps/wei/views.py:436 #: apps/wei/views.py:440
msgid "" msgid ""
"This user can't be in her/his first year since he/she has already participed " "This user can't be in her/his first year since he/she has already participed "
"to a WEI." "to a WEI."
@ -1276,19 +1289,19 @@ msgstr ""
"Cet utilisateur ne peut pas être en première année puisqu'iel a déjà " "Cet utilisateur ne peut pas être en première année puisqu'iel a déjà "
"participé à un WEI." "participé à un WEI."
#: apps/wei/views.py:464 templates/wei/weiclub_info.html:63 #: apps/wei/views.py:468 templates/wei/weiclub_info.html:63
msgid "Register 2A+" msgid "Register 2A+"
msgstr "Inscrire un 2A+" msgstr "Inscrire un 2A+"
#: apps/wei/views.py:482 apps/wei/views.py:565 #: apps/wei/views.py:486 apps/wei/views.py:569
msgid "You already opened an account in the Société générale." msgid "You already opened an account in the Société générale."
msgstr "Vous avez déjà ouvert un compte auprès de la société générale." msgstr "Vous avez déjà ouvert un compte auprès de la société générale."
#: apps/wei/views.py:722 #: apps/wei/views.py:726
msgid "This user didn't give her/his caution check." msgid "This user didn't give her/his caution check."
msgstr "Cet utilisateur n'a pas donné son chèque de caution." msgstr "Cet utilisateur n'a pas donné son chèque de caution."
#: apps/wei/views.py:791 apps/wei/views.py:811 apps/wei/views.py:821 #: apps/wei/views.py:795 apps/wei/views.py:815 apps/wei/views.py:825
#: templates/wei/survey.html:12 templates/wei/survey_closed.html:12 #: templates/wei/survey.html:12 templates/wei/survey_closed.html:12
#: templates/wei/survey_end.html:12 #: templates/wei/survey_end.html:12
msgid "Survey WEI" msgid "Survey WEI"
@ -1955,8 +1968,8 @@ msgstr ""
#: templates/treasury/sogecredit_detail.html:50 #: templates/treasury/sogecredit_detail.html:50
msgid "Please ask the user to credit its note before deleting this credit." msgid "Please ask the user to credit its note before deleting this credit."
msgstr "" msgstr ""
"Merci de demander à l'utilisateur de recharger sa note avant de " "Merci de demander à l'utilisateur de recharger sa note avant de supprimer la "
"supprimer la demande de crédit." "demande de crédit."
#: templates/treasury/sogecredit_detail.html:64 #: templates/treasury/sogecredit_detail.html:64
msgid "Return to credit list" msgid "Return to credit list"