8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-05-16 23:56:12 +00:00

Fix club edit and add some documentation on that error.

This commit is contained in:
Hugo Levy-Falk 2020-12-28 20:50:00 +01:00 committed by Gabriel Detraz
parent 27343b8323
commit bc644fd32e
2 changed files with 13 additions and 7 deletions

View file

@ -64,11 +64,17 @@ def acl_base_decorator(method_name, *targets, on_instance=True):
"""Base decorator for acl. It checks if the `request.user` has the
permission by calling model.method_name. If the flag on_instance is True,
tries to get an instance of the model by calling
`model.get_instance(*args, **kwargs)` and runs `instance.mehod_name`
`model.get_instance(obj_id, *args, **kwargs)` and runs `instance.mehod_name`
rather than model.method_name.
It is not intended to be used as is. It is a base for others ACL
decorators.
decorators. Beware, if you redefine the `get_instance` method for your
model, give it a signature such as
`def get_instance(cls, object_id, *_args, **_kwargs)`, because you will
likely have an url with a named parameter "userid" if *e.g.* your model
is an user. Otherwise, if the parameter name in `get_instance` was also
`userid`, then `get_instance` would end up having two identical parameter
passed on, and this would result in a `TypeError` exception.
Args:
method_name: The name of the method which is to to be used for ACL.

View file

@ -2027,10 +2027,10 @@ class Adherent(User):
self.gpg_fingerprint = gpg_fingerprint
@classmethod
def get_instance(cls, adherentid, *_args, **_kwargs):
def get_instance(cls, object_id, *_args, **_kwargs):
"""Try to find an instance of `Adherent` with the given id.
:param adherentid: The id of the adherent we are looking for.
:param object_id: The id of the adherent we are looking for.
:return: An adherent.
"""
@ -2154,13 +2154,13 @@ class Club(User):
)
@classmethod
def get_instance(cls, clubid, *_args, **_kwargs):
def get_instance(cls, object_id, *_args, **_kwargs):
"""Try to find an instance of `Club` with the given id.
:param clubid: The id of the adherent we are looking for.
:param object_id: The id of the adherent we are looking for.
:return: A club.
"""
return cls.objects.get(pk=clubid)
return cls.objects.get(pk=object_id)
@receiver(post_save, sender=Adherent)