Commit cd3c8a4c authored by Calum Mackervoy's avatar Calum Mackervoy

LDPMetaMixin

parent cd9e27cd
Pipeline #7281 failed with stage
in 1 minute and 22 seconds
......@@ -13,6 +13,11 @@ from djangoldp.fields import LDPUrlField
from djangoldp.permissions import LDPPermissions
class LDPPMetaMixin:
'''A meta class which all children of Model should inherit'''
default_permissions = ('add', 'change', 'delete', 'view', 'control')
class Model(models.Model):
urlid = LDPUrlField(blank=True, null=True, unique=True)
......@@ -89,8 +94,7 @@ class Model(models.Model):
return path
class Meta:
default_permissions = ('add', 'change', 'delete', 'view', 'control')
class Meta(LDPPMetaMixin):
abstract = True
depth = 0
......@@ -165,15 +169,11 @@ class Model(models.Model):
class LDPSource(Model):
federation = models.CharField(max_length=255)
class Meta:
class Meta(LDPPMetaMixin):
rdf_type = 'ldp:Container'
ordering = ('federation',)
container_path = 'sources'
lookup_field = 'federation'
permissions = (
('view_source', 'acl:Read'),
('control_source', 'acl:Control'),
)
def __str__(self):
return "{}: {}".format(self.federation, self.urlid)
......
......@@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
from django.db import models
from django.utils.datetime_safe import date
from djangoldp.models import Model
from djangoldp.models import Model, LDPPMetaMixin
class Skill(Model):
......@@ -15,7 +15,7 @@ class Skill(Model):
def recent_jobs(self):
return self.joboffer_set.filter(date__gte=date.today())
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
owner_perms = ['inherit', 'change', 'delete', 'control']
......@@ -35,7 +35,7 @@ class JobOffer(Model):
def some_skill(self):
return self.skills.all().first()
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'change', 'add']
owner_perms = ['inherit', 'delete', 'control']
......@@ -50,7 +50,7 @@ class Conversation(models.Model):
author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
peer_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="peers_conv")
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
owner_perms = ['inherit', 'change', 'delete', 'control']
......@@ -60,7 +60,7 @@ class Resource(Model):
joboffers = models.ManyToManyField(JobOffer, blank=True, related_name='resources')
description = models.CharField(max_length=255)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control']
authenticated_perms = ['inherit']
owner_perms = ['inherit']
......@@ -73,7 +73,7 @@ class UserProfile(Model):
description = models.CharField(max_length=255, blank=True, null=True)
user = models.OneToOneField(settings.AUTH_USER_MODEL)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit']
owner_perms = ['inherit', 'change', 'control']
......@@ -85,7 +85,7 @@ class Message(models.Model):
conversation = models.ForeignKey(Conversation, on_delete=models.DO_NOTHING)
author_user = models.ForeignKey(settings.AUTH_USER_MODEL)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
owner_perms = ['inherit', 'change', 'delete', 'control']
......@@ -95,7 +95,7 @@ class Dummy(models.Model):
some = models.CharField(max_length=255, blank=True, null=True)
slug = models.SlugField(blank=True, null=True, unique=True)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
owner_perms = ['inherit', 'change', 'delete', 'control']
......@@ -104,7 +104,7 @@ class Dummy(models.Model):
class LDPDummy(Model):
some = models.CharField(max_length=255, blank=True, null=True)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
owner_perms = ['inherit', 'change', 'delete', 'control']
......@@ -114,7 +114,7 @@ class LDPDummy(Model):
class PermissionlessDummy(Model):
some = models.CharField(max_length=255, blank=True, null=True)
class Meta:
class Meta(LDPPMetaMixin):
anonymous_perms = []
authenticated_perms = []
owner_perms = []
......@@ -127,7 +127,7 @@ class Invoice(Model):
title = models.CharField(max_length=255, blank=True, null=True)
date = models.DateField(blank=True, null=True)
class Meta:
class Meta(LDPPMetaMixin):
depth = 2
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
......@@ -139,7 +139,7 @@ class Batch(Model):
invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, related_name='batches')
title = models.CharField(max_length=255, blank=True, null=True)
class Meta:
class Meta(LDPPMetaMixin):
serializer_fields = ['@id', 'title', 'invoice', 'tasks']
anonymous_perms = ['view', 'add']
authenticated_perms = ['inherit', 'add']
......@@ -152,7 +152,7 @@ class Task(models.Model):
batch = models.ForeignKey(Batch, on_delete=models.CASCADE, related_name='tasks')
title = models.CharField(max_length=255)
class Meta:
class Meta(LDPPMetaMixin):
serializer_fields = ['@id', 'title', 'batch']
anonymous_perms = ['view']
authenticated_perms = ['inherit', 'add']
......@@ -164,7 +164,7 @@ class Post(Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True)
peer_user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="peers_post")
class Meta:
class Meta(LDPPMetaMixin):
auto_author = 'author'
anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control']
authenticated_perms = ['inherit']
......@@ -175,7 +175,7 @@ class Circle(Model):
description = models.CharField(max_length=255)
team = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
class Meta:
class Meta(LDPPMetaMixin):
nested_fields = ["team"]
anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control']
authenticated_perms = ["inherit"]
......
......@@ -15,7 +15,7 @@ class TestGuardianPermissions(APITestCase):
# optional setup for testing PermissionlessDummy model with parameterised perms
def setUpGuardianDummyWithPerms(self, perms=[]):
self.dummy = PermissionlessDummy.objects.create(some='test')
model_name = PermissionlessDummy.Meta.model_name
model_name = PermissionlessDummy._meta.model_name
for perm in perms:
assign_perm(perm + '_' + model_name, self.user, self.dummy)
......
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