Skip to content

Commit

Permalink
v3.21.1 (#497)
Browse files Browse the repository at this point in the history
* Don't try crucible tasks if it's not enabled. Fix auto tagging bug for player mode.

* Fix user role migration issue
  • Loading branch information
sei-bstein authored Sep 24, 2024
1 parent 5bd1327 commit 1b04fd8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ public partial class MigrateUserRoles : Migration
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql
("""
DO $$
DECLARE unmigratedUsers INTEGER;
BEGIN
SELECT INTO unmigratedUsers COUNT(*) FROM "Users" WHERE "Role" > 4;

IF unmigratedUsers > 0 THEN
UPDATE "Users" SET "Role" = CASE
WHEN "Role" = 0 THEN 0
WHEN CAST("Role" AS BIT(7)) & B'0100000' = b'0100000' THEN 4
WHEN CAST("Role" AS BIT(7)) & B'0010000' = B'0010000' THEN 3
WHEN CAST("Role" AS BIT(7)) & B'1000000' = B'1000000' THEN 2
WHEN "Role" != 0 THEN 1
ELSE 0
END
WHERE "Role" != 0;
END IF;
END; $$;
""");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{

// there's no going back, my friend
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Gameboard.Api.Features.Admin;
public sealed class ApprovePlayerNameRequest
{
public required string Name { get; set; }
public required string RevisionReason { get; set; }
public string RevisionReason { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface ICrucibleService
{
Task CompleteGamespace(Data.Challenge entity);
Task<GameEngineGameState> GradeChallenge(string challengeId, GameEngineSectionSubmission model);
bool IsEnabled();
Task<ExternalSpec[]> ListSpecs();
Task<GameEngineGameState> PreviewGamespace(string externalId);
Task<GameEngineGameState> RegisterGamespace(Data.ChallengeSpec spec, Data.Game game, Data.Player player, Data.Challenge entity);
Expand All @@ -41,6 +42,9 @@ IStore store

private readonly IStore _store = store;

public bool IsEnabled()
=> CrucibleOptions.Enabled;

public async Task<GameEngineGameState> RegisterGamespace(Data.ChallengeSpec spec, Data.Game game, Data.Player player, Data.Challenge entity)
{
var whenCreated = DateTimeOffset.UtcNow;
Expand Down Expand Up @@ -187,7 +191,7 @@ public async Task<GameEngineGameState> GradeChallenge(string challengeId, GameEn
public async Task<ExternalSpec[]> ListSpecs()
{
if (!CrucibleOptions.Enabled)
return Array.Empty<ExternalSpec>();
return [];

var eventTemplates = await Alloy.GetEventTemplatesAsync();
return Mapper.Map<ExternalSpec[]>(eventTemplates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public async Task<GameEngineGameState> RegisterGamespace(GameEngineChallengeRegi
case GameEngineType.TopoMojo:
var topoState = await Mojo.RegisterGamespaceAsync(new GamespaceRegistration
{
Players = new RegistrationPlayer[]
{
Players =
[
new()
{
SubjectId = registration.Player.TeamId,
SubjectName = registration.Player.ApprovedName
}
},
],
ResourceId = registration.ChallengeSpec.ExternalId,
Variant = registration.Variant,
Points = registration.ChallengeSpec.Points,
Expand Down Expand Up @@ -240,12 +240,19 @@ public async Task<ExternalSpec[]> ListGameEngineSpecs(SearchFilter model)
tasks.Add(mojoTask);
}

crucibleTask = _crucible.ListSpecs();
tasks.Add(crucibleTask);
if (_crucible.IsEnabled())
{
crucibleTask = _crucible.ListSpecs();
tasks.Add(crucibleTask);
}

await Task.WhenAll(tasks);
}
catch (Exception) { }
catch (Exception ex)
{
Logger.LogCritical($"Couldn't reach the game engine: {ex.GetType().Name}: {ex.Message}");
throw;
}

if (mojoTask != null && mojoTask.IsCompletedSuccessfully)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Gameboard.Api/Features/Support/AutoTagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public async Task<IEnumerable<string>> GetAutoTags(Data.Ticket ticket, Cancellat
})
.SingleAsync(cancellationToken);

var playerModeValue = (int)challengeData.PlayerMode;

var autoTagConfig = await _store
.WithNoTracking<SupportSettingsAutoTag>()
.Where(t => t.IsEnabled)
Expand All @@ -54,7 +56,7 @@ public async Task<IEnumerable<string>> GetAutoTags(Data.Ticket ticket, Cancellat
t =>
(t.ConditionType == SupportSettingsAutoTagConditionType.ChallengeSpecId && t.ConditionValue == challengeData.SpecId) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.GameId && t.ConditionValue == challengeData.GameId) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.PlayerMode && t.ConditionValue == challengeData.PlayerMode.ToString()) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.PlayerMode && t.ConditionValue == playerModeValue.ToString()) ||
(t.ConditionType == SupportSettingsAutoTagConditionType.SponsorId && teamSponsorIds.Contains(t.ConditionValue))
)
.Select(t => new
Expand Down

0 comments on commit 1b04fd8

Please sign in to comment.