Commit ee08ecad authored by Thibaud's avatar Thibaud

Fix bug #74: Container include a @type": "ldp:Container"

Changed the behavior of the serialization in LDListMixin tho that it includes @type: ldp:Container
parent 83b96248
Pipeline #1994 passed with stage
in 32 seconds
......@@ -144,12 +144,14 @@ class MyModel(models.Model):
## permissions
This allows you to add permissions for AnonymousUser, logged in user, author ... in the url:
Currently, there are 3 choices :
* PublicPostPermissions
* PrivateProjectPermissions
* NotificationsPermissions
* ObjectPermission
* AnonymousReadOnly
* InboxPermissions
Specific permissin classes can be developed to fit special needs.
PublicPostPermissions gives these permissions:
ObjectPermission give permissions assign in the administration
AnonymousReadOnly gives these permissions:
* Anonymous users: can read all posts
* Logged in users: can read all posts + create new posts
* Author: can read all posts + create new posts + update their own
......@@ -157,30 +159,15 @@ PublicPostPermissions gives these permissions:
```
from django.conf.urls import url
from djangoldp.views import LDPViewSet
from djangoldp.permissions import PublicPostPermissions
from djangoldp.permissions import AnonymousReadOnly
urlpatterns = [
url(r'^projects/', ProjectViewSet.urls(permission_classes=(PublicPostPermissions,))),
url(r'^projects/', ProjectViewSet.urls(permission_classes=(AnonymousReadOnly,))),
url(r'^customers/', LDPViewSet.urls(model=Customer)),
]
```
PrivateProjectPermissions provides the following
* Anonymous users: no permissions
* Logged in users: can read projects if they're in the team
* Users of group Partners: can see all projects + update all projects
```
from django.conf.urls import url
from djangoldp.views import LDPViewSet
from djangoldp.permissions import PrivateProjectPermissions
urlpatterns = [
url(r'^projects/', ProjectViewSet.urls(permission_classes=(PrivateProjectPermissions,))),
url(r'^customers/', LDPViewSet.urls(model=Customer)),
]
```
NotificationsPermissions is used for, well, notifications:
InboxPermissions is used for, well, notifications:
* Anonymous users: can create notifications but can't read
* Logged in users: can create notifications but can't read
* Inbox owners: can read + update all notifications
......@@ -191,7 +178,7 @@ from djangoldp.views import LDPViewSet
from djangoldp.permissions import NotificationsPermissions
urlpatterns = [
url(r'^projects/', ProjectViewSet.urls(permission_classes=(NotificationsPermissions,))),
url(r'^projects/', ProjectViewSet.urls(permission_classes=(InboxPermissions,))),
url(r'^customers/', LDPViewSet.urls(model=Customer)),
]
```
......
......@@ -15,7 +15,7 @@ class LDListMixin:
data = [data]
return [self.child_relation.to_internal_value(item['@id']) for item in data]
def to_representation(self, value):
return {'@id': self.id, 'ldp:contains': super().to_representation(value)}
return {'@id': self.id, '@type': 'ldp:Container', 'ldp:contains': super().to_representation(value)}
def get_attribute(self, instance):
parent_id_field = self.parent.fields[self.parent.url_field_name]
context = self.parent.context
......@@ -89,8 +89,10 @@ class LDPSerializer(HyperlinkedModelSerializer):
def to_representation(self, obj):
data = super().to_representation(obj)
if hasattr(obj._meta, 'rdf_type'):
data['@type'] = obj._meta.rdf_type
data['permissions'] = [{'mode': {'@type': name.split('_')[0]}} for name in get_perms(self.context['request'].user, obj)]
return data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment