Add CanCreateMixin, and add amount in journals

This commit is contained in:
Skia
2016-06-20 15:47:19 +02:00
parent 18db95cfd2
commit 3023d6d744
7 changed files with 104 additions and 7 deletions

View File

@ -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

View File

@ -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