mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 04:43:10 +00:00
Merge branch 'fix-club-edit-acl' into 'dev'
Fix club edit and add some documentation on that error. See merge request re2o/re2o!580
This commit is contained in:
commit
3459994754
2 changed files with 13 additions and 7 deletions
10
re2o/acl.py
10
re2o/acl.py
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue