-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(open v2 api): fetch user department 404 when user is virtual user (…
- Loading branch information
Showing
4 changed files
with
24 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,18 +360,25 @@ def get(self, request, *args, **kwargs): | |
params = slz.validated_data | ||
|
||
# 注:兼容 v2 的 OpenAPI 只提供默认租户的数据(包括默认租户本身数据源的数据 & 其他租户协同过来的数据) | ||
filters = { | ||
"tenant_id": self.default_tenant.id, | ||
"data_source__type": DataSourceTypeEnum.REAL, | ||
} | ||
lookup_filter = {} | ||
if params["lookup_field"] == "username": | ||
# username 其实就是新的租户用户 ID,形式如 admin / [email protected] / uuid4 | ||
filters["id"] = kwargs["lookup_value"] | ||
lookup_filter["id"] = kwargs["lookup_value"] | ||
else: | ||
# 用户 ID 即为数据源用户 ID | ||
filters["data_source_user__id"] = kwargs["lookup_value"] | ||
|
||
tenant_user = TenantUser.objects.select_related("data_source_user").filter(**filters).first() | ||
lookup_filter["data_source_user__id"] = kwargs["lookup_value"] | ||
|
||
tenant_user = ( | ||
TenantUser.objects.select_related("data_source_user") | ||
.filter( | ||
Q(**lookup_filter), | ||
Q(tenant_id=self.default_tenant.id), | ||
# Note: 兼容 v2 仅仅允许默认租户下的虚拟账号输出 | ||
Q(data_source__type=DataSourceTypeEnum.REAL) | ||
| Q(data_source__owner_tenant_id=self.default_tenant.id, data_source__type=DataSourceTypeEnum.VIRTUAL), | ||
) | ||
.first() | ||
) | ||
if not tenant_user: | ||
raise Http404(f"user {params['lookup_field']}:{kwargs['lookup_value']} not found") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,15 +481,12 @@ def get(self, request, *args, **kwargs): | |
slz.is_valid(raise_exception=True) | ||
params = slz.validated_data | ||
|
||
# 路径参数 | ||
lookup_value = kwargs["lookup_value"] | ||
|
||
lookup_filter = {} | ||
if params["lookup_field"] == "username": | ||
# username 其实就是新的租户用户 ID,形式如 admin / [email protected] / uuid4 | ||
lookup_filter["id"] = lookup_value | ||
lookup_filter["id"] = kwargs["lookup_value"] | ||
else: | ||
lookup_filter["data_source_user__id"] = lookup_value | ||
lookup_filter["data_source_user__id"] = kwargs["lookup_value"] | ||
|
||
# 注:兼容 v2 的 OpenAPI 只提供默认租户的数据(包括默认租户本身数据源的数据 & 其他租户协同过来的数据) | ||
tenant_user = ( | ||
|
@@ -703,9 +700,11 @@ def put(self, request, *args, **kwargs): | |
slz = ProfileLanguageUpdateInputSLZ(data=request.data) | ||
slz.is_valid(raise_exception=True) | ||
|
||
# Note: 由于虚拟账号并不支持登录,所以不存在设置语言的场景 | ||
tenant_user = TenantUser.objects.filter( | ||
id=kwargs["username"], tenant=self.default_tenant, data_source__type=DataSourceTypeEnum.REAL | ||
Q(id=kwargs["username"]), | ||
Q(tenant=self.default_tenant), | ||
Q(data_source__type=DataSourceTypeEnum.REAL) | ||
| Q(data_source__owner_tenant_id=self.default_tenant.id, data_source__type=DataSourceTypeEnum.VIRTUAL), | ||
).first() | ||
if not tenant_user: | ||
raise Http404(f"user username:{kwargs['username']} not found") | ||
|