Skip to content

Commit

Permalink
Add mastodon url to settings (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
mczachurski authored Oct 6, 2024
1 parent 0aa6452 commit 32f6986
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/VernissageServer/Controllers/SettingsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ struct SettingsController {
/// "systemDefaultUserId": "7257953010311411321",
/// "isOpenAIEnabled": false,
/// "openAIKey": "assg98svsa87y89as7tvd8",
/// "patreonUrl": ""
/// "patreonUrl": "",
/// "mastodonUrl": ""
/// }
/// ```
///
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -229,7 +231,8 @@ struct SettingsController {
/// "webThumbnail": "",
/// "webTitle": "Vernissage",
/// "systemDefaultUserId": "7257953010311411321",
/// "patreonUrl": ""
/// "patreonUrl": "",
/// "mastodonUrl": "",
/// }
/// ```
///
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct PublicSettingsDto {
var webPushVapidPublicKey: String?

var patreonUrl: String?
var mastodonUrl: String?
let totalCost: Int
let usersSupport: Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct SettingsDto {
var webLanguages: String
var webContactUserId: String
var patreonUrl: String
var mastodonUrl: String

var maxCharacters: Int
var maxMediaAttachments: Int
Expand Down Expand Up @@ -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) ?? ""
Expand Down
1 change: 1 addition & 0 deletions Sources/VernissageServer/Extensions/Application+Seed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions Sources/VernissageServer/Models/Setting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum SettingKey: String {
case imageSizeLimit
case systemDefaultUserId
case patreonUrl
case mastodonUrl

// Recaptcha.
case isRecaptchaEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 32f6986

Please sign in to comment.