From 5f7d3cac9918c09b047dafb464bab6f858182648 Mon Sep 17 00:00:00 2001 From: Rick Mason Date: Fri, 11 Oct 2024 20:34:44 +0100 Subject: [PATCH] Change ClubOrTeam to Team because team, not club, permissions will be required #627 --- .../SqlServerPlayerRepositoryTests.cs | 24 +++++++++---------- .../SqlServerPlayerRepositoryUnitTests.cs | 2 +- ...dPlayersForMemberSurfaceControllerTests.cs | 2 +- .../Models/LinkedPlayersViewModel.cs | 4 ++-- .../LinkedPlayersForIdentityController.cs | 2 +- ...nkedPlayersForIdentitySurfaceController.cs | 4 ++-- .../Views/LinkedPlayersForIdentity.cshtml | 4 ++-- .../Views/LinkedPlayersForMember.cshtml | 2 +- .../Views/Partials/_LinkedPlayers.cshtml | 6 ++--- .../Statistics/PlayerIdentityLinkedBy.cs | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Stoolball.Data.SqlServer.IntegrationTests/Statistics/SqlServerPlayerRepositoryTests.cs b/Stoolball.Data.SqlServer.IntegrationTests/Statistics/SqlServerPlayerRepositoryTests.cs index 648db9c6..97bda372 100644 --- a/Stoolball.Data.SqlServer.IntegrationTests/Statistics/SqlServerPlayerRepositoryTests.cs +++ b/Stoolball.Data.SqlServer.IntegrationTests/Statistics/SqlServerPlayerRepositoryTests.cs @@ -430,7 +430,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit SetupMocksForLinkPlayerIdentity(player, player); var repo = CreateRepository(); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player.PlayerId!.Value, player.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name")); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player.PlayerId!.Value, player.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name")); } [Fact] @@ -441,7 +441,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_both_pl SetupMocksForLinkPlayerIdentity(player1, player2); var repo = CreateRepository(); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name")); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name")); } [Theory] @@ -457,7 +457,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_target_ var currentMember = player1.MemberKey!.Value; SetupMocksForLinkPlayerIdentity(player1, player2); - var exception = await Record.ExceptionAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember, "Member name")); + var exception = await Record.ExceptionAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember, "Member name")); Assert.Null(exception); } else @@ -467,7 +467,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_target_ var player2 = _testData.AnyPlayerNotLinkedToMemberWithOnlyOneIdentity(p => p.IsOnTheSameTeamAs(player1)); SetupMocksForLinkPlayerIdentity(player1, player2); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember.memberKey, currentMember.memberName)); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember.memberKey, currentMember.memberName)); } } @@ -485,7 +485,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit var currentMember = player2.MemberKey!.Value; SetupMocksForLinkPlayerIdentity(player1, player2); - var exception = await Record.ExceptionAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember, "Member name")); + var exception = await Record.ExceptionAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember, "Member name")); Assert.Null(exception); } else @@ -495,7 +495,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit var player2 = _testData.AnyPlayerLinkedToMemberWithOnlyOneIdentity(p => p.MemberKey != currentMember.memberKey && p.IsOnTheSameTeamAs(player1)); SetupMocksForLinkPlayerIdentity(player1, player2); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember.memberKey, currentMember.memberName)); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember.memberKey, currentMember.memberName)); } } @@ -507,7 +507,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit SetupMocksForLinkPlayerIdentity(player1, player2); var repo = CreateRepository(); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name")); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name")); } [Fact] @@ -518,7 +518,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_target_ SetupMocksForLinkPlayerIdentity(player1, player2); var repo = CreateRepository(); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name")); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name")); } [Fact] @@ -532,7 +532,7 @@ public async Task LinkPlayerIdentity_merges_players() var member = _testData.AnyMemberNotLinkedToPlayer(); var repo = CreateRepository(); - var movedIdentityResult = await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, member.memberKey, member.memberName); + var movedIdentityResult = await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, member.memberKey, member.memberName); await repo.ProcessAsyncUpdatesForPlayers(); Assert.Equal(player1.PlayerId, movedIdentityResult.PlayerIdForTargetPlayer); @@ -573,7 +573,7 @@ public async Task LinkPlayerIdentity_merges_players() } var movedIdentityLinkedBy = await connectionForAssert.QuerySingleAsync($"SELECT LinkedBy FROM {Tables.PlayerIdentity} WHERE PlayerIdentityId = @PlayerIdentityId", player2.PlayerIdentities[0]); - Assert.Equal(PlayerIdentityLinkedBy.ClubOrTeam.ToString(), movedIdentityLinkedBy); + Assert.Equal(PlayerIdentityLinkedBy.Team.ToString(), movedIdentityLinkedBy); var obsoletePlayerShouldBeRemoved = await connectionForAssert.QuerySingleOrDefaultAsync($"SELECT COUNT(PlayerId) FROM {Tables.Player} WHERE PlayerId = @PlayerId", player2); Assert.Equal(0, obsoletePlayerShouldBeRemoved); @@ -590,7 +590,7 @@ public async Task LinkPlayerIdentity_redirects_deleted_player_to_linked_player() var member = _testData.AnyMemberNotLinkedToPlayer(); var repo = CreateRepository(); - await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, member.memberKey, member.memberName).ConfigureAwait(false); + await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, member.memberKey, member.memberName).ConfigureAwait(false); VerifyPlayerIsRedirected(player1.PlayerRoute!, player2.PlayerRoute!); } @@ -606,7 +606,7 @@ public async Task LinkPlayerIdentity_audits_and_logs() var member = _testData.AnyMemberNotLinkedToPlayer(); var repo = CreateRepository(); - await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, member.memberKey, member.memberName).ConfigureAwait(false); + await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, member.memberKey, member.memberName).ConfigureAwait(false); // audits and logs delete of original player and update of target player _auditRepository.Verify(x => x.CreateAudit(It.Is(x => x.Action == AuditAction.Update && x.EntityUri!.ToString().EndsWith(player1.PlayerId.ToString()!)), It.IsAny()), Times.Once); diff --git a/Stoolball.Data.SqlServer.UnitTests/SqlServerPlayerRepositoryUnitTests.cs b/Stoolball.Data.SqlServer.UnitTests/SqlServerPlayerRepositoryUnitTests.cs index da194f77..ef23040b 100644 --- a/Stoolball.Data.SqlServer.UnitTests/SqlServerPlayerRepositoryUnitTests.cs +++ b/Stoolball.Data.SqlServer.UnitTests/SqlServerPlayerRepositoryUnitTests.cs @@ -140,7 +140,7 @@ public async Task LinkPlayerIdentity_throws_ArgumentNullException_if_memberName_ { var repo = CreateRepository(); - await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(Guid.NewGuid(), Guid.NewGuid(), PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), memberName)); + await Assert.ThrowsAsync(async () => await repo.LinkPlayerIdentity(Guid.NewGuid(), Guid.NewGuid(), PlayerIdentityLinkedBy.Team, Guid.NewGuid(), memberName)); } [Fact] diff --git a/Stoolball.Web.UnitTests/Statistics/LinkedPlayersForMemberSurfaceControllerTests.cs b/Stoolball.Web.UnitTests/Statistics/LinkedPlayersForMemberSurfaceControllerTests.cs index 1d115bb5..6234459c 100644 --- a/Stoolball.Web.UnitTests/Statistics/LinkedPlayersForMemberSurfaceControllerTests.cs +++ b/Stoolball.Web.UnitTests/Statistics/LinkedPlayersForMemberSurfaceControllerTests.cs @@ -95,7 +95,7 @@ public async Task Player_not_found_by_route_returns_NotFound() public async Task UnlinkPlayerIdentityFromMemberAccount_not_called_for_identity_not_linked_by_member() { var player = CreatePlayerWith4PlayerIdentities(); - player.PlayerIdentities[0].LinkedBy = PlayerIdentityLinkedBy.ClubOrTeam; + player.PlayerIdentities[0].LinkedBy = PlayerIdentityLinkedBy.Team; var memberKey = Guid.NewGuid(); var memberName = "Member name"; _memberManager.Setup(x => x.GetCurrentMemberAsync()).Returns(Task.FromResult(new MemberIdentityUser { Key = memberKey, Name = memberName })); diff --git a/Stoolball.Web/Statistics/Models/LinkedPlayersViewModel.cs b/Stoolball.Web/Statistics/Models/LinkedPlayersViewModel.cs index aed3078c..1dfffb04 100644 --- a/Stoolball.Web/Statistics/Models/LinkedPlayersViewModel.cs +++ b/Stoolball.Web/Statistics/Models/LinkedPlayersViewModel.cs @@ -20,11 +20,11 @@ public LinkedPlayersViewModel(IPublishedContent? contentModel = null, IUserServi public string LinkedByHeading { get; set; } = "Linked by"; public string LinkedByMemberLabel { get; set; } = PlayerIdentityLinkedBy.Member.ToString(); - public string LinkedByClubOrTeamLabel { get; set; } = PlayerIdentityLinkedBy.ClubOrTeam.ToString(); + public string LinkedByTeamLabel { get; set; } = PlayerIdentityLinkedBy.Team.ToString(); public string LinkedByStoolballEnglandLabel { get; set; } = PlayerIdentityLinkedBy.StoolballEngland.ToString(); public PlayerIdentityLinkedBy? CurrentMemberRole { get; set; } public bool CanUnlinkIdentitiesLinkedByMember { get; set; } - public bool CanUnlinkIdentitiesLinkedByClubOrTeam { get; set; } + public bool CanUnlinkIdentitiesLinkedByTeam { get; set; } public Guid? AddIdentitiesFromTeamId { get; set; } public bool CanRemoveFinalIdentity { get; set; } public bool ShowLinkedIdentityInTable { get; set; } = true; diff --git a/Stoolball.Web/Teams/LinkedPlayersForIdentityController.cs b/Stoolball.Web/Teams/LinkedPlayersForIdentityController.cs index da62ef2e..ff1e1826 100644 --- a/Stoolball.Web/Teams/LinkedPlayersForIdentityController.cs +++ b/Stoolball.Web/Teams/LinkedPlayersForIdentityController.cs @@ -63,7 +63,7 @@ public LinkedPlayersForIdentityController(ILogger UpdateLinkedPlayers(LinkedPlayersFormData formD var currentMember = await _memberManager.GetCurrentMemberAsync(); var isTeamOwner = await _memberManager.IsMemberAuthorizedAsync(null, [model.ContextIdentity.Team.MemberGroupName!], null); - var roleGrantingPermission = isTeamOwner ? PlayerIdentityLinkedBy.ClubOrTeam : PlayerIdentityLinkedBy.StoolballEngland; + var roleGrantingPermission = isTeamOwner ? PlayerIdentityLinkedBy.Team : PlayerIdentityLinkedBy.StoolballEngland; model.Player = await _playerDataSource.ReadPlayerByRoute(model.ContextIdentity.Player!.PlayerRoute!); @@ -86,7 +86,7 @@ public async Task UpdateLinkedPlayers(LinkedPlayersFormData formD var submittedIdentities = formData.PlayerIdentities.Select(id => id.PlayerIdentityId!.Value).ToList(); var identitiesToLink = submittedIdentities.Where(id => !previousIdentities.Contains(id)); var identitiesToKeep = submittedIdentities.Where(id => previousIdentities.Contains(id)).Union([model.ContextIdentity.PlayerIdentityId.Value]); - var identitiesToUnlink = model.Player!.PlayerIdentities.Where(id => id.LinkedBy == PlayerIdentityLinkedBy.ClubOrTeam && !identitiesToKeep.Contains(id.PlayerIdentityId!.Value)); + var identitiesToUnlink = model.Player!.PlayerIdentities.Where(id => id.LinkedBy == PlayerIdentityLinkedBy.Team && !identitiesToKeep.Contains(id.PlayerIdentityId!.Value)); var movedPlayerResults = new List(); foreach (var identity in identitiesToLink) diff --git a/Stoolball.Web/Views/LinkedPlayersForIdentity.cshtml b/Stoolball.Web/Views/LinkedPlayersForIdentity.cshtml index 164a85a3..c1e79511 100644 --- a/Stoolball.Web/Views/LinkedPlayersForIdentity.cshtml +++ b/Stoolball.Web/Views/LinkedPlayersForIdentity.cshtml @@ -9,10 +9,10 @@ } @{ Model.LinkedByMemberLabel = "Player"; - Model.LinkedByClubOrTeamLabel = "Club or team"; + Model.LinkedByTeamLabel = "Team"; Model.LinkedByStoolballEnglandLabel = "Stoolball England"; Model.AddIdentitiesFromTeamId = Model.ContextIdentity?.Team?.TeamId; - Model.CanUnlinkIdentitiesLinkedByClubOrTeam = true; + Model.CanUnlinkIdentitiesLinkedByTeam = true; Model.ShowLinkedIdentityInTable = false; } @await Html.PartialAsync("_JQueryValidate") diff --git a/Stoolball.Web/Views/LinkedPlayersForMember.cshtml b/Stoolball.Web/Views/LinkedPlayersForMember.cshtml index 8a412192..4a2496af 100644 --- a/Stoolball.Web/Views/LinkedPlayersForMember.cshtml +++ b/Stoolball.Web/Views/LinkedPlayersForMember.cshtml @@ -9,7 +9,7 @@ SmidgeHelper.RequiresCss(new CssFile("~/css/account.min.css") { Order = 100 }); Model.LinkedByHeading = "Added by"; Model.LinkedByMemberLabel = "You"; - Model.LinkedByClubOrTeamLabel = "Your team"; + Model.LinkedByTeamLabel = "Your team"; Model.LinkedByStoolballEnglandLabel = "Admins"; Model.CanUnlinkIdentitiesLinkedByMember = true; Model.CanRemoveFinalIdentity = true; diff --git a/Stoolball.Web/Views/Partials/_LinkedPlayers.cshtml b/Stoolball.Web/Views/Partials/_LinkedPlayers.cshtml index c2377734..753e347c 100644 --- a/Stoolball.Web/Views/Partials/_LinkedPlayers.cshtml +++ b/Stoolball.Web/Views/Partials/_LinkedPlayers.cshtml @@ -9,8 +9,8 @@ { case PlayerIdentityLinkedBy.Member: return Model.LinkedByMemberLabel; - case PlayerIdentityLinkedBy.ClubOrTeam: - return Model.LinkedByClubOrTeamLabel; + case PlayerIdentityLinkedBy.Team: + return Model.LinkedByTeamLabel; case PlayerIdentityLinkedBy.StoolballEngland: return Model.LinkedByStoolballEnglandLabel; } @@ -50,7 +50,7 @@