Browse Source

perf: 组织属性添加 internal

pull/11220/head
ibuler 1 year ago committed by Bryan
parent
commit
c72ec5ea78
  1. 8
      apps/orgs/models.py
  2. 6
      apps/orgs/serializers.py

8
apps/orgs/models.py

@ -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)

6
apps/orgs/serializers.py

@ -1,8 +1,8 @@
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from .utils import get_current_org
from .models import Organization
from .utils import get_current_org
class ResourceStatisticsSerializer(serializers.Serializer):
@ -25,7 +25,7 @@ class OrgSerializer(ModelSerializer):
fields_mini = ['id', 'name']
fields_small = fields_mini + [
'resource_statistics',
'is_default', 'is_root',
'is_default', 'is_root', 'internal',
'date_created', 'created_by',
'comment', 'created_by',
]

Loading…
Cancel
Save