diff --git a/internal/deployer/providers.go b/internal/deployer/providers.go index d59f40c7b..103240f4d 100644 --- a/internal/deployer/providers.go +++ b/internal/deployer/providers.go @@ -1523,7 +1523,7 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy deployer, err := pWebhook.NewSSLDeployerProvider(&pWebhook.SSLDeployerProviderConfig{ WebhookUrl: access.Url, - WebhookData: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "webhookData", access.DefaultDataForDeployment), + WebhookData: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "webhookData", access.DataStringForDeployment), Method: access.Method, Headers: mergedHeaders, AllowInsecureConnections: access.AllowInsecureConnections, diff --git a/internal/domain/access.go b/internal/domain/access.go index dd63ada1f..c40307850 100644 --- a/internal/domain/access.go +++ b/internal/domain/access.go @@ -139,8 +139,8 @@ type AccessConfigForDingTalkBot struct { } type AccessConfigForDiscordBot struct { - BotToken string `json:"botToken"` - DefaultChannelId string `json:"defaultChannelId,omitempty"` + BotToken string `json:"botToken"` + ChannelId string `json:"channelId,omitempty"` } type AccessConfigForDNSLA struct { @@ -167,14 +167,14 @@ type AccessConfigForEdgio struct { } type AccessConfigForEmail struct { - SmtpHost string `json:"smtpHost"` - SmtpPort int32 `json:"smtpPort"` - SmtpTls bool `json:"smtpTls"` - Username string `json:"username"` - Password string `json:"password"` - DefaultSenderAddress string `json:"defaultSenderAddress,omitempty"` - DefaultSenderName string `json:"defaultSenderName,omitempty"` - DefaultReceiverAddress string `json:"defaultReceiverAddress,omitempty"` + SmtpHost string `json:"smtpHost"` + SmtpPort int32 `json:"smtpPort"` + SmtpTls bool `json:"smtpTls"` + Username string `json:"username"` + Password string `json:"password"` + SenderAddress string `json:"senderAddress"` + SenderName string `json:"senderName"` + ReceiverAddress string `json:"receiverAddress,omitempty"` } type AccessConfigForFlexCDN struct { @@ -251,10 +251,10 @@ type AccessConfigForLeCDN struct { } type AccessConfigForMattermost struct { - ServerUrl string `json:"serverUrl"` - Username string `json:"username"` - Password string `json:"password"` - DefaultChannelId string `json:"defaultChannelId,omitempty"` + ServerUrl string `json:"serverUrl"` + Username string `json:"username"` + Password string `json:"password"` + ChannelId string `json:"channelId,omitempty"` } type AccessConfigForNamecheap struct { @@ -326,8 +326,8 @@ type AccessConfigForSafeLine struct { } type AccessConfigForSlackBot struct { - BotToken string `json:"botToken"` - DefaultChannelId string `json:"defaultChannelId,omitempty"` + BotToken string `json:"botToken"` + ChannelId string `json:"channelId,omitempty"` } type AccessConfigForSpaceship struct { @@ -360,8 +360,8 @@ type AccessConfigForSSLCom struct { } type AccessConfigForTelegramBot struct { - BotToken string `json:"botToken"` - DefaultChatId int64 `json:"defaultChatId,omitempty"` + BotToken string `json:"botToken"` + ChatId int64 `json:"chatId,omitempty"` } type AccessConfigForTencentCloud struct { @@ -402,12 +402,12 @@ type AccessConfigForWangsu struct { } type AccessConfigForWebhook struct { - Url string `json:"url"` - Method string `json:"method,omitempty"` - HeadersString string `json:"headers,omitempty"` - AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"` - DefaultDataForDeployment string `json:"defaultDataForDeployment,omitempty"` - DefaultDataForNotification string `json:"defaultDataForNotification,omitempty"` + Url string `json:"url"` + Method string `json:"method,omitempty"` + HeadersString string `json:"headers,omitempty"` + DataStringForDeployment string `json:"dataForDeployment,omitempty"` + DataStringForNotification string `json:"dataForNotification,omitempty"` + AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"` } type AccessConfigForWeComBot struct { diff --git a/internal/notify/providers.go b/internal/notify/providers.go index 872f5d26a..2b54e45e0 100644 --- a/internal/notify/providers.go +++ b/internal/notify/providers.go @@ -53,7 +53,7 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er return pDiscordBot.NewNotifierProvider(&pDiscordBot.NotifierProviderConfig{ BotToken: access.BotToken, - ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.DefaultChannelId), + ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.ChannelId), }) } @@ -70,9 +70,9 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er SmtpTls: access.SmtpTls, Username: access.Username, Password: access.Password, - SenderAddress: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "senderAddress", access.DefaultSenderAddress), - SenderName: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "senderName", access.DefaultSenderName), - ReceiverAddress: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "receiverAddress", access.DefaultReceiverAddress), + SenderAddress: access.SenderAddress, + SenderName: access.SenderName, + ReceiverAddress: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "receiverAddress", access.ReceiverAddress), }) } @@ -99,7 +99,7 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er ServerUrl: access.ServerUrl, Username: access.Username, Password: access.Password, - ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.DefaultChannelId), + ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.ChannelId), }) } @@ -112,7 +112,7 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er return pSlackBot.NewNotifierProvider(&pSlackBot.NotifierProviderConfig{ BotToken: access.BotToken, - ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.DefaultChannelId), + ChannelId: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "channelId", access.ChannelId), }) } @@ -125,7 +125,7 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er return pTelegramBot.NewNotifierProvider(&pTelegramBot.NotifierProviderConfig{ BotToken: access.BotToken, - ChatId: xmaps.GetOrDefaultInt64(options.ProviderServiceConfig, "chatId", access.DefaultChatId), + ChatId: xmaps.GetOrDefaultInt64(options.ProviderServiceConfig, "chatId", access.ChatId), }) } @@ -158,7 +158,7 @@ func createNotifierProvider(options *notifierProviderOptions) (core.Notifier, er return pWebhook.NewNotifierProvider(&pWebhook.NotifierProviderConfig{ WebhookUrl: access.Url, - WebhookData: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "webhookData", access.DefaultDataForNotification), + WebhookData: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "webhookData", access.DataStringForNotification), Method: access.Method, Headers: mergedHeaders, AllowInsecureConnections: access.AllowInsecureConnections, diff --git a/migrations/1753272000_v0.4.0_migrate.go b/migrations/1753272000_v0.4.0_migrate.go index 98219ce3d..f6b8fe4a1 100644 --- a/migrations/1753272000_v0.4.0_migrate.go +++ b/migrations/1753272000_v0.4.0_migrate.go @@ -83,6 +83,89 @@ func init() { } } + // update collection `access` + { + collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e") + if err != nil { + return err + } + + records, err := app.FindAllRecords(collection) + if err != nil { + return err + } + + for _, record := range records { + changed := false + + provider := record.GetString("provider") + config := make(map[string]any) + if err := record.UnmarshalJSONField("config", &config); err != nil { + return err + } + + switch provider { + case "discordbot", "mattermost", "slackbot": + if _, ok := config["defaultChannelId"]; ok { + config["channelId"] = config["defaultChannelId"] + delete(config, "defaultChannelId") + record.Set("config", config) + changed = true + } + + case "email": + if _, ok := config["defaultSenderAddress"]; ok { + config["senderAddress"] = config["defaultSenderAddress"] + delete(config, "defaultSenderAddress") + record.Set("config", config) + changed = true + } + if _, ok := config["defaultSenderName"]; ok { + config["senderName"] = config["defaultSenderName"] + delete(config, "defaultSenderName") + record.Set("config", config) + changed = true + } + if _, ok := config["defaultReceiverAddress"]; ok { + config["receiverAddress"] = config["defaultReceiverAddress"] + delete(config, "defaultReceiverAddress") + record.Set("config", config) + changed = true + } + + case "telegrambot": + if _, ok := config["defaultChatId"]; ok { + config["chatId"] = config["defaultChatId"] + delete(config, "defaultChatId") + record.Set("config", config) + changed = true + } + + case "webhook": + if _, ok := config["defaultDataForDeployment"]; ok { + config["dataForDeployment"] = config["defaultDataForDeployment"] + delete(config, "defaultDataForDeployment") + record.Set("config", config) + changed = true + } + if _, ok := config["defaultDataForNotification"]; ok { + config["dataForNotification"] = config["defaultDataForNotification"] + delete(config, "defaultDataForNotification") + record.Set("config", config) + changed = true + } + } + + if changed { + if err := app.Save(record); err != nil { + return err + } + + tracer.Printf("record #%s in collection '%s' updated", record.Id, collection.Name) + } + } + } + tracer.Printf("done") return nil }, func(app core.App) error { diff --git a/ui/src/components/access/AccessFormDiscordBotConfig.tsx b/ui/src/components/access/AccessFormDiscordBotConfig.tsx index c6bc85e52..c01b76ec6 100644 --- a/ui/src/components/access/AccessFormDiscordBotConfig.tsx +++ b/ui/src/components/access/AccessFormDiscordBotConfig.tsx @@ -29,7 +29,7 @@ const AccessFormDiscordBotConfig = ({ form: formInst, formName, disabled, initia .string(t("access.form.discordbot_token.placeholder")) .min(1, t("access.form.discordbot_token.placeholder")) .max(256, t("common.errmsg.string_max", { max: 256 })), - defaultChannelId: z.string().nullish(), + channelId: z.string().nullish(), }); const formRule = createSchemaFieldRule(formSchema); @@ -56,12 +56,12 @@ const AccessFormDiscordBotConfig = ({ form: formInst, formName, disabled, initia } + tooltip={} > - + ); diff --git a/ui/src/components/access/AccessFormEmailConfig.tsx b/ui/src/components/access/AccessFormEmailConfig.tsx index e5848494e..6b5df5514 100644 --- a/ui/src/components/access/AccessFormEmailConfig.tsx +++ b/ui/src/components/access/AccessFormEmailConfig.tsx @@ -23,6 +23,9 @@ const initFormModel = (): AccessFormEmailConfigFieldValues => { smtpTls: true, username: "", password: "", + senderAddress: "", + senderName: "", + receiverAddress: "", }; }; @@ -47,15 +50,9 @@ const AccessFormEmailConfig = ({ form: formInst, formName, disabled, initialValu .string() .min(1, t("access.form.email_password.placeholder")) .max(256, t("common.errmsg.string_max", { max: 256 })), - defaultSenderAddress: z - .string() - .nullish() - .refine((v) => { - if (!v) return true; - return validEmailAddress(v); - }, t("common.errmsg.email_invalid")), - defaultSenderName: z.string().nullish(), - defaultReceiverAddress: z + senderAddress: z.email(t("common.errmsg.email_invalid")), + senderName: z.string().nullish(), + receiverAddress: z .string() .nullish() .refine((v) => { @@ -112,16 +109,16 @@ const AccessFormEmailConfig = ({ form: formInst, formName, disabled, initialValu - - + + - - + + - - + + ); diff --git a/ui/src/components/access/AccessFormMattermostConfig.tsx b/ui/src/components/access/AccessFormMattermostConfig.tsx index 178987f51..c42a328ec 100644 --- a/ui/src/components/access/AccessFormMattermostConfig.tsx +++ b/ui/src/components/access/AccessFormMattermostConfig.tsx @@ -30,7 +30,7 @@ const AccessFormMattermostConfig = ({ form: formInst, formName, disabled, initia serverUrl: z.url(t("common.errmsg.url_invalid")), username: z.string().nonempty(t("access.form.mattermost_username.placeholder")), password: z.string().nonempty(t("access.form.mattermost_password.placeholder")), - defaultChannelId: z.string().nullish(), + channelId: z.string().nullish(), }); const formRule = createSchemaFieldRule(formSchema); @@ -65,12 +65,12 @@ const AccessFormMattermostConfig = ({ form: formInst, formName, disabled, initia } + tooltip={} > - + ); diff --git a/ui/src/components/access/AccessFormSlackBotConfig.tsx b/ui/src/components/access/AccessFormSlackBotConfig.tsx index 6c7b6e9c5..a12fea3bb 100644 --- a/ui/src/components/access/AccessFormSlackBotConfig.tsx +++ b/ui/src/components/access/AccessFormSlackBotConfig.tsx @@ -29,7 +29,7 @@ const AccessFormSlackBotConfig = ({ form: formInst, formName, disabled, initialV .string(t("access.form.slackbot_token.placeholder")) .min(1, t("access.form.slackbot_token.placeholder")) .max(256, t("common.errmsg.string_max", { max: 256 })), - defaultChannelId: z.string().nullish(), + channelId: z.string().nullish(), }); const formRule = createSchemaFieldRule(formSchema); @@ -56,12 +56,12 @@ const AccessFormSlackBotConfig = ({ form: formInst, formName, disabled, initialV } + tooltip={} > - + ); diff --git a/ui/src/components/access/AccessFormTelegramBotConfig.tsx b/ui/src/components/access/AccessFormTelegramBotConfig.tsx index 993e3da57..423aae797 100644 --- a/ui/src/components/access/AccessFormTelegramBotConfig.tsx +++ b/ui/src/components/access/AccessFormTelegramBotConfig.tsx @@ -29,16 +29,12 @@ const AccessFormTelegramBotConfig = ({ form: formInst, formName, disabled, initi .string(t("access.form.telegrambot_token.placeholder")) .min(1, t("access.form.telegrambot_token.placeholder")) .max(256, t("common.errmsg.string_max", { max: 256 })), - defaultChatId: z + chatId: z .preprocess( (v) => (v == null || v === "" ? undefined : Number(v)), - z - .number() - .nullish() - .refine((v) => { - if (v == null || v + "" === "") return true; - return !Number.isNaN(+v!) && +v! !== 0; - }, t("access.form.telegrambot_default_chat_id.placeholder")) + z.number().refine((v) => { + return !Number.isNaN(+v!) && +v! !== 0; + }, t("access.form.telegrambot_chat_id.placeholder")) ) .nullish(), }); @@ -67,12 +63,12 @@ const AccessFormTelegramBotConfig = ({ form: formInst, formName, disabled, initi } + tooltip={} > - + ); diff --git a/ui/src/components/access/AccessFormWebhookConfig.tsx b/ui/src/components/access/AccessFormWebhookConfig.tsx index a83b6692c..7e18c2727 100644 --- a/ui/src/components/access/AccessFormWebhookConfig.tsx +++ b/ui/src/components/access/AccessFormWebhookConfig.tsx @@ -25,7 +25,7 @@ const initFormModel = (): AccessFormWebhookConfigFieldValues => { method: "POST", headers: "Content-Type: application/json", allowInsecureConnections: false, - defaultDataForDeployment: JSON.stringify( + dataForDeployment: JSON.stringify( { name: "${DOMAINS}", cert: "${CERTIFICATE}", @@ -34,7 +34,7 @@ const initFormModel = (): AccessFormWebhookConfigFieldValues => { null, 2 ), - defaultDataForNotification: JSON.stringify( + dataForNotification: JSON.stringify( { subject: "${SUBJECT}", message: "${MESSAGE}", @@ -65,7 +65,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa } return true; }, t("access.form.webhook_headers.errmsg.invalid")), - defaultDataForDeployment: z + dataForDeployment: z .string() .nullish() .refine((v) => { @@ -78,8 +78,8 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa } catch { return false; } - }, t("access.form.webhook_default_data.errmsg.json_invalid")), - defaultDataForNotification: z + }, t("access.form.webhook_data.errmsg.json_invalid")), + dataForNotification: z .string() .nullish() .refine((v) => { @@ -92,7 +92,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa } catch { return false; } - }, t("access.form.webhook_default_data.errmsg.json_invalid")), + }, t("access.form.webhook_data.errmsg.json_invalid")), allowInsecureConnections: z.boolean().nullish(), }); const formRule = createSchemaFieldRule(formSchema); @@ -105,27 +105,27 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa }; const handleWebhookDataForDeploymentBlur = () => { - const value = formInst.getFieldValue("defaultDataForDeployment"); + const value = formInst.getFieldValue("dataForDeployment"); try { const json = JSON.stringify(JSON.parse(value), null, 2); - formInst.setFieldValue("defaultDataForDeployment", json); + formInst.setFieldValue("dataForDeployment", json); } catch { return; } }; const handleWebhookDataForNotificationBlur = () => { - const value = formInst.getFieldValue("defaultDataForNotification"); + const value = formInst.getFieldValue("dataForNotification"); try { const json = JSON.stringify(JSON.parse(value), null, 2); - formInst.setFieldValue("defaultDataForNotification", json); + formInst.setFieldValue("dataForNotification", json); } catch { return; } }; const handlePresetDataForDeploymentClick = () => { - formInst.setFieldValue("defaultDataForDeployment", initFormModel().defaultDataForDeployment); + formInst.setFieldValue("dataForDeployment", initFormModel().dataForDeployment); }; const handlePresetDataForNotificationClick = (key: string) => { @@ -135,7 +135,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json\r\nAuthorization: Bearer "); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { title: "${SUBJECT}", @@ -153,7 +153,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json\r\nAuthorization: Bearer "); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { title: "${SUBJECT}", @@ -171,7 +171,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { topic: "", @@ -190,7 +190,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { token: "", @@ -209,7 +209,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { token: "", @@ -227,7 +227,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { title: "${SUBJECT}", @@ -244,7 +244,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); formInst.setFieldValue( - "defaultDataForNotification", + "dataForNotification", JSON.stringify( { text: "${SUBJECT}", @@ -259,7 +259,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa default: formInst.setFieldValue("method", "POST"); formInst.setFieldValue("headers", "Content-Type: application/json"); - formInst.setFieldValue("defaultDataForNotification", initFormModel().defaultDataForNotification); + formInst.setFieldValue("dataForNotification", initFormModel().dataForNotification); break; } }; @@ -308,7 +308,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa - + - } /> + } /> @@ -339,7 +339,7 @@ const AccessFormWebhookConfig = ({ form: formInst, formName, disabled, initialVa