1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-20 17:41:55 +02:00

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,
NoteSpecial=NoteSpecial,
F=F,
Q=Q
Q=Q,
now=datetime.datetime.now(),
today=datetime.date.today(),
)
yield permission

File diff suppressed because it is too large Load Diff

View File

@ -120,7 +120,12 @@ class Permission(models.Model):
('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
# query -> [] | {} (the empty query representing all objects)
@ -142,18 +147,34 @@ class Permission(models.Model):
# Examples:
# Q(is_superuser=True) := {"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(
PermissionMask,
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:
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)
def __str__(self):
if self.field:
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)
return self.description
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.
"""
registration.information = self.__dict__
registration.save()
class WEISurveyAlgorithm:
@ -140,6 +139,10 @@ class WEISurvey:
Store the information of the survey into the database.
"""
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()
@classmethod

View File

@ -28,8 +28,12 @@ from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIM
class CurrentWEIDetailView(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs):
wei = WEIClub.objects.filter(membership_start__lte=date.today()).order_by('date_start').last()
return reverse_lazy('wei:wei_detail', args=(wei.pk,))
wei = WEIClub.objects.filter(membership_start__lte=date.today()).order_by('date_start')
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):