From a0579d916bde01534ef9d712b91faa15e9586ed2 Mon Sep 17 00:00:00 2001 From: Marcin Czachurski Date: Sun, 6 Oct 2024 09:53:14 +0200 Subject: [PATCH] Add mastodon url to settings --- .../Controllers/SettingsController.swift | 14 ++++++++++++-- .../DataTransferObjects/PublicSettingsDto.swift | 1 + .../DataTransferObjects/SettingsDto.swift | 2 ++ .../Extensions/Application+Seed.swift | 1 + Sources/VernissageServer/Models/Setting.swift | 1 + .../SettingsUpdateActionTests.swift | 4 ++++ 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Sources/VernissageServer/Controllers/SettingsController.swift b/Sources/VernissageServer/Controllers/SettingsController.swift index 6d9d2ed7..c9082b7b 100644 --- a/Sources/VernissageServer/Controllers/SettingsController.swift +++ b/Sources/VernissageServer/Controllers/SettingsController.swift @@ -103,7 +103,8 @@ struct SettingsController { /// "systemDefaultUserId": "7257953010311411321", /// "isOpenAIEnabled": false, /// "openAIKey": "assg98svsa87y89as7tvd8", - /// "patreonUrl": "" + /// "patreonUrl": "", + /// "mastodonUrl": "" /// } /// ``` /// @@ -164,6 +165,7 @@ struct SettingsController { isOpenAIEnabled: settings.isOpenAIEnabled, webPushVapidPublicKey: webPushVapidPublicKey, patreonUrl: settings.patreonUrl, + mastodonUrl: settings.mastodonUrl, totalCost: settings.totalCost, usersSupport: settings.usersSupport, showLocalTimelineForAnonymous: settings.showLocalTimelineForAnonymous, @@ -229,7 +231,8 @@ struct SettingsController { /// "webThumbnail": "", /// "webTitle": "Vernissage", /// "systemDefaultUserId": "7257953010311411321", - /// "patreonUrl": "" + /// "patreonUrl": "", + /// "mastodonUrl": "", /// } /// ``` /// @@ -376,6 +379,13 @@ struct SettingsController { transaction: database) } + if settingsDto.mastodonUrl != settings.getString(.mastodonUrl) { + try await self.update(.mastodonUrl, + with: .string(settingsDto.mastodonUrl), + on: request, + transaction: database) + } + if settingsDto.webContactUserId != settings.getString(.webContactUserId) { try await self.update(.webContactUserId, with: .string(settingsDto.webContactUserId), diff --git a/Sources/VernissageServer/DataTransferObjects/PublicSettingsDto.swift b/Sources/VernissageServer/DataTransferObjects/PublicSettingsDto.swift index 5798d467..0501012a 100644 --- a/Sources/VernissageServer/DataTransferObjects/PublicSettingsDto.swift +++ b/Sources/VernissageServer/DataTransferObjects/PublicSettingsDto.swift @@ -13,6 +13,7 @@ struct PublicSettingsDto { var webPushVapidPublicKey: String? var patreonUrl: String? + var mastodonUrl: String? let totalCost: Int let usersSupport: Int diff --git a/Sources/VernissageServer/DataTransferObjects/SettingsDto.swift b/Sources/VernissageServer/DataTransferObjects/SettingsDto.swift index cf9fb232..04b3db2a 100644 --- a/Sources/VernissageServer/DataTransferObjects/SettingsDto.swift +++ b/Sources/VernissageServer/DataTransferObjects/SettingsDto.swift @@ -30,6 +30,7 @@ struct SettingsDto { var webLanguages: String var webContactUserId: String var patreonUrl: String + var mastodonUrl: String var maxCharacters: Int var maxMediaAttachments: Int @@ -92,6 +93,7 @@ struct SettingsDto { self.webContactUserId = settings.getString(.webContactUserId) ?? "" self.systemDefaultUserId = settings.getString(.systemDefaultUserId) ?? "" self.patreonUrl = settings.getString(.patreonUrl) ?? "" + self.mastodonUrl = settings.getString(.mastodonUrl) ?? "" self.isOpenAIEnabled = settings.getBool(.isOpenAIEnabled) ?? false self.openAIKey = settings.getString(.openAIKey) ?? "" diff --git a/Sources/VernissageServer/Extensions/Application+Seed.swift b/Sources/VernissageServer/Extensions/Application+Seed.swift index a95d3a66..5b003026 100644 --- a/Sources/VernissageServer/Extensions/Application+Seed.swift +++ b/Sources/VernissageServer/Extensions/Application+Seed.swift @@ -48,6 +48,7 @@ extension Application { try await ensureSettingExists(on: database, existing: settings, key: .imageSizeLimit, value: .int(10_485_760)) try await ensureSettingExists(on: database, existing: settings, key: .systemDefaultUserId, value: .string("")) try await ensureSettingExists(on: database, existing: settings, key: .patreonUrl, value: .string("")) + try await ensureSettingExists(on: database, existing: settings, key: .mastodonUrl, value: .string("")) // Financial support. try await ensureSettingExists(on: database, existing: settings, key: .totalCost, value: .int(0)) diff --git a/Sources/VernissageServer/Models/Setting.swift b/Sources/VernissageServer/Models/Setting.swift index 84c667cd..c962302c 100644 --- a/Sources/VernissageServer/Models/Setting.swift +++ b/Sources/VernissageServer/Models/Setting.swift @@ -62,6 +62,7 @@ public enum SettingKey: String { case imageSizeLimit case systemDefaultUserId case patreonUrl + case mastodonUrl // Recaptcha. case isRecaptchaEnabled diff --git a/Tests/VernissageServerTests/AcceptanceTests/SettingsController/SettingsUpdateActionTests.swift b/Tests/VernissageServerTests/AcceptanceTests/SettingsController/SettingsUpdateActionTests.swift index ffa668e8..2e24f850 100644 --- a/Tests/VernissageServerTests/AcceptanceTests/SettingsController/SettingsUpdateActionTests.swift +++ b/Tests/VernissageServerTests/AcceptanceTests/SettingsController/SettingsUpdateActionTests.swift @@ -58,6 +58,8 @@ extension ControllersTests { settingsDto.webThumbnail = "webThumbnail" settingsDto.webLanguages = "webLanguages" settingsDto.webContactUserId = "webContactUserId" + settingsDto.patreonUrl = "patreonUrl" + settingsDto.mastodonUrl = "mastodonUrl" settingsDto.maxCharacters = 501 settingsDto.maxMediaAttachments = 5 @@ -99,6 +101,8 @@ extension ControllersTests { #expect(updatedSettingsDto.maxCharacters == 501, "Setting maxCharacters should be correct.") #expect(updatedSettingsDto.maxMediaAttachments == 5, "Setting maxMediaAttachments should be correct.") #expect(updatedSettingsDto.imageSizeLimit == 10_485_761, "Setting imageSizeLimit should be correct.") + #expect(updatedSettingsDto.patreonUrl == "patreonUrl", "Setting webEmail should be correct.") + #expect(updatedSettingsDto.mastodonUrl == "mastodonUrl", "Setting webEmail should be correct.") } @Test("Setting should not be updated if user is not super user")