Skip to content

Commit 1e6084e

Browse files
refactor: Remove legacy claim-based restrictions from chat command settings
1 parent 1e3b4df commit 1e6084e

6 files changed

Lines changed: 16 additions & 117 deletions

File tree

src/XtremeIdiots.Portal.Web.Tests/Controllers/GameServersControllerTests.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ public void PopulateConfigFromNamespace_ChatCommandsNamespace_MapsServerOverride
190190
"enabled": false,
191191
"freshnessSeconds": 4,
192192
"requiredTags": ["tag-fu"],
193-
"requiredClaims": ["claim-fu"],
194193
"settings": {
195194
"messages": [
196195
{ "message": "server-fu-{name}", "enabled": true }
@@ -208,12 +207,10 @@ public void PopulateConfigFromNamespace_ChatCommandsNamespace_MapsServerOverride
208207
Assert.False(fu.UseGlobalEnabled);
209208
Assert.False(fu.UseGlobalFreshness);
210209
Assert.False(fu.UseGlobalRequiredTags);
211-
Assert.False(fu.UseGlobalRequiredClaims);
212210
Assert.False(fu.UseGlobalMessages);
213211
Assert.False(fu.Enabled);
214212
Assert.Equal(4, fu.FreshnessSeconds);
215213
Assert.Equal("tag-fu", fu.RequiredTags);
216-
Assert.Equal("claim-fu", fu.RequiredClaims);
217214
Assert.Single(fu.Messages);
218215
Assert.Equal("server-fu-{name}", fu.Messages[0].Message);
219216
}
@@ -233,8 +230,7 @@ public void PopulateGlobalDefaults_ChatCommandsNamespace_MapsGlobalCommandDefaul
233230
"defaults": {
234231
"enabled": true,
235232
"freshnessSeconds": { "default": 8, "readOnly": 6, "mutating": 4 },
236-
"requiredTags": ["tag-a"],
237-
"requiredClaims": ["claim-a"]
233+
"requiredTags": ["tag-a"]
238234
},
239235
"commands": {
240236
"fu": {
@@ -305,8 +301,6 @@ public async Task SaveConfigNamespacesAsync_AgentEnabled_UpsertsChatCommandsCont
305301
FreshnessSeconds = 4,
306302
UseGlobalRequiredTags = false,
307303
RequiredTags = "tag-fu",
308-
UseGlobalRequiredClaims = false,
309-
RequiredClaims = "claim-fu",
310304
UseGlobalMessages = false,
311305
Messages =
312306
[
@@ -327,7 +321,6 @@ public async Task SaveConfigNamespacesAsync_AgentEnabled_UpsertsChatCommandsCont
327321
Assert.False(fu.GetProperty("enabled").GetBoolean());
328322
Assert.Equal(4, fu.GetProperty("freshnessSeconds").GetInt32());
329323
Assert.Equal("tag-fu", fu.GetProperty("requiredTags")[0].GetString());
330-
Assert.Equal("claim-fu", fu.GetProperty("requiredClaims")[0].GetString());
331324
Assert.Equal("server-fu-{name}", fu.GetProperty("settings").GetProperty("messages")[0].GetProperty("message").GetString());
332325
}
333326

@@ -375,8 +368,6 @@ public async Task SaveConfigNamespacesAsync_AgentEnabled_BlankChatCommandRequire
375368
FreshnessSeconds = 4,
376369
UseGlobalRequiredTags = false,
377370
RequiredTags = string.Empty,
378-
UseGlobalRequiredClaims = false,
379-
RequiredClaims = string.Empty,
380371
UseGlobalMessages = false,
381372
Messages =
382373
[
@@ -397,7 +388,6 @@ public async Task SaveConfigNamespacesAsync_AgentEnabled_BlankChatCommandRequire
397388
Assert.False(fu.GetProperty("enabled").GetBoolean());
398389
Assert.Equal(4, fu.GetProperty("freshnessSeconds").GetInt32());
399390
Assert.Empty(fu.GetProperty("requiredTags").EnumerateArray());
400-
Assert.Empty(fu.GetProperty("requiredClaims").EnumerateArray());
401391
Assert.Equal("server-fu-{name}", fu.GetProperty("settings").GetProperty("messages")[0].GetProperty("message").GetString());
402392
}
403393

src/XtremeIdiots.Portal.Web.Tests/Controllers/GlobalSettingsControllerTests.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ public void PopulateModelFromNamespace_ChatCommandsNamespace_MapsDefaultsAndFuMe
105105
"defaults": {
106106
"enabled": true,
107107
"freshnessSeconds": { "default": 8, "readOnly": 6, "mutating": 4 },
108-
"requiredTags": ["tag-a"],
109-
"requiredClaims": ["claim-a"]
108+
"requiredTags": ["tag-a"]
110109
},
111110
"commands": {
112111
"fu": {
113112
"enabled": true,
114113
"freshnessSeconds": 9,
115114
"requiredTags": ["tag-fu"],
116-
"requiredClaims": ["claim-fu"],
117115
"settings": {
118116
"messages": [
119117
{ "message": "fu-{name}", "enabled": true }
@@ -132,20 +130,18 @@ public void PopulateModelFromNamespace_ChatCommandsNamespace_MapsDefaultsAndFuMe
132130
Assert.Equal(6, model.ChatCommands.ReadOnlyFreshnessSeconds);
133131
Assert.Equal(4, model.ChatCommands.MutatingFreshnessSeconds);
134132
Assert.Equal("tag-a", model.ChatCommands.DefaultRequiredTags);
135-
Assert.Equal("claim-a", model.ChatCommands.DefaultRequiredClaims);
136133

137134
var fu = model.ChatCommands.Commands.Single(x => x.Name == "fu");
138135
Assert.True(fu.Enabled);
139136
Assert.Equal(9, fu.FreshnessSeconds);
140137
Assert.Equal("tag-fu", fu.RequiredTags);
141-
Assert.Equal("claim-fu", fu.RequiredClaims);
142138
Assert.Single(fu.Messages);
143139
Assert.Equal("fu-{name}", fu.Messages[0].Message);
144140
Assert.True(fu.Messages[0].Enabled);
145141
}
146142

147143
[Fact]
148-
public async Task Index_Post_ChatCommandsBlankRequirements_OmitsGlobalTagAndClaimDefaults()
144+
public async Task Index_Post_ChatCommandsBlankRequirements_OmitsGlobalTagDefaults()
149145
{
150146
var sut = CreateSut();
151147
var upsertPayloads = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
@@ -166,8 +162,7 @@ public async Task Index_Post_ChatCommandsBlankRequirements_OmitsGlobalTagAndClai
166162
{
167163
ChatCommands = new ChatCommandGlobalSettingsViewModel
168164
{
169-
DefaultRequiredTags = string.Empty,
170-
DefaultRequiredClaims = string.Empty
165+
DefaultRequiredTags = string.Empty
171166
}
172167
};
173168

@@ -180,6 +175,5 @@ public async Task Index_Post_ChatCommandsBlankRequirements_OmitsGlobalTagAndClai
180175
var defaults = doc.RootElement.GetProperty("defaults");
181176

182177
Assert.False(defaults.TryGetProperty("requiredTags", out _));
183-
Assert.False(defaults.TryGetProperty("requiredClaims", out _));
184178
}
185179
}

src/XtremeIdiots.Portal.Web/ViewModels/ChatCommandSettingsViewModels.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public class ChatCommandGlobalSettingsViewModel : IValidatableObject
3636
[DisplayName("Default Required Tags")]
3737
public string? DefaultRequiredTags { get; set; } = string.Empty;
3838

39-
[DisplayName("Default Required Claims")]
40-
public string? DefaultRequiredClaims { get; set; } = string.Empty;
41-
4239
public List<ChatCommandGlobalEntryViewModel> Commands { get; set; } =
4340
ChatCommandDescriptorCatalog.All
4441
.Select(static descriptor => new ChatCommandGlobalEntryViewModel
@@ -105,9 +102,6 @@ public abstract class ChatCommandEntryViewModelBase
105102
[DisplayName("Required Tags")]
106103
public string? RequiredTags { get; set; } = string.Empty;
107104

108-
[DisplayName("Required Claims")]
109-
public string? RequiredClaims { get; set; } = string.Empty;
110-
111105
public List<BroadcastMessageViewModel> Messages { get; set; } = [];
112106
}
113107

@@ -126,9 +120,6 @@ public sealed class ChatCommandServerEntryViewModel : ChatCommandEntryViewModelB
126120
[DisplayName("Use Global Required Tags")]
127121
public bool UseGlobalRequiredTags { get; set; } = true;
128122

129-
[DisplayName("Use Global Required Claims")]
130-
public bool UseGlobalRequiredClaims { get; set; } = true;
131-
132123
[DisplayName("Use Global Messages")]
133124
public bool UseGlobalMessages { get; set; } = true;
134125
}
@@ -186,7 +177,6 @@ public static void PopulateGlobal(ChatCommandGlobalSettingsViewModel target, Jso
186177
}
187178

188179
target.DefaultRequiredTags = string.Join(", ", GetStringArray(defaultsElement, "requiredTags"));
189-
target.DefaultRequiredClaims = string.Join(", ", GetStringArray(defaultsElement, "requiredClaims"));
190180
}
191181

192182
if (root.TryGetProperty("commands", out var commandsElement) && commandsElement.ValueKind == JsonValueKind.Object)
@@ -236,12 +226,6 @@ public static string BuildGlobalConfigurationJson(ChatCommandGlobalSettingsViewM
236226
defaults["requiredTags"] = defaultRequiredTags;
237227
}
238228

239-
var defaultRequiredClaims = SplitCsv(model.DefaultRequiredClaims);
240-
if (defaultRequiredClaims.Length > 0)
241-
{
242-
defaults["requiredClaims"] = defaultRequiredClaims;
243-
}
244-
245229
payload["schemaVersion"] = ChatCommandSettingsConstants.SupportedSchemaVersion;
246230
payload["defaults"] = defaults;
247231
payload["commands"] = commands;
@@ -288,12 +272,6 @@ public static string BuildServerConfigurationJson(ChatCommandServerSettingsViewM
288272
payload["requiredTags"] = requiredTags;
289273
}
290274

291-
var requiredClaims = SplitCsv(command.RequiredClaims);
292-
if (requiredClaims.Length > 0)
293-
{
294-
payload["requiredClaims"] = requiredClaims;
295-
}
296-
297275
if (command.Messages.Count > 0)
298276
{
299277
var messagePayloads = command.Messages.Select(m =>
@@ -331,11 +309,6 @@ public static string BuildServerConfigurationJson(ChatCommandServerSettingsViewM
331309
payload["requiredTags"] = SplitCsv(command.RequiredTags);
332310
}
333311

334-
if (!command.UseGlobalRequiredClaims)
335-
{
336-
payload["requiredClaims"] = SplitCsv(command.RequiredClaims);
337-
}
338-
339312
if (!command.UseGlobalMessages && command.Messages.Count > 0)
340313
{
341314
var messagePayloads = command.Messages.Select(m =>
@@ -391,15 +364,6 @@ private static void PopulateCommandEntries<T>(IReadOnlyList<T> commands, JsonEle
391364
}
392365
}
393366

394-
if (commandElement.TryGetProperty("requiredClaims", out _))
395-
{
396-
command.RequiredClaims = string.Join(", ", GetStringArray(commandElement, "requiredClaims"));
397-
if (isServerOverride && command is ChatCommandServerEntryViewModel serverEntry)
398-
{
399-
serverEntry.UseGlobalRequiredClaims = false;
400-
}
401-
}
402-
403367
if (commandElement.TryGetProperty("settings", out var settingsElement) &&
404368
settingsElement.ValueKind == JsonValueKind.Object &&
405369
settingsElement.TryGetProperty("messages", out var messagesElement) &&

src/XtremeIdiots.Portal.Web/Views/GameServers/ConfigurationSections/_ChatCommandsConfiguration.cshtml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<strong>!fu</strong> message payloads now live inside the <code>chatCommands</code> contract. Leaving the
1919
server-specific list empty while using a local override will make the command unavailable on this server.
2020
</p>
21+
<div class="alert alert-warning mt-3 mb-0" role="alert">
22+
Legacy claim-based command restrictions are no longer supported. Saving chat command settings will keep only
23+
tag-based authorization rules.
24+
</div>
2125
</div>
2226
</div>
2327

@@ -33,9 +37,6 @@ StringComparison.OrdinalIgnoreCase));
3337
var globalTags = !string.IsNullOrWhiteSpace(globalCommand?.RequiredTags)
3438
? globalCommand.RequiredTags
3539
: Model.GlobalChatCommands.DefaultRequiredTags;
36-
var globalClaims = !string.IsNullOrWhiteSpace(globalCommand?.RequiredClaims)
37-
? globalCommand.RequiredClaims
38-
: Model.GlobalChatCommands.DefaultRequiredClaims;
3940
var globalMessageCount = globalCommand?.Messages?.Count ?? 0;
4041
var isFuCommand = string.Equals(command.Name, "fu", StringComparison.OrdinalIgnoreCase);
4142

@@ -125,7 +126,7 @@ StringComparison.OrdinalIgnoreCase));
125126
</div>
126127

127128
<div class="row">
128-
<div class="col-lg-6">
129+
<div class="col-lg-12">
129130
<div class="border rounded p-3 mb-3">
130131
<input type="hidden" name="ChatCommands.Commands[@i].UseGlobalRequiredTags" value="false" />
131132
<div class="form-check mb-3">
@@ -157,39 +158,6 @@ StringComparison.OrdinalIgnoreCase));
157158
</div>
158159
</div>
159160
</div>
160-
161-
<div class="col-lg-6">
162-
<div class="border rounded p-3 mb-3">
163-
<input type="hidden" name="ChatCommands.Commands[@i].UseGlobalRequiredClaims" value="false" />
164-
<div class="form-check mb-3">
165-
@if (command.UseGlobalRequiredClaims)
166-
{
167-
<input class="form-check-input" type="checkbox"
168-
id="ChatCommands_Commands_@(i)__UseGlobalRequiredClaims"
169-
name="ChatCommands.Commands[@i].UseGlobalRequiredClaims" value="true" data-global-toggle
170-
data-global-target="chat-command-@i-claims-override" checked="checked" />
171-
}
172-
else
173-
{
174-
<input class="form-check-input" type="checkbox"
175-
id="ChatCommands_Commands_@(i)__UseGlobalRequiredClaims"
176-
name="ChatCommands.Commands[@i].UseGlobalRequiredClaims" value="true" data-global-toggle
177-
data-global-target="chat-command-@i-claims-override" />
178-
}
179-
<label class="form-check-label" for="ChatCommands_Commands_@(i)__UseGlobalRequiredClaims">Use
180-
global required claims</label>
181-
</div>
182-
<div class="small text-muted mb-2">Global value: <strong>@(string.IsNullOrWhiteSpace(globalClaims) ?
183-
"None" : globalClaims)</strong></div>
184-
<div id="chat-command-@i-claims-override"
185-
class="@(command.UseGlobalRequiredClaims ? "d-none" : string.Empty)">
186-
<label asp-for="ChatCommands.Commands[i].RequiredClaims" class="form-label"></label>
187-
<input asp-for="ChatCommands.Commands[i].RequiredClaims" class="form-control" />
188-
<span asp-validation-for="ChatCommands.Commands[i].RequiredClaims" class="text-danger"></span>
189-
<small class="form-text text-muted">Optional. Leave blank to avoid extra claim gating.</small>
190-
</div>
191-
</div>
192-
</div>
193161
</div>
194162

195163
@if (isFuCommand)

src/XtremeIdiots.Portal.Web/Views/GlobalSettings/_ChatCommandsConfiguration.cshtml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
Configure fleet-wide defaults for in-game chat commands. Per-command overrides below can refine the shared
1414
defaults.
1515
</p>
16+
<div class="alert alert-warning" role="alert">
17+
Legacy claim-based command restrictions are no longer supported. Saving chat command settings will keep only
18+
tag-based authorization rules.
19+
</div>
1620

1721
<div class="row">
1822
<div class="col-md-4">
@@ -65,24 +69,15 @@
6569
<strong>!register</strong>.</small>
6670
</div>
6771
</div>
68-
<div class="col-md-4">
72+
<div class="col-md-8">
6973
<div class="mb-3">
7074
<label asp-for="ChatCommands.DefaultRequiredTags" class="form-label"></label>
7175
<input asp-for="ChatCommands.DefaultRequiredTags" class="form-control" />
7276
<span asp-validation-for="ChatCommands.DefaultRequiredTags" class="text-danger"></span>
7377
<small class="form-text text-muted">Optional comma-separated player tags. Leave blank for no tag
7478
requirement.</small>
75-
</div>
7679
</div>
77-
<div class="col-md-4">
78-
<div class="mb-3">
79-
<label asp-for="ChatCommands.DefaultRequiredClaims" class="form-label"></label>
80-
<input asp-for="ChatCommands.DefaultRequiredClaims" class="form-control" />
81-
<span asp-validation-for="ChatCommands.DefaultRequiredClaims" class="text-danger"></span>
82-
<small class="form-text text-muted">Optional comma-separated portal claims. Leave blank for no claim
83-
requirement.</small>
84-
</div>
85-
</div>
80+
</div>
8681
</div>
8782
</div>
8883
</div>
@@ -152,18 +147,6 @@
152147
</div>
153148
</div>
154149

155-
<div class="row">
156-
<div class="col-lg-6">
157-
<div class="mb-0">
158-
<label asp-for="ChatCommands.Commands[i].RequiredClaims" class="form-label"></label>
159-
<input asp-for="ChatCommands.Commands[i].RequiredClaims" class="form-control"
160-
placeholder="@Model.ChatCommands.DefaultRequiredClaims" />
161-
<span asp-validation-for="ChatCommands.Commands[i].RequiredClaims" class="text-danger"></span>
162-
<small class="form-text text-muted">Optional. Leave blank to avoid extra claim gating.</small>
163-
</div>
164-
</div>
165-
</div>
166-
167150
@if (isFuCommand)
168151
{
169152
var containerId = $"global-chat-command-{i}-messages-container";

src/XtremeIdiots.Portal.Web/XtremeIdiots.Portal.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<PackageReference Include="MX.Api.Abstractions" Version="2.3.31" />
4949
<PackageReference Include="MX.Api.Client" Version="2.3.31" />
5050
<PackageReference Include="XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1" Version="2.1.180" />
51-
<PackageReference Include="XtremeIdiots.Portal.ChatCommands.Abstractions.V1" Version="1.1.73" />
51+
<PackageReference Include="XtremeIdiots.Portal.ChatCommands.Abstractions.V1" Version="1.1.74" />
5252
<PackageReference Include="XtremeIdiots.Portal.Repository.Api.Client.V1" Version="2.1.250" />
5353
<PackageReference Include="XtremeIdiots.Portal.Repository.Abstractions.V1" Version="2.1.250" />
5454
<PackageReference Include="MX.GeoLocation.Api.Client.V1" Version="1.2.39" />

0 commit comments

Comments
 (0)