From 11257ae069b8dd2fcb94e77adfbe51c73be528b6 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 14 Dec 2024 16:51:58 +0100 Subject: [PATCH] chore: clean up backend code, fix most inspections --- Foxnouns.Backend/Config.cs | 6 ++++-- .../Authentication/TumblrAuthController.cs | 14 ++++++++++++++ Foxnouns.Backend/Controllers/FlagsController.cs | 2 +- Foxnouns.Backend/Database/Models/User.cs | 4 +++- Foxnouns.Backend/Dto/Flag.cs | 3 +-- Foxnouns.Backend/Dto/Member.cs | 1 + Foxnouns.Backend/Dto/User.cs | 1 + .../Extensions/WebApplicationExtensions.cs | 2 +- Foxnouns.Backend/Jobs/Payloads.cs | 8 +------- .../Mailables/PasswordChangedMailable.cs | 14 ++++++++++++++ .../Mailables/ResetPasswordMailable.cs | 14 ++++++++++++++ .../Middleware/AuthorizationMiddleware.cs | 1 - .../Services/Auth/FediverseAuthService.Misskey.cs | 5 +---- .../Services/Auth/FediverseAuthService.cs | 3 +-- Foxnouns.Backend/Services/EmailRateLimiter.cs | 14 ++++++++++++++ Foxnouns.Backend/Services/MemberRendererService.cs | 1 - .../Services/MetricsCollectionService.cs | 2 +- Foxnouns.Backend/Services/ObjectStorageService.cs | 1 - Foxnouns.Backend/Services/UserRendererService.cs | 2 -- .../Utils/OpenApi/PropertyKeySchemaTransformer.cs | 14 ++++++++++++++ .../Utils/ValidationUtils.Preferences.cs | 1 - 21 files changed, 86 insertions(+), 27 deletions(-) diff --git a/Foxnouns.Backend/Config.cs b/Foxnouns.Backend/Config.cs index 3874204..e0a579b 100644 --- a/Foxnouns.Backend/Config.cs +++ b/Foxnouns.Backend/Config.cs @@ -12,6 +12,8 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . + +// ReSharper disable UnusedAutoPropertyAccessor.Global using Serilog.Events; namespace Foxnouns.Backend; @@ -20,8 +22,8 @@ public class Config { public string Host { get; init; } = "localhost"; public int Port { get; init; } = 3000; - public string BaseUrl { get; set; } = null!; - public string MediaBaseUrl { get; set; } = null!; + public string BaseUrl { get; init; } = null!; + public string MediaBaseUrl { get; init; } = null!; public string Address => $"http://{Host}:{Port}"; public string MetricsAddress => $"http://{Host}:{Logging.MetricsPort}"; diff --git a/Foxnouns.Backend/Controllers/Authentication/TumblrAuthController.cs b/Foxnouns.Backend/Controllers/Authentication/TumblrAuthController.cs index 919ca3f..9860957 100644 --- a/Foxnouns.Backend/Controllers/Authentication/TumblrAuthController.cs +++ b/Foxnouns.Backend/Controllers/Authentication/TumblrAuthController.cs @@ -1,3 +1,17 @@ +// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . using System.Net; using System.Web; using EntityFramework.Exceptions.Common; diff --git a/Foxnouns.Backend/Controllers/FlagsController.cs b/Foxnouns.Backend/Controllers/FlagsController.cs index c68fb96..2b145ac 100644 --- a/Foxnouns.Backend/Controllers/FlagsController.cs +++ b/Foxnouns.Backend/Controllers/FlagsController.cs @@ -73,7 +73,7 @@ public class FlagsController( await db.SaveChangesAsync(); queue.QueueInvocableWithPayload( - new CreateFlagPayload(flag.Id, CurrentUser!.Id, req.Name, req.Image, req.Description) + new CreateFlagPayload(flag.Id, CurrentUser!.Id, req.Image) ); return Accepted(userRenderer.RenderPrideFlag(flag)); diff --git a/Foxnouns.Backend/Database/Models/User.cs b/Foxnouns.Backend/Database/Models/User.cs index c60430a..12df0ae 100644 --- a/Foxnouns.Backend/Database/Models/User.cs +++ b/Foxnouns.Backend/Database/Models/User.cs @@ -12,6 +12,8 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . + +// ReSharper disable UnusedAutoPropertyAccessor.Global using System.ComponentModel.DataAnnotations.Schema; using Foxnouns.Backend.Utils; using Newtonsoft.Json; @@ -89,5 +91,5 @@ public enum PreferenceSize public class UserSettings { - public bool? DarkMode { get; set; } = null; + public bool? DarkMode { get; set; } } diff --git a/Foxnouns.Backend/Dto/Flag.cs b/Foxnouns.Backend/Dto/Flag.cs index 955d8bd..203442b 100644 --- a/Foxnouns.Backend/Dto/Flag.cs +++ b/Foxnouns.Backend/Dto/Flag.cs @@ -14,6 +14,7 @@ // along with this program. If not, see . // ReSharper disable NotAccessedPositionalProperty.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global using Foxnouns.Backend.Database; using Foxnouns.Backend.Utils; @@ -23,8 +24,6 @@ public record PrideFlagResponse(Snowflake Id, string? ImageUrl, string Name, str public record CreateFlagRequest(string Name, string Image, string? Description); -public record CreateFlagResponse(Snowflake Id, string Name, string? Description); - public class UpdateFlagRequest : PatchRequest { public string? Name { get; init; } diff --git a/Foxnouns.Backend/Dto/Member.cs b/Foxnouns.Backend/Dto/Member.cs index b0c4bfa..4fcc147 100644 --- a/Foxnouns.Backend/Dto/Member.cs +++ b/Foxnouns.Backend/Dto/Member.cs @@ -14,6 +14,7 @@ // along with this program. If not, see . // ReSharper disable NotAccessedPositionalProperty.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global using Foxnouns.Backend.Database; using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Utils; diff --git a/Foxnouns.Backend/Dto/User.cs b/Foxnouns.Backend/Dto/User.cs index 0ab9511..a78aeba 100644 --- a/Foxnouns.Backend/Dto/User.cs +++ b/Foxnouns.Backend/Dto/User.cs @@ -15,6 +15,7 @@ // ReSharper disable NotAccessedPositionalProperty.Global // ReSharper disable ClassNeverInstantiated.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global using Foxnouns.Backend.Database; using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Utils; diff --git a/Foxnouns.Backend/Extensions/WebApplicationExtensions.cs b/Foxnouns.Backend/Extensions/WebApplicationExtensions.cs index 41c9712..d1b1156 100644 --- a/Foxnouns.Backend/Extensions/WebApplicationExtensions.cs +++ b/Foxnouns.Backend/Extensions/WebApplicationExtensions.cs @@ -57,7 +57,7 @@ public static class WebApplicationExtensions if (config.Logging.SeqLogUrl != null) { - logCfg.WriteTo.Seq(config.Logging.SeqLogUrl, LogEventLevel.Verbose); + logCfg.WriteTo.Seq(config.Logging.SeqLogUrl); } // AddSerilog doesn't seem to add an ILogger to the service collection, so add that manually. diff --git a/Foxnouns.Backend/Jobs/Payloads.cs b/Foxnouns.Backend/Jobs/Payloads.cs index 192a6fa..374a5b7 100644 --- a/Foxnouns.Backend/Jobs/Payloads.cs +++ b/Foxnouns.Backend/Jobs/Payloads.cs @@ -18,12 +18,6 @@ namespace Foxnouns.Backend.Jobs; public record AvatarUpdatePayload(Snowflake Id, string? NewAvatar); -public record CreateFlagPayload( - Snowflake Id, - Snowflake UserId, - string Name, - string ImageData, - string? Description -); +public record CreateFlagPayload(Snowflake Id, Snowflake UserId, string ImageData); public record CreateDataExportPayload(Snowflake UserId); diff --git a/Foxnouns.Backend/Mailables/PasswordChangedMailable.cs b/Foxnouns.Backend/Mailables/PasswordChangedMailable.cs index 79d86e3..46a0309 100644 --- a/Foxnouns.Backend/Mailables/PasswordChangedMailable.cs +++ b/Foxnouns.Backend/Mailables/PasswordChangedMailable.cs @@ -1,3 +1,17 @@ +// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . using Coravel.Mailer.Mail; namespace Foxnouns.Backend.Mailables; diff --git a/Foxnouns.Backend/Mailables/ResetPasswordMailable.cs b/Foxnouns.Backend/Mailables/ResetPasswordMailable.cs index 0f89b90..ee06732 100644 --- a/Foxnouns.Backend/Mailables/ResetPasswordMailable.cs +++ b/Foxnouns.Backend/Mailables/ResetPasswordMailable.cs @@ -1,3 +1,17 @@ +// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . using Coravel.Mailer.Mail; namespace Foxnouns.Backend.Mailables; diff --git a/Foxnouns.Backend/Middleware/AuthorizationMiddleware.cs b/Foxnouns.Backend/Middleware/AuthorizationMiddleware.cs index 908598a..976dc5b 100644 --- a/Foxnouns.Backend/Middleware/AuthorizationMiddleware.cs +++ b/Foxnouns.Backend/Middleware/AuthorizationMiddleware.cs @@ -14,7 +14,6 @@ // along with this program. If not, see . using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Utils; -using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace Foxnouns.Backend.Middleware; diff --git a/Foxnouns.Backend/Services/Auth/FediverseAuthService.Misskey.cs b/Foxnouns.Backend/Services/Auth/FediverseAuthService.Misskey.cs index beff74a..10a61e4 100644 --- a/Foxnouns.Backend/Services/Auth/FediverseAuthService.Misskey.cs +++ b/Foxnouns.Backend/Services/Auth/FediverseAuthService.Misskey.cs @@ -14,10 +14,8 @@ // along with this program. If not, see . using System.Net; using System.Text.Json.Serialization; -using System.Web; using Foxnouns.Backend.Database; using Foxnouns.Backend.Database.Models; -using Foxnouns.Backend.Extensions; namespace Foxnouns.Backend.Services.Auth; @@ -120,8 +118,7 @@ public partial class FediverseAuthService private async Task GenerateMisskeyAuthUrlAsync( FediverseApplication app, - bool forceRefresh, - string? state = null + bool forceRefresh ) { if (forceRefresh) diff --git a/Foxnouns.Backend/Services/Auth/FediverseAuthService.cs b/Foxnouns.Backend/Services/Auth/FediverseAuthService.cs index 250455a..9ca7290 100644 --- a/Foxnouns.Backend/Services/Auth/FediverseAuthService.cs +++ b/Foxnouns.Backend/Services/Auth/FediverseAuthService.cs @@ -131,8 +131,7 @@ public partial class FediverseAuthService ), FediverseInstanceType.MisskeyApi => await GenerateMisskeyAuthUrlAsync( app, - forceRefresh, - state + forceRefresh ), _ => throw new ArgumentOutOfRangeException(nameof(app), app.InstanceType, null), }; diff --git a/Foxnouns.Backend/Services/EmailRateLimiter.cs b/Foxnouns.Backend/Services/EmailRateLimiter.cs index 9e73792..3a1a81a 100644 --- a/Foxnouns.Backend/Services/EmailRateLimiter.cs +++ b/Foxnouns.Backend/Services/EmailRateLimiter.cs @@ -1,3 +1,17 @@ +// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . using System.Collections.Concurrent; using System.Threading.RateLimiting; using NodaTime; diff --git a/Foxnouns.Backend/Services/MemberRendererService.cs b/Foxnouns.Backend/Services/MemberRendererService.cs index 39f73ba..b0efc8d 100644 --- a/Foxnouns.Backend/Services/MemberRendererService.cs +++ b/Foxnouns.Backend/Services/MemberRendererService.cs @@ -17,7 +17,6 @@ using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Dto; using Foxnouns.Backend.Utils; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; namespace Foxnouns.Backend.Services; diff --git a/Foxnouns.Backend/Services/MetricsCollectionService.cs b/Foxnouns.Backend/Services/MetricsCollectionService.cs index 30568d5..8de0264 100644 --- a/Foxnouns.Backend/Services/MetricsCollectionService.cs +++ b/Foxnouns.Backend/Services/MetricsCollectionService.cs @@ -38,7 +38,7 @@ public class MetricsCollectionService(ILogger logger, IServiceProvider services, // ReSharper disable once SuggestVarOrType_SimpleTypes await using var db = scope.ServiceProvider.GetRequiredService(); - List? users = await db + List users = await db .Users.Where(u => !u.Deleted) .Select(u => u.LastActive) .ToListAsync(ct); diff --git a/Foxnouns.Backend/Services/ObjectStorageService.cs b/Foxnouns.Backend/Services/ObjectStorageService.cs index abfeafc..5ced7fb 100644 --- a/Foxnouns.Backend/Services/ObjectStorageService.cs +++ b/Foxnouns.Backend/Services/ObjectStorageService.cs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . using Minio; -using Minio.DataModel; using Minio.DataModel.Args; using Minio.Exceptions; diff --git a/Foxnouns.Backend/Services/UserRendererService.cs b/Foxnouns.Backend/Services/UserRendererService.cs index b5b1c50..028fc75 100644 --- a/Foxnouns.Backend/Services/UserRendererService.cs +++ b/Foxnouns.Backend/Services/UserRendererService.cs @@ -17,8 +17,6 @@ using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Dto; using Foxnouns.Backend.Utils; using Microsoft.EntityFrameworkCore; -using Newtonsoft.Json; -using NodaTime; namespace Foxnouns.Backend.Services; diff --git a/Foxnouns.Backend/Utils/OpenApi/PropertyKeySchemaTransformer.cs b/Foxnouns.Backend/Utils/OpenApi/PropertyKeySchemaTransformer.cs index 5be20cd..92c1f7c 100644 --- a/Foxnouns.Backend/Utils/OpenApi/PropertyKeySchemaTransformer.cs +++ b/Foxnouns.Backend/Utils/OpenApi/PropertyKeySchemaTransformer.cs @@ -1,3 +1,17 @@ +// Copyright (C) 2023-present sam/u1f320 (vulpine.solutions) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . using Foxnouns.Backend.Database; using Microsoft.AspNetCore.OpenApi; using Microsoft.OpenApi.Any; diff --git a/Foxnouns.Backend/Utils/ValidationUtils.Preferences.cs b/Foxnouns.Backend/Utils/ValidationUtils.Preferences.cs index da6c61c..3eed6e2 100644 --- a/Foxnouns.Backend/Utils/ValidationUtils.Preferences.cs +++ b/Foxnouns.Backend/Utils/ValidationUtils.Preferences.cs @@ -12,7 +12,6 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -using Foxnouns.Backend.Controllers; using Foxnouns.Backend.Dto; namespace Foxnouns.Backend.Utils;