@ -1,6 +1,7 @@
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Group, Permission
|
||||
from django.forms import ValidationError
|
||||
|
||||
from .fields import *
|
||||
|
||||
@ -52,11 +53,19 @@ class TenancyObject(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
def validatate_organization_exists(self):
|
||||
|
||||
if not self:
|
||||
raise ValidationError('You must provide an organization')
|
||||
|
||||
|
||||
organization = models.ForeignKey(
|
||||
Organization,
|
||||
on_delete=models.CASCADE,
|
||||
blank = False,
|
||||
null = True,
|
||||
validators = [validatate_organization_exists],
|
||||
)
|
||||
|
||||
is_global = models.BooleanField(
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
from django.forms import ValidationError
|
||||
|
||||
from rest_framework.permissions import DjangoObjectPermissions
|
||||
|
||||
from access.mixin import OrganizationMixin
|
||||
@ -44,6 +46,9 @@ class OrganizationPermissionAPI(DjangoObjectPermissions, OrganizationMixin):
|
||||
|
||||
if 'organization' in request.data:
|
||||
|
||||
if not request.data['organization']:
|
||||
raise ValidationError('you must provide an organization')
|
||||
|
||||
object_organization = int(request.data['organization'])
|
||||
|
||||
elif method == 'patch':
|
||||
|
Reference in New Issue
Block a user