Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for selecting channels for system messages #1489

Merged
merged 12 commits into from
May 21, 2023
Merged
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Whenever you make a change to a model schema that must be reflected in the datab

We have a script to do this.

Warning: You may need to temporarily set valid MySql credentials in [MySqlDesignTimeDbContextFactory.cs](../src/Tgstation.Server.Host/Database/Design/MySqlDesignTimeDbContextFactory.cs) for migrations to generate properly. I have no idea why. Be careful not to commit the change.

1. Run `build/GenerateMigrations.sh NameOfMigration` from the project root.
1. You should now have MY/MS/SL/PG migration files generated in `/src/Tgstation.Server.Host/Models/Migrations`. Fix compiler warnings in the generated files. Ensure all classes are in the Tgstation.Server.Host.Database.Migrations namespace.
1. Manually review what each migration does.
Expand Down
9 changes: 9 additions & 0 deletions build/Common.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Version.props" />

<PropertyGroup>
<TgsNetVersion>net6.0</TgsNetVersion>
<LangVersion>latest</LangVersion>
<DebugType>Full</DebugType>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
<TgsHostWatchdogVersion>1.2.2</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>1.0.1</TgsMigratorVersion>
<TgsNetVersion>net6.0</TgsNetVersion>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions src/Tgstation.Server.Api/Models/Internal/ChatChannelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public abstract class ChatChannelBase
[Required]
public bool? IsUpdatesChannel { get; set; }

/// <summary>
/// If the <see cref="ChatChannel"/> received system messages.
/// </summary>
[Required]
public bool? IsSystemChannel { get; set; }

/// <summary>
/// A custom tag users can define to group channels together.
/// </summary>
Expand Down
8 changes: 3 additions & 5 deletions src/Tgstation.Server.Api/Tgstation.Server.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<Version>$(TgsApiLibraryVersion)</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Cyberboss/Dominion</Authors>
Expand All @@ -19,11 +18,10 @@
<PackageReleaseNotes>Minor documentation correction.</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Tgstation.Server.Api.xml</DocumentationFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>CA1028</NoWarn>
</PropertyGroup>

Expand Down
7 changes: 3 additions & 4 deletions src/Tgstation.Server.Client/Tgstation.Server.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<Version>$(TgsClientVersion)</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Cyberboss/Dominion</Authors>
Expand All @@ -19,11 +18,11 @@
<PackageReleaseNotes>Added missing Dispose() call to the StringContents for requests with bodies and added missing ConfigureAwait(false) to async call.</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Tgstation.Server.Client.xml</DocumentationFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
9 changes: 3 additions & 6 deletions src/Tgstation.Server.Common/Tgstation.Server.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<Version>$(TgsCoreVersion)</Version>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Tgstation.Server.Client.xml</DocumentationFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<Version>$(TgsCoreVersion)</Version>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Tgstation.Server.Host.Shared.xml</DocumentationFile>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<DebugType>Full</DebugType>
<TargetFramework>$(TgsNetVersion)</TargetFramework>
<Version>$(TgsCoreVersion)</Version>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifier>win</RuntimeIdentifier>
<DebugType>Full</DebugType>
<Version>$(TgsCoreVersion)</Version>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.3</LangVersion>
<DocumentationFile>bin\Debug\Tgstation.Server.Host.Console.xml</DocumentationFile>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/Version.props" />
<Import Project="../../build/Common.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DebugType>Full</DebugType>
<AddSyntheticProjectReferencesForSolutionDependencies>false</AddSyntheticProjectReferencesForSolutionDependencies>
<Version>$(TgsHostWatchdogVersion)</Version>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<DocumentationFile>bin\$(Configuration)\netstandard2.0\Tgstation.Server.Host.Watchdog.xml</DocumentationFile>
<CodeAnalysisRuleSet>../../build/analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(TargetDir)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion src/Tgstation.Server.Host/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.15",
"version": "6.0.16",
"commands": [
"dotnet-ef"
]
Expand Down
5 changes: 5 additions & 0 deletions src/Tgstation.Server.Host/Components/Chat/ChannelMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ sealed class ChannelMapping
/// </summary>
public bool IsAdminChannel { get; set; }

/// <summary>
/// If the <see cref="Channel"/> is a system messages channel.
/// </summary>
public bool IsSystemChannel { get; set; }

/// <summary>
/// The <see cref="ChannelRepresentation"/> with the mapped Id.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Tgstation.Server.Host/Components/Chat/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public async Task ChangeChannels(long connectionId, IEnumerable<Models.ChatChann
IrcChannel = apiModel.IrcChannel,
IsAdminChannel = apiModel.IsAdminChannel,
IsUpdatesChannel = apiModel.IsUpdatesChannel,
IsSystemChannel = apiModel.IsSystemChannel,
IsWatchdogChannel = apiModel.IsWatchdogChannel,
Tag = apiModel.Tag,
})
Expand All @@ -220,6 +221,7 @@ public async Task ChangeChannels(long connectionId, IEnumerable<Models.ChatChann
IsWatchdogChannel = kvp.Key.IsWatchdogChannel == true,
IsUpdatesChannel = kvp.Key.IsUpdatesChannel == true,
IsAdminChannel = kvp.Key.IsAdminChannel == true,
IsSystemChannel = kvp.Key.IsSystemChannel == true,
ProviderChannelId = channelRepresentation.RealId,
ProviderId = connectionId,
Channel = channelRepresentation,
Expand Down Expand Up @@ -514,7 +516,7 @@ public Task HandleRestart(Version updateVersion, bool gracefulShutdown, Cancella
List<ulong> wdChannels;
lock (mappedChannels) // so it doesn't change while we're using it
wdChannels = mappedChannels
.Where(x => !x.Value.Channel.IsPrivateChannel)
.Where(x => !x.Value.IsSystemChannel)
.Select(x => x.Key)
.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ sealed class TopicClientFactory : ITopicClientFactory
/// <param name="logger">The value of <see cref="logger"/>.</param>
public TopicClientFactory(ILogger<TopicClient> logger)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
if (logger == null)
throw new ArgumentNullException(nameof(logger));

// Don't want the debug logs Topic client spits out either, they're too verbose
if (logger.IsEnabled(LogLevel.Trace))
this.logger = logger;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
using (await SemaphoreSlimContext.Lock(synchronizationSemaphore, ct))
await LaunchNoLock(true, true, true, reattachInfo, ct);
},
cancellationToken)
;
cancellationToken);
}

/// <inheritdoc />
Expand Down
1 change: 1 addition & 0 deletions src/Tgstation.Server.Host/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static Models.ChatChannel ConvertApiChatChannel(Api.Models.ChatChannel api, Chat
IsAdminChannel = api.IsAdminChannel ?? false,
IsWatchdogChannel = api.IsWatchdogChannel ?? false,
IsUpdatesChannel = api.IsUpdatesChannel ?? false,
IsSystemChannel = api.IsSystemChannel ?? false,
Tag = api.Tag,
};

Expand Down
17 changes: 13 additions & 4 deletions src/Tgstation.Server.Host/Database/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,22 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
/// <summary>
/// Used by unit tests to remind us to setup the correct MSSQL migration downgrades.
/// </summary>
internal static readonly Type MSLatestMigration = typeof(MSAddReattachInfoInitialCompileJob);
internal static readonly Type MSLatestMigration = typeof(MSAddSystemChannels);

/// <summary>
/// Used by unit tests to remind us to setup the correct MYSQL migration downgrades.
/// </summary>
internal static readonly Type MYLatestMigration = typeof(MYAddReattachInfoInitialCompileJob);
internal static readonly Type MYLatestMigration = typeof(MYAddSystemChannels);

/// <summary>
/// Used by unit tests to remind us to setup the correct PostgresSQL migration downgrades.
/// </summary>
internal static readonly Type PGLatestMigration = typeof(PGAddReattachInfoInitialCompileJob);
internal static readonly Type PGLatestMigration = typeof(PGAddSystemChannels);

/// <summary>
/// Used by unit tests to remind us to setup the correct SQLite migration downgrades.
/// </summary>
internal static readonly Type SLLatestMigration = typeof(SLAddReattachInfoInitialCompileJob);
internal static readonly Type SLLatestMigration = typeof(SLAddSystemChannels);

/// <inheritdoc />
#pragma warning disable CA1502 // Cyclomatic complexity
Expand Down Expand Up @@ -425,6 +425,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

string BadDatabaseType() => throw new ArgumentException($"Invalid DatabaseType: {currentDatabaseType}", nameof(currentDatabaseType));

if (targetVersion < new Version(5, 13, 0))
targetMigration = currentDatabaseType switch
{
DatabaseType.MySql => nameof(MYAddReattachInfoInitialCompileJob),
DatabaseType.PostgresSql => nameof(PGAddReattachInfoInitialCompileJob),
DatabaseType.SqlServer => nameof(MSAddReattachInfoInitialCompileJob),
DatabaseType.Sqlite => nameof(SLAddReattachInfoInitialCompileJob),
_ => BadDatabaseType(),
};
if (targetVersion < new Version(5, 7, 3))
targetMigration = currentDatabaseType switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public MySqlDatabaseContext CreateDbContext(string[] args)
=> new MySqlDatabaseContext(
DesignTimeDbContextFactoryHelpers.CreateDatabaseContextOptions<MySqlDatabaseContext>(
DatabaseType.MariaDB,
"Server=127.0.0.1;User Id=root;Password=fake;Database=TGS_Design"));
"Server=127.0.0.1;User Id=root;Password=zdxfOOTlQFnklwzytzCj;Database=TGS_Design"));
}
}
Loading
Loading