diff --git a/apps/orgs/middleware.py b/apps/orgs/middleware.py index efbee2dde..2448fffc3 100644 --- a/apps/orgs/middleware.py +++ b/apps/orgs/middleware.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # -from .models import Organization from .utils import get_org_from_request, set_current_org diff --git a/apps/orgs/serializers.py b/apps/orgs/serializers.py index 7a57b4fac..c4402d433 100644 --- a/apps/orgs/serializers.py +++ b/apps/orgs/serializers.py @@ -74,26 +74,29 @@ class OrgMemberSerializer(BulkModelSerializer): ).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) - 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) - 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):