Skip to content
Snippets Groups Projects
Commit 6b034e86 authored by Thibaud Duquennoy's avatar Thibaud Duquennoy Committed by Jean-Baptiste
Browse files

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 6ff20225
No related branches found
No related tags found
1 merge request!25Url id field
...@@ -147,12 +147,14 @@ class MyModel(models.Model): ...@@ -147,12 +147,14 @@ class MyModel(models.Model):
## permissions ## permissions
This allows you to add permissions for AnonymousUser, logged in user, author ... in the url: This allows you to add permissions for AnonymousUser, logged in user, author ... in the url:
Currently, there are 3 choices : Currently, there are 3 choices :
* PublicPostPermissions * ObjectPermission
* PrivateProjectPermissions * AnonymousReadOnly
* NotificationsPermissions * InboxPermissions
Specific permissin classes can be developed to fit special needs. 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 * Anonymous users: can read all posts
* Logged in users: can read all posts + create new posts * Logged in users: can read all posts + create new posts
* Author: can read all posts + create new posts + update their own * Author: can read all posts + create new posts + update their own
...@@ -160,30 +162,15 @@ PublicPostPermissions gives these permissions: ...@@ -160,30 +162,15 @@ PublicPostPermissions gives these permissions:
``` ```
from django.conf.urls import url from django.conf.urls import url
from djangoldp.views import LDPViewSet from djangoldp.views import LDPViewSet
from djangoldp.permissions import PublicPostPermissions from djangoldp.permissions import AnonymousReadOnly
urlpatterns = [ urlpatterns = [
url(r'^projects/', ProjectViewSet.urls(permission_classes=(PublicPostPermissions,))), url(r'^projects/', ProjectViewSet.urls(permission_classes=(AnonymousReadOnly,))),
url(r'^customers/', LDPViewSet.urls(model=Customer)), url(r'^customers/', LDPViewSet.urls(model=Customer)),
] ]
``` ```
PrivateProjectPermissions provides the following InboxPermissions is used for, well, notifications:
* 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:
* Anonymous users: can create notifications but can't read * Anonymous users: can create notifications but can't read
* Logged in 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 * Inbox owners: can read + update all notifications
...@@ -194,7 +181,7 @@ from djangoldp.views import LDPViewSet ...@@ -194,7 +181,7 @@ from djangoldp.views import LDPViewSet
from djangoldp.permissions import NotificationsPermissions from djangoldp.permissions import NotificationsPermissions
urlpatterns = [ urlpatterns = [
url(r'^projects/', ProjectViewSet.urls(permission_classes=(NotificationsPermissions,))), url(r'^projects/', ProjectViewSet.urls(permission_classes=(InboxPermissions,))),
url(r'^customers/', LDPViewSet.urls(model=Customer)), url(r'^customers/', LDPViewSet.urls(model=Customer)),
] ]
``` ```
......
...@@ -183,6 +183,7 @@ class LDPSerializer(HyperlinkedModelSerializer): ...@@ -183,6 +183,7 @@ class LDPSerializer(HyperlinkedModelSerializer):
def to_representation(self, obj): def to_representation(self, obj):
data = super().to_representation(obj) data = super().to_representation(obj)
if hasattr(obj._meta, 'rdf_type'): if hasattr(obj._meta, 'rdf_type'):
data['@type'] = obj._meta.rdf_type data['@type'] = obj._meta.rdf_type
data['permissions'] = [{'mode': {'@type': name.split('_')[0]}} for name in data['permissions'] = [{'mode': {'@type': name.split('_')[0]}} for name in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment