mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add CanCreateMixin, and add amount in journals
This commit is contained in:
@ -12,6 +12,11 @@ def forbidden(request):
|
||||
def not_found(request):
|
||||
return HttpResponseNotFound(render(request, "core/404.jinja"))
|
||||
|
||||
def can_create(mod, user):
|
||||
if mod.can_be_created_by(user):
|
||||
return True
|
||||
return False
|
||||
|
||||
def can_edit_prop(obj, user):
|
||||
if obj is None or user.is_owner(obj):
|
||||
return True
|
||||
@ -27,6 +32,19 @@ def can_view(obj, user):
|
||||
return True
|
||||
return can_edit(obj, user)
|
||||
|
||||
class CanCreateMixin(View):
|
||||
"""
|
||||
This view is made to protect any child view that would create an object, and thus, that can not be protected by any
|
||||
of the following mixin
|
||||
"""
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
res = super(CanCreateMixin, self).dispatch(request, *arg, **kwargs)
|
||||
if hasattr(self, 'model'):
|
||||
mod = self.model
|
||||
if can_create(mod, self.request.user):
|
||||
return res
|
||||
raise PermissionDenied
|
||||
|
||||
class CanEditPropMixin(View):
|
||||
"""
|
||||
This view is made to protect any child view that would be showing some properties of an object that are restricted
|
||||
|
Reference in New Issue
Block a user