Some other performance improvements

This commit is contained in:
Skia
2016-12-18 11:55:45 +01:00
parent bf6483039d
commit 4a7df31f5e
3 changed files with 10 additions and 9 deletions

View File

@ -385,7 +385,7 @@ class User(AbstractBaseUser):
"""
Determine if the object can be edited by the user
"""
if self.is_owner(obj):
if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self):
return True
if hasattr(obj, "edit_groups"):
for g in obj.edit_groups.all():
@ -393,7 +393,7 @@ class User(AbstractBaseUser):
return True
if isinstance(obj, User) and obj == self:
return True
if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self):
if self.is_owner(obj):
return True
return False
@ -401,13 +401,13 @@ class User(AbstractBaseUser):
"""
Determine if the object can be viewed by the user
"""
if self.can_edit(obj):
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
return True
if hasattr(obj, "view_groups"):
for g in obj.view_groups.all():
if self.is_in_group(g.name):
return True
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
if self.can_edit(obj):
return True
return False

View File

@ -18,6 +18,7 @@ import os
from core.models import SithFile, RealGroup, Notification
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, can_view, not_found
from counter.models import Counter
def send_file(request, file_id, file_class=SithFile, file_attr="file"):
"""
@ -28,7 +29,6 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
f = file_class.objects.filter(id=file_id).first()
if f is None or not f.file:
return not_found(request)
from counter.models import Counter
if not (can_view(f, request.user) or
('counter_token' in request.session.keys() and
request.session['counter_token'] and # check if not null for counters that have no token set