mirror of https://github.com/jumpserver/jumpserver
fix(old-api): 调整旧的组织与用户关联接口
parent
9685a25dc6
commit
b5fcc10925
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
|
|
||||||
from .models import Organization
|
|
||||||
from .utils import get_org_from_request, set_current_org
|
from .utils import get_org_from_request, set_current_org
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,26 +74,29 @@ class OrgMemberSerializer(BulkModelSerializer):
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
class OrgMemberAdminSerializer(BulkModelSerializer):
|
class OrgMemberOldBaseSerializer(BulkModelSerializer):
|
||||||
|
organization = serializers.PrimaryKeyRelatedField(
|
||||||
|
label=_('Organization'), queryset=Organization.objects.all(), required=True, source='org'
|
||||||
|
)
|
||||||
|
|
||||||
|
def to_internal_value(self, data):
|
||||||
|
view = self.context['view']
|
||||||
|
org_id = view.kwargs.get('org_id')
|
||||||
|
if org_id:
|
||||||
|
data['organization'] = org_id
|
||||||
|
return super().to_internal_value(data)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = OrganizationMember
|
||||||
|
fields = ('id', 'organization', 'user', 'role')
|
||||||
|
|
||||||
|
|
||||||
|
class OrgMemberAdminSerializer(OrgMemberOldBaseSerializer):
|
||||||
role = serializers.HiddenField(default=ROLE.ADMIN)
|
role = serializers.HiddenField(default=ROLE.ADMIN)
|
||||||
organization = serializers.PrimaryKeyRelatedField(
|
|
||||||
label=_('Organization'), queryset=Organization.objects.all(), required=True, source='org'
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = OrganizationMember
|
|
||||||
fields = ('id', 'organization', 'user', 'role')
|
|
||||||
|
|
||||||
|
|
||||||
class OrgMemberUserSerializer(BulkModelSerializer):
|
class OrgMemberUserSerializer(OrgMemberOldBaseSerializer):
|
||||||
role = serializers.HiddenField(default=ROLE.USER)
|
role = serializers.HiddenField(default=ROLE.USER)
|
||||||
organization = serializers.PrimaryKeyRelatedField(
|
|
||||||
label=_('Organization'), queryset=Organization.objects.all(), required=True, source='org'
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = OrganizationMember
|
|
||||||
fields = ('id', 'organization', 'user', 'role')
|
|
||||||
|
|
||||||
|
|
||||||
class OrgRetrieveSerializer(OrgReadSerializer):
|
class OrgRetrieveSerializer(OrgReadSerializer):
|
||||||
|
|
Loading…
Reference in New Issue