diff --git a/djangoldp/models.py b/djangoldp/models.py index 261518f5b41bed656a85fac0ab643c3b9336876f..4bd5b10e5756f15031a0457f0e4a5f5ef3baf835 100644 --- a/djangoldp/models.py +++ b/djangoldp/models.py @@ -257,10 +257,10 @@ class Model(models.Model): return getattr(model_class._meta, meta_name, meta) @staticmethod - def get_permissions(obj_or_model, user_or_group, filter): + def get_permissions(obj_or_model, context, filter): permissions = filter for permission_class in Model.get_permission_classes(obj_or_model, [LDPPermissions]): - permissions = permission_class().filter_user_perms(user_or_group, obj_or_model, permissions) + permissions = permission_class().filter_user_perms(context, obj_or_model, permissions) return [{'mode': {'@type': name.split('_')[0]}} for name in permissions] @classmethod diff --git a/djangoldp/permissions.py b/djangoldp/permissions.py index 682ed35442ccfce727718467736e8be55da79a20..c8f71aa846a2df552e5bfa5c1079c1cc98b73b41 100644 --- a/djangoldp/permissions.py +++ b/djangoldp/permissions.py @@ -97,9 +97,9 @@ class LDPPermissions(DjangoObjectPermissions): return self.perms_cache[perms_cache_key] # return list(perms) - def filter_user_perms(self, user, obj_or_model, permissions): + def filter_user_perms(self, context, obj_or_model, permissions): # Only used on Model.get_permissions to translate permissions to LDP - return [perm for perm in permissions if perm in self.user_permissions(user, obj_or_model)] + return [perm for perm in permissions if perm in self.user_permissions(context['request'].user, obj_or_model)] # perms_map defines the permissions required for different methods perms_map = { diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index 6fc13ee35bced56e0ad4bd1533a72e2d31e1d782..e45a55a7559534c0ed8131f74cbccd49f7ecb527 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -107,7 +107,7 @@ class LDListMixin: return self.to_representation_cache.get(cache_key) filtered_values = value - container_permissions = Model.get_permissions(child_model, self.context['request'].user, ['view', 'add']) + container_permissions = Model.get_permissions(child_model, self.context, ['view', 'add']) else: # this is a container. Parent model is the containing object, child the model contained @@ -127,10 +127,9 @@ class LDListMixin: filtered_values = list( filter(lambda v: Model.get_permission_classes(v, [LDPPermissions])[0]().has_object_permission( self.context['request'], self.context['view'], v), value)) - container_permissions = Model.get_permissions(child_model, self.context['request'].user, ['add']) + container_permissions = Model.get_permissions(child_model, self.context, ['add']) container_permissions.extend( - Model.get_permissions(parent_model, self.context['request'].user, - ['view'])) + Model.get_permissions(parent_model, self.context, ['view'])) self.to_representation_cache.set(self.id, {'@id': self.id, '@type': 'ldp:Container', @@ -345,7 +344,7 @@ class LDPSerializer(HyperlinkedModelSerializer): data['@type'] = rdf_type if rdf_context is not None: data['@context'] = rdf_context - data['permissions'] = Model.get_permissions(obj, self.context['request'].user, + data['permissions'] = Model.get_permissions(obj, self.context, ['view', 'change', 'control', 'delete']) return data @@ -382,7 +381,7 @@ class LDPSerializer(HyperlinkedModelSerializer): item in data], 'permissions': Model.get_permissions(self.parent.Meta.model, - self.context['request'].user, + self.context, ['view', 'add']) } else: