2016-02-11 22:58:32 +01:00
|
|
|
from ..utils.access_permissions import BaseAccessPermissions
|
|
|
|
|
2016-02-11 11:29:19 +01:00
|
|
|
|
2016-02-11 22:58:32 +01:00
|
|
|
class ItemAccessPermissions(BaseAccessPermissions):
|
|
|
|
"""
|
|
|
|
Access permissions container for Item and ItemViewSet.
|
|
|
|
"""
|
2016-02-11 11:29:19 +01:00
|
|
|
def can_retrieve(self, user):
|
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
Returns True if the user has read access model instances.
|
2016-02-11 11:29:19 +01:00
|
|
|
"""
|
2016-02-11 22:58:32 +01:00
|
|
|
return user.has_perm('agenda.can_see')
|
|
|
|
|
2016-03-02 00:46:19 +01:00
|
|
|
def get_serializer_class(self, user=None):
|
2016-02-11 22:58:32 +01:00
|
|
|
"""
|
|
|
|
Returns serializer class.
|
|
|
|
"""
|
|
|
|
from .serializers import ItemSerializer
|
|
|
|
|
|
|
|
return ItemSerializer
|
2016-03-02 00:46:19 +01:00
|
|
|
|
|
|
|
def get_restricted_data(self, full_data, user):
|
|
|
|
"""
|
|
|
|
Returns the restricted serialized data for the instance prepared
|
|
|
|
for the user.
|
|
|
|
"""
|
|
|
|
if (self.can_retrieve(user) and
|
|
|
|
(not full_data['is_hidden'] or
|
|
|
|
user.has_perm('agenda.can_see_hidden_items'))):
|
|
|
|
data = full_data
|
|
|
|
else:
|
|
|
|
data = None
|
|
|
|
return data
|