调用DELETE /api/v1/dashboard/ 接口时,一直提示要登录 #29778
Unanswered
jinlinyouyou
asked this question in
Q&A / Help
Replies: 1 comment
-
确保用户已正确认证并具有删除操作的必要权限。以下是处理删除仪表板操作的代码示例,包括错误处理: export function handleDashboardDelete(
{ id, dashboard_title: dashboardTitle }: Dashboard,
refreshData: (config?: FetchDataConfig | null) => void,
addSuccessToast: (arg0: string) => void,
addDangerToast: (arg0: string) => void,
dashboardFilter?: string,
userId?: string | number,
) {
return SupersetClient.delete({
endpoint: `/api/v1/dashboard/${id}`,
}).then(
() => {
const filters = {
pageIndex: 0,
pageSize: PAGE_SIZE,
sortBy: [
{
id: 'changed_on_delta_humanized',
desc: true,
},
],
filters: [
{
id: 'owners',
operator: 'rel_m_m',
value: `${userId}`,
},
],
};
if (dashboardFilter === 'Mine') refreshData(filters);
else refreshData();
addSuccessToast(t('Deleted: %s', dashboardTitle));
},
createErrorHandler(errMsg =>
addDangerToast(
t('There was an issue deleting %s: %s', dashboardTitle, errMsg),
),
),
);
} 确保以下几点:
如果问题仍然存在,可能与会话过期或令牌使用不正确有关。请仔细检查认证流程和令牌有效性。 此外,后端代码对DELETE端点进行了多项检查,如果用户没有必要的权限或仪表板不存在,可能会返回403(禁止)或404(未找到)响应。以下是后端代码的相关部分: @expose("/<pk>", methods=("DELETE",))
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.delete",
log_to_statsd=False,
)
def delete(self, pk: int) -> Response:
"""Delete a dashboard.
---
delete:
summary: Delete a dashboard
parameters:
- in: path
schema:
type: integer
name: pk
responses:
200:
description: Dashboard deleted
content:
application/json:
schema:
type: object
properties:
message:
type: string
401:
$ref: '#/components/responses/401'
403:
$ref: '#/components/responses/403'
404:
$ref: '#/components/responses/404'
422:
$ref: '#/components/responses/422'
500:
$ref: '#/components/responses/500'
"""
try:
DeleteDashboardCommand([pk]).run()
return self.response(200, message="OK")
except DashboardNotFoundError:
return self.response_404()
except DashboardForbiddenError:
return self.response_403()
except DashboardDeleteFailedError as ex:
logger.error(
"Error deleting model %s: %s",
self.__class__.__name__,
str(ex),
exc_info=True,
)
return self.response_422(message=str(ex)) 确保用户具有必要的权限并且仪表板存在。如果用户未授权,后端将返回403响应;如果仪表板不存在,将返回404响应[1][2][3]. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
我在调用DELETE /api/v1/dashboard/ 接口时,接口一直返回登录页面的HTML TEXT,明明我已经传了HEADER Authorization
Beta Was this translation helpful? Give feedback.
All reactions