Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add AliasVault.Shared.Server project (#221)
Leendert de Borst962886118661
diff --git a/aliasvault.sln b/aliasvault.slnindex 512cdb7b9..d20754add 100644--- a/aliasvault.sln+++ b/aliasvault.sln@@ -69,6 +69,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AliasVault.Shared.Core", "sEndProjectProject("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AliasVault.TaskRunner", "src\Services\AliasVault.TaskRunner\AliasVault.TaskRunner.csproj", "{D631A936-DD1C-40CC-B735-BD0A5D4F46A1}"EndProject+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AliasVault.Shared.Server", "src\Shared\AliasVault.Shared.Server\AliasVault.Shared.Server.csproj", "{34FADEB6-4B56-463B-B359-F844B43D76D9}"+EndProjectGlobalGlobalSection(SolutionConfigurationPlatforms) = preSolutionDebug|Any CPU = Debug|Any CPU@@ -175,6 +177,10 @@ Global{D631A936-DD1C-40CC-B735-BD0A5D4F46A1}.Debug|Any CPU.Build.0 = Debug|Any CPU{D631A936-DD1C-40CC-B735-BD0A5D4F46A1}.Release|Any CPU.ActiveCfg = Release|Any CPU{D631A936-DD1C-40CC-B735-BD0A5D4F46A1}.Release|Any CPU.Build.0 = Release|Any CPU+ {34FADEB6-4B56-463B-B359-F844B43D76D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {34FADEB6-4B56-463B-B359-F844B43D76D9}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {34FADEB6-4B56-463B-B359-F844B43D76D9}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {34FADEB6-4B56-463B-B359-F844B43D76D9}.Release|Any CPU.Build.0 = Release|Any CPUEndGlobalSectionGlobalSection(SolutionProperties) = preSolutionHideSolutionNode = FALSE@@ -204,6 +210,7 @@ Global{15EFE0D0-F41B-47D7-86B7-8F840335CB82} = {DD359F0A-0180-4F8F-9E48-46213386BA4D}{40CA41BF-9E67-4D0A-A3F8-38B94992E4CA} = {DD359F0A-0180-4F8F-9E48-46213386BA4D}{D631A936-DD1C-40CC-B735-BD0A5D4F46A1} = {8A477241-B96C-4174-968D-D40CB77F1ECD}+ {34FADEB6-4B56-463B-B359-F844B43D76D9} = {DD359F0A-0180-4F8F-9E48-46213386BA4D}EndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionSolutionGuid = {FEE82475-C009-4762-8113-A6563D9DC49E}diff --git a/src/Shared/AliasVault.Shared.Server/AliasVault.Shared.Server.csproj b/src/Shared/AliasVault.Shared.Server/AliasVault.Shared.Server.csprojnew file mode 100644index 000000000..54233aa2e--- /dev/null+++ b/src/Shared/AliasVault.Shared.Server/AliasVault.Shared.Server.csproj@@ -0,0 +1,36 @@+<Project Sdk="Microsoft.NET.Sdk">++ <PropertyGroup>+ <TargetFramework>net9.0</TargetFramework>+ <ImplicitUsings>enable</ImplicitUsings>+ <Nullable>enable</Nullable>+ </PropertyGroup>++ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">+ <DocumentationFile>bin\Debug\net9.0\AliasVault.Shared.Server.xml</DocumentationFile>+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>+ </PropertyGroup>++ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">+ <DocumentationFile>bin\Release\net9.0\AliasVault.Shared.Server.xml</DocumentationFile>+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>+ </PropertyGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\Databases\AliasServerDb\AliasServerDb.csproj" />+ </ItemGroup>++ <ItemGroup>+ <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">+ <PrivateAssets>all</PrivateAssets>+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>+ </PackageReference>+ </ItemGroup>++ <ItemGroup>+ <AdditionalFiles Include="..\..\stylecop.json">+ <Link>stylecop.json</Link>+ </AdditionalFiles>+ </ItemGroup>++</Project>diff --git a/src/AliasVault.Admin/Models/ServerSettingsModel.cs b/src/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.cssimilarity index 97%rename from src/AliasVault.Admin/Models/ServerSettingsModel.csrename to src/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.csindex 4ef9bf826..789fd6ef8 100644--- a/src/AliasVault.Admin/Models/ServerSettingsModel.cs+++ b/src/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.cs@@ -5,7 +5,7 @@// </copyright>//------------------------------------------------------------------------namespace AliasVault.Admin.Models;+namespace AliasVault.Shared.Server.Models;/// <summary>/// Server settings model.diff --git a/src/Shared/AliasVault.Shared.Server/README.md b/src/Shared/AliasVault.Shared.Server/README.mdnew file mode 100644index 000000000..00eacde73--- /dev/null+++ b/src/Shared/AliasVault.Shared.Server/README.md@@ -0,0 +1,5 @@+# AliasVault.Shared.Server++This project contains shared functionality used only by the server applications and not required by the client applications.++This is to reduce the number of client dependencies and keep the client applications as lightweight as possible.\ No newline at end of filediff --git a/src/AliasVault.Admin/Services/ServerSettingsService.cs b/src/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.cssimilarity index 81%rename from src/AliasVault.Admin/Services/ServerSettingsService.csrename to src/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.csindex 752fb6434..2f78b96a1 100644--- a/src/AliasVault.Admin/Services/ServerSettingsService.cs+++ b/src/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.cs@@ -5,33 +5,24 @@// </copyright>//------------------------------------------------------------------------namespace AliasVault.Admin.Services;+namespace AliasVault.Shared.Server.Services;using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using AliasServerDb;-using AliasVault.Admin.Models;+using AliasVault.Shared.Server.Models;using Microsoft.EntityFrameworkCore;/// <summary>/// Server settings service./// </summary>-public class ServerSettingsService+/// <param name="dbContextFactory">IDbContextFactory instance.</param>+public class ServerSettingsService(IDbContextFactory<AliasServerDbContext> dbContextFactory){- private readonly AliasServerDbContext _dbContext;private readonly Dictionary<string, string?> _cache = new();- /// <summary>- /// Initializes a new instance of the <see cref="ServerSettingsService"/> class.- /// </summary>- /// <param name="dbContext">The database context.</param>- public ServerSettingsService(AliasServerDbContext dbContext)- {- _dbContext = dbContext;- }-/// <summary>/// Gets the setting async./// </summary>@@ -44,7 +35,9 @@ public class ServerSettingsServicereturn cachedValue;}- var setting = await _dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);+ await using var dbContext = await dbContextFactory.CreateDbContextAsync(CancellationToken.None);+ var setting = await dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);+_cache[key] = setting?.Value;return setting?.Value;}@@ -63,7 +56,8 @@ public class ServerSettingsServicereturn;}- var setting = await _dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);+ await using var dbContext = await dbContextFactory.CreateDbContextAsync(CancellationToken.None);+ var setting = await dbContext.ServerSettings.FirstOrDefaultAsync(x => x.Key == key);var now = DateTime.UtcNow;// If setting exists and value hasn't changed, return early@@ -83,7 +77,7 @@ public class ServerSettingsServiceCreatedAt = now,UpdatedAt = now,};- _dbContext.ServerSettings.Add(setting);+ dbContext.ServerSettings.Add(setting);}else{@@ -91,7 +85,7 @@ public class ServerSettingsServicesetting.UpdatedAt = now;}- await _dbContext.SaveChangesAsync();+ await dbContext.SaveChangesAsync();_cache[key] = value;}@@ -101,7 +95,8 @@ public class ServerSettingsService/// <returns>The settings.</returns>public async Task<ServerSettingsModel> GetAllSettingsAsync(){- var settings = await _dbContext.ServerSettings.ToDictionaryAsync(x => x.Key, x => x.Value);+ await using var dbContext = await dbContextFactory.CreateDbContextAsync(CancellationToken.None);+ var settings = await dbContext.ServerSettings.ToDictionaryAsync(x => x.Key, x => x.Value);return new ServerSettingsModel{