From 0bda29f143ebbaafa092de9efddfb2794bb90745 Mon Sep 17 00:00:00 2001 From: Jiawei Chen <907997375@qq.com> Date: Fri, 9 Jun 2023 21:52:30 +0800 Subject: [PATCH] feat: show 404 error for non-existent objects in edit pages --- web/src/AdapterEditPage.js | 5 +++++ web/src/ApplicationEditPage.js | 5 +++++ web/src/CertEditPage.js | 5 +++++ web/src/ChatEditPage.js | 5 +++++ web/src/MessageEditPage.js | 5 +++++ web/src/ModelEditPage.js | 5 +++++ web/src/OrganizationEditPage.js | 5 +++++ web/src/PaymentEditPage.js | 5 +++++ web/src/PermissionEditPage.js | 5 +++++ web/src/PlanEditPage.js | 5 +++++ web/src/PricingEditPage.js | 5 +++++ web/src/ProductEditPage.js | 5 +++++ web/src/ProviderEditPage.js | 5 +++++ web/src/RoleEditPage.js | 5 +++++ web/src/SubscriptionEditPage.js | 5 +++++ web/src/SyncerEditPage.js | 5 +++++ web/src/TokenEditPage.js | 5 +++++ web/src/UserEditPage.js | 5 +++++ web/src/WebhookEditPage.js | 5 +++++ 19 files changed, 95 insertions(+) diff --git a/web/src/AdapterEditPage.js b/web/src/AdapterEditPage.js index f07f32b6..d308914d 100644 --- a/web/src/AdapterEditPage.js +++ b/web/src/AdapterEditPage.js @@ -50,6 +50,11 @@ class AdapterEditPage extends React.Component { AdapterBackend.getAdapter("admin", this.state.adapterName) .then((res) => { if (res.status === "ok") { + if (res.data === null) { + this.props.history.push("/404"); + return; + } + this.setState({ adapter: res.data, }); diff --git a/web/src/ApplicationEditPage.js b/web/src/ApplicationEditPage.js index 5f2f70c6..59765462 100644 --- a/web/src/ApplicationEditPage.js +++ b/web/src/ApplicationEditPage.js @@ -119,6 +119,11 @@ class ApplicationEditPage extends React.Component { getApplication() { ApplicationBackend.getApplication("admin", this.state.applicationName) .then((application) => { + if (application === null) { + this.props.history.push("/404"); + return; + } + if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) { application.grantTypes = ["authorization_code"]; } diff --git a/web/src/CertEditPage.js b/web/src/CertEditPage.js index 403deb01..628d063c 100644 --- a/web/src/CertEditPage.js +++ b/web/src/CertEditPage.js @@ -45,6 +45,11 @@ class CertEditPage extends React.Component { getCert() { CertBackend.getCert(this.state.owner, this.state.certName) .then((cert) => { + if (cert === null) { + this.props.history.push("/404"); + return; + } + this.setState({ cert: cert, }); diff --git a/web/src/ChatEditPage.js b/web/src/ChatEditPage.js index 31c36889..87231280 100644 --- a/web/src/ChatEditPage.js +++ b/web/src/ChatEditPage.js @@ -41,6 +41,11 @@ class ChatEditPage extends React.Component { getChat() { ChatBackend.getChat("admin", this.state.chatName) .then((chat) => { + if (chat === null) { + this.props.history.push("/404"); + return; + } + this.setState({ chat: chat, }); diff --git a/web/src/MessageEditPage.js b/web/src/MessageEditPage.js index 2fff4442..a71fe31b 100644 --- a/web/src/MessageEditPage.js +++ b/web/src/MessageEditPage.js @@ -46,6 +46,11 @@ class MessageEditPage extends React.Component { getMessage() { MessageBackend.getMessage("admin", this.state.messageName) .then((message) => { + if (message === null) { + this.props.history.push("/404"); + return; + } + this.setState({ message: message, }); diff --git a/web/src/ModelEditPage.js b/web/src/ModelEditPage.js index 1b8cbb7f..b396a3d6 100644 --- a/web/src/ModelEditPage.js +++ b/web/src/ModelEditPage.js @@ -48,6 +48,11 @@ class ModelEditPage extends React.Component { getModel() { ModelBackend.getModel(this.state.organizationName, this.state.modelName) .then((model) => { + if (model === null) { + this.props.history.push("/404"); + return; + } + this.setState({ model: model, }); diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js index c0aa4d7d..ca5dfd78 100644 --- a/web/src/OrganizationEditPage.js +++ b/web/src/OrganizationEditPage.js @@ -50,6 +50,11 @@ class OrganizationEditPage extends React.Component { getOrganization() { OrganizationBackend.getOrganization("admin", this.state.organizationName) .then((organization) => { + if (organization === null) { + this.props.history.push("/404"); + return; + } + this.setState({ organization: organization, }); diff --git a/web/src/PaymentEditPage.js b/web/src/PaymentEditPage.js index 088a4262..9161ea71 100644 --- a/web/src/PaymentEditPage.js +++ b/web/src/PaymentEditPage.js @@ -42,6 +42,11 @@ class PaymentEditPage extends React.Component { getPayment() { PaymentBackend.getPayment("admin", this.state.paymentName) .then((payment) => { + if (payment === null) { + this.props.history.push("/404"); + return; + } + this.setState({ payment: payment, }); diff --git a/web/src/PermissionEditPage.js b/web/src/PermissionEditPage.js index 4630d033..bca97d13 100644 --- a/web/src/PermissionEditPage.js +++ b/web/src/PermissionEditPage.js @@ -50,6 +50,11 @@ class PermissionEditPage extends React.Component { getPermission() { PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName) .then((permission) => { + if (permission === null) { + this.props.history.push("/404"); + return; + } + this.setState({ permission: permission, }); diff --git a/web/src/PlanEditPage.js b/web/src/PlanEditPage.js index 38fe9d97..6fd86e9c 100644 --- a/web/src/PlanEditPage.js +++ b/web/src/PlanEditPage.js @@ -47,6 +47,11 @@ class PlanEditPage extends React.Component { getPlan() { PlanBackend.getPlan(this.state.organizationName, this.state.planName) .then((plan) => { + if (plan === null) { + this.props.history.push("/404"); + return; + } + this.setState({ plan: plan, }); diff --git a/web/src/PricingEditPage.js b/web/src/PricingEditPage.js index 948aa052..e07b726e 100644 --- a/web/src/PricingEditPage.js +++ b/web/src/PricingEditPage.js @@ -50,6 +50,11 @@ class PricingEditPage extends React.Component { getPricing() { PricingBackend.getPricing(this.state.organizationName, this.state.pricingName) .then((pricing) => { + if (pricing === null) { + this.props.history.push("/404"); + return; + } + this.setState({ pricing: pricing, }); diff --git a/web/src/ProductEditPage.js b/web/src/ProductEditPage.js index 21353a0a..c7b22eeb 100644 --- a/web/src/ProductEditPage.js +++ b/web/src/ProductEditPage.js @@ -45,6 +45,11 @@ class ProductEditPage extends React.Component { getProduct() { ProductBackend.getProduct(this.props.account.owner, this.state.productName) .then((product) => { + if (product === null) { + this.props.history.push("/404"); + return; + } + this.setState({ product: product, }); diff --git a/web/src/ProviderEditPage.js b/web/src/ProviderEditPage.js index d9bd23ac..9bb3aae6 100644 --- a/web/src/ProviderEditPage.js +++ b/web/src/ProviderEditPage.js @@ -50,6 +50,11 @@ class ProviderEditPage extends React.Component { getProvider() { ProviderBackend.getProvider(this.state.owner, this.state.providerName) .then((res) => { + if (res === null) { + this.props.history.push("/404"); + return; + } + if (res.status === "ok") { this.setState({ provider: res.data, diff --git a/web/src/RoleEditPage.js b/web/src/RoleEditPage.js index 2c8f9a30..8a2a130e 100644 --- a/web/src/RoleEditPage.js +++ b/web/src/RoleEditPage.js @@ -43,6 +43,11 @@ class RoleEditPage extends React.Component { getRole() { RoleBackend.getRole(this.state.organizationName, this.state.roleName) .then((role) => { + if (role === null) { + this.props.history.push("/404"); + return; + } + this.setState({ role: role, }); diff --git a/web/src/SubscriptionEditPage.js b/web/src/SubscriptionEditPage.js index 953e1102..38dfc7b7 100644 --- a/web/src/SubscriptionEditPage.js +++ b/web/src/SubscriptionEditPage.js @@ -47,6 +47,11 @@ class SubscriptionEditPage extends React.Component { getSubscription() { SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName) .then((subscription) => { + if (subscription === null) { + this.props.history.push("/404"); + return; + } + this.setState({ subscription: subscription, }); diff --git a/web/src/SyncerEditPage.js b/web/src/SyncerEditPage.js index 34fdeb66..88a8ac7a 100644 --- a/web/src/SyncerEditPage.js +++ b/web/src/SyncerEditPage.js @@ -48,6 +48,11 @@ class SyncerEditPage extends React.Component { getSyncer() { SyncerBackend.getSyncer("admin", this.state.syncerName) .then((syncer) => { + if (syncer === null) { + this.props.history.push("/404"); + return; + } + this.setState({ syncer: syncer, }); diff --git a/web/src/TokenEditPage.js b/web/src/TokenEditPage.js index 1fd05cf7..72c92101 100644 --- a/web/src/TokenEditPage.js +++ b/web/src/TokenEditPage.js @@ -36,6 +36,11 @@ class TokenEditPage extends React.Component { getToken() { TokenBackend.getToken("admin", this.state.tokenName) .then((token) => { + if (token === null) { + this.props.history.push("/404"); + return; + } + this.setState({ token: token, }); diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index 3d398605..3f5daa28 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -66,6 +66,11 @@ class UserEditPage extends React.Component { getUser() { UserBackend.getUser(this.state.organizationName, this.state.userName) .then((data) => { + if (data === null) { + this.props.history.push("/404"); + return; + } + if (data.status === null || data.status !== "error") { this.setState({ user: data, diff --git a/web/src/WebhookEditPage.js b/web/src/WebhookEditPage.js index 454e4c54..4fb5514b 100644 --- a/web/src/WebhookEditPage.js +++ b/web/src/WebhookEditPage.js @@ -123,6 +123,11 @@ class WebhookEditPage extends React.Component { getWebhook() { WebhookBackend.getWebhook("admin", this.state.webhookName) .then((webhook) => { + if (webhook === null) { + this.props.history.push("/404"); + return; + } + this.setState({ webhook: webhook, });