Skip to content

Commit

Permalink
Change ClubOrTeam to Team because team, not club, permissions will be…
Browse files Browse the repository at this point in the history
… required #627
  • Loading branch information
sussexrick committed Oct 11, 2024
1 parent 0e7dd60 commit 5f7d3ca
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit
SetupMocksForLinkPlayerIdentity(player, player);

var repo = CreateRepository();
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player.PlayerId!.Value, player.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name"));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player.PlayerId!.Value, player.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name"));
}

[Fact]
Expand All @@ -441,7 +441,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_both_pl
SetupMocksForLinkPlayerIdentity(player1, player2);

var repo = CreateRepository();
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name"));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name"));
}

[Theory]
Expand All @@ -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
Expand All @@ -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<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember.memberKey, currentMember.memberName));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember.memberKey, currentMember.memberName));
}
}

Expand All @@ -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
Expand All @@ -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<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, currentMember.memberKey, currentMember.memberName));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, currentMember.memberKey, currentMember.memberName));
}
}

Expand All @@ -507,7 +507,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_identit
SetupMocksForLinkPlayerIdentity(player1, player2);

var repo = CreateRepository();
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name"));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name"));
}

[Fact]
Expand All @@ -518,7 +518,7 @@ public async Task LinkPlayerIdentity_throws_InvalidOperationException_if_target_
SetupMocksForLinkPlayerIdentity(player1, player2);

var repo = CreateRepository();
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), "Member name"));
await Assert.ThrowsAsync<InvalidOperationException>(async () => await repo.LinkPlayerIdentity(player1.PlayerId!.Value, player2.PlayerIdentities[0].PlayerIdentityId!.Value, PlayerIdentityLinkedBy.Team, Guid.NewGuid(), "Member name"));
}

[Fact]
Expand All @@ -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);
Expand Down Expand Up @@ -573,7 +573,7 @@ public async Task LinkPlayerIdentity_merges_players()
}

var movedIdentityLinkedBy = await connectionForAssert.QuerySingleAsync<string>($"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<int>($"SELECT COUNT(PlayerId) FROM {Tables.Player} WHERE PlayerId = @PlayerId", player2);
Assert.Equal(0, obsoletePlayerShouldBeRemoved);
Expand All @@ -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!);
}
Expand All @@ -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<AuditRecord>(x => x.Action == AuditAction.Update && x.EntityUri!.ToString().EndsWith(player1.PlayerId.ToString()!)), It.IsAny<IDbTransaction>()), Times.Once);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public async Task LinkPlayerIdentity_throws_ArgumentNullException_if_memberName_
{
var repo = CreateRepository();

await Assert.ThrowsAsync<ArgumentNullException>(async () => await repo.LinkPlayerIdentity(Guid.NewGuid(), Guid.NewGuid(), PlayerIdentityLinkedBy.ClubOrTeam, Guid.NewGuid(), memberName));
await Assert.ThrowsAsync<ArgumentNullException>(async () => await repo.LinkPlayerIdentity(Guid.NewGuid(), Guid.NewGuid(), PlayerIdentityLinkedBy.Team, Guid.NewGuid(), memberName));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
4 changes: 2 additions & 2 deletions Stoolball.Web/Statistics/Models/LinkedPlayersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Stoolball.Web/Teams/LinkedPlayersForIdentityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LinkedPlayersForIdentityController(ILogger<LinkedPlayersForIdentityContro

model.Authorization.CurrentMemberIsAuthorized = await _authorizationPolicy.IsAuthorized(model.ContextIdentity.Team);
var isTeamOwner = await _memberManager.IsMemberAuthorizedAsync(null, [model.ContextIdentity.Team.MemberGroupName!], null);
model.CurrentMemberRole = isTeamOwner ? PlayerIdentityLinkedBy.ClubOrTeam : PlayerIdentityLinkedBy.StoolballEngland;
model.CurrentMemberRole = isTeamOwner ? PlayerIdentityLinkedBy.Team : PlayerIdentityLinkedBy.StoolballEngland;

model.Metadata.PageTitle = $"Link {model.ContextIdentity.PlayerIdentityName} to the same player listed under another name";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public async Task<IActionResult> 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!);

var previousIdentities = model.Player!.PlayerIdentities.Select(id => id.PlayerIdentityId!.Value).ToList();
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<MovedPlayerIdentity>();
foreach (var identity in identitiesToLink)
Expand Down
4 changes: 2 additions & 2 deletions Stoolball.Web/Views/LinkedPlayersForIdentity.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion Stoolball.Web/Views/LinkedPlayersForMember.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Stoolball.Web/Views/Partials/_LinkedPlayers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -50,7 +50,7 @@
<div class="related-item__animate">
@Html.Hidden($"PlayerIdentities[{i}].PlayerIdentityId", identitiesToShow[i].PlayerIdentityId, new { @class = "related-item__data related-item__id", data_item = identitiesToShow[i].PlayerIdentityId })
@if ((identitiesToShow[i].LinkedBy == PlayerIdentityLinkedBy.Member && Model.CanUnlinkIdentitiesLinkedByMember) ||
(identitiesToShow[i].LinkedBy == PlayerIdentityLinkedBy.ClubOrTeam && Model.CanUnlinkIdentitiesLinkedByClubOrTeam))
(identitiesToShow[i].LinkedBy == PlayerIdentityLinkedBy.Team && Model.CanUnlinkIdentitiesLinkedByTeam))
{
<button type="button" class="btn-delete-icon">@await Html.PartialAsync("_DeleteIcon", $"Unlink {identitiesToShow[i].PlayerIdentityName} from your account")</button>
}
Expand Down
2 changes: 1 addition & 1 deletion Stoolball/Statistics/PlayerIdentityLinkedBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum PlayerIdentityLinkedBy
{
DefaultIdentity,
Member,
ClubOrTeam,
Team,
StoolballEngland
}
}

0 comments on commit 5f7d3ca

Please sign in to comment.