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:
@ -130,7 +130,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
return True
|
||||
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
|
||||
if 'subscription' in settings.INSTALLED_APPS:
|
||||
from subscription import Subscriber
|
||||
from subscription.models import Subscriber
|
||||
s = Subscriber.objects.filter(pk=self.pk).first()
|
||||
if s is not None and s.is_subscribed():
|
||||
return True
|
||||
@ -256,6 +256,14 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
def __init__(self, request):
|
||||
super(AnonymousUser, self).__init__()
|
||||
|
||||
def is_in_group(self, group_name):
|
||||
"""
|
||||
The anonymous user is only the public group
|
||||
"""
|
||||
if group_name == settings.SITH_GROUPS['public']['name']:
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_owner(self, obj):
|
||||
return False
|
||||
|
||||
|
@ -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