2018-11-02 06:38:44 +00:00
|
|
|
from rest_framework import serializers
|
2023-08-08 02:25:27 +00:00
|
|
|
from rest_framework.serializers import ModelSerializer
|
2020-07-20 02:42:22 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
from .models import Organization
|
2023-08-08 02:25:27 +00:00
|
|
|
from .utils import get_current_org
|
2018-07-25 03:21:12 +00:00
|
|
|
|
|
|
|
|
2021-01-17 04:08:21 +00:00
|
|
|
class ResourceStatisticsSerializer(serializers.Serializer):
|
|
|
|
users_amount = serializers.IntegerField(required=False)
|
|
|
|
groups_amount = serializers.IntegerField(required=False)
|
|
|
|
|
|
|
|
assets_amount = serializers.IntegerField(required=False)
|
|
|
|
nodes_amount = serializers.IntegerField(required=False)
|
|
|
|
domains_amount = serializers.IntegerField(required=False)
|
|
|
|
gateways_amount = serializers.IntegerField(required=False)
|
|
|
|
|
|
|
|
asset_perms_amount = serializers.IntegerField(required=False)
|
|
|
|
|
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
class OrgSerializer(ModelSerializer):
|
2021-01-17 11:10:11 +00:00
|
|
|
resource_statistics = ResourceStatisticsSerializer(source='resource_statistics_cache', read_only=True)
|
2021-01-17 04:08:21 +00:00
|
|
|
|
2018-07-25 03:21:12 +00:00
|
|
|
class Meta:
|
|
|
|
model = Organization
|
2020-06-11 10:05:18 +00:00
|
|
|
fields_mini = ['id', 'name']
|
|
|
|
fields_small = fields_mini + [
|
2021-04-29 11:10:45 +00:00
|
|
|
'resource_statistics',
|
2023-08-08 02:25:27 +00:00
|
|
|
'is_default', 'is_root', 'internal',
|
2022-02-17 12:13:31 +00:00
|
|
|
'date_created', 'created_by',
|
2021-04-29 11:10:45 +00:00
|
|
|
'comment', 'created_by',
|
2020-06-11 10:05:18 +00:00
|
|
|
]
|
2021-01-17 04:08:21 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
fields_m2m = []
|
2020-06-11 10:05:18 +00:00
|
|
|
fields = fields_small + fields_m2m
|
2019-03-19 11:09:09 +00:00
|
|
|
read_only_fields = ['created_by', 'date_created']
|
2020-07-20 02:42:22 +00:00
|
|
|
|
2020-11-19 06:49:50 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
class CurrentOrgSerializer(ModelSerializer):
|
2020-11-06 02:46:04 +00:00
|
|
|
class Meta:
|
2022-02-17 12:13:31 +00:00
|
|
|
model = Organization
|
|
|
|
fields = ['id', 'name', 'is_default', 'is_root', 'comment']
|
2020-11-06 02:46:04 +00:00
|
|
|
|
2020-05-21 08:09:42 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
class CurrentOrgDefault:
|
|
|
|
requires_context = False
|
2021-03-02 06:57:48 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
def __call__(self, *args):
|
|
|
|
return get_current_org()
|
2021-03-02 06:57:48 +00:00
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
def __repr__(self):
|
|
|
|
return '%s()' % self.__class__.__name__
|