|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
from django.db import models |
|
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
|
from rest_framework.serializers import ValidationError |
|
|
|
|
|
|
|
|
|
from common.db.models import JMSBaseModel |
|
|
|
|
from common.tree import TreeNode |
|
|
|
@ -15,6 +16,7 @@ class OrgRoleMixin:
|
|
|
|
|
DEFAULT_NAME = _('DEFAULT') |
|
|
|
|
SYSTEM_ID = '00000000-0000-0000-0000-000000000004' |
|
|
|
|
SYSTEM_NAME = _('SYSTEM') |
|
|
|
|
VIRTUAL_IDS = [ROOT_ID, DEFAULT_ID, SYSTEM_ID] |
|
|
|
|
members: models.Manager |
|
|
|
|
id: str |
|
|
|
|
|
|
|
|
@ -171,6 +173,10 @@ class Organization(OrgRoleMixin, JMSBaseModel):
|
|
|
|
|
def is_default(self): |
|
|
|
|
return str(self.id) == self.DEFAULT_ID |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def internal(self): |
|
|
|
|
return str(self.id) in self.VIRTUAL_IDS |
|
|
|
|
|
|
|
|
|
def change_to(self): |
|
|
|
|
from .utils import set_current_org |
|
|
|
|
set_current_org(self) |
|
|
|
@ -223,5 +229,7 @@ class Organization(OrgRoleMixin, JMSBaseModel):
|
|
|
|
|
TicketFlow.objects.filter(org_id=self.id).delete() |
|
|
|
|
|
|
|
|
|
def delete(self, *args, **kwargs): |
|
|
|
|
if str(self.id) in self.VIRTUAL_IDS: |
|
|
|
|
raise ValidationError(_('Can not delete virtual org')) |
|
|
|
|
self.delete_related_models() |
|
|
|
|
return super().delete(*args, **kwargs) |
|
|
|
|