From d4df601fe41c4cb5d14cf662ff3776bb5fa1c7f3 Mon Sep 17 00:00:00 2001 From: Simon Schulze Date: Sun, 30 Apr 2023 17:41:25 +0200 Subject: [PATCH 1/2] Add owner role Adjust tests for new role and recursive implicit role checking --- src/iRLeagueApiCore.Common/LeagueRoleValue.cs | 4 +++- src/iRLeagueApiCore.Common/LeagueRoles.cs | 9 ++++++++- .../iRLeagueApiCore.Common.csproj | 2 +- .../LeagueRolesTests.cs | 20 +++++++++++-------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/iRLeagueApiCore.Common/LeagueRoleValue.cs b/src/iRLeagueApiCore.Common/LeagueRoleValue.cs index 97da10c..baf5026 100644 --- a/src/iRLeagueApiCore.Common/LeagueRoleValue.cs +++ b/src/iRLeagueApiCore.Common/LeagueRoleValue.cs @@ -14,7 +14,9 @@ internal LeagueRoleValue(string value) internal LeagueRoleValue(string value, IEnumerable implicitRoles) { this.value = value; - this.implicitRoles = implicitRoles.ToArray(); + this.implicitRoles = implicitRoles + .SelectMany(x => new[] { x }.Concat(x.GetImplicitRoles())) + .ToArray(); } public static implicit operator string(LeagueRoleValue role) => role.value; diff --git a/src/iRLeagueApiCore.Common/LeagueRoles.cs b/src/iRLeagueApiCore.Common/LeagueRoles.cs index 33485fd..480be09 100644 --- a/src/iRLeagueApiCore.Common/LeagueRoles.cs +++ b/src/iRLeagueApiCore.Common/LeagueRoles.cs @@ -27,13 +27,20 @@ public static class LeagueRoles /// Administrator of the league with full privileges /// public const string Admin = "Admin"; - public static LeagueRoleValue AdminValue { get; } = new(Admin, new[] { OrganizerValue, StewardValue, MemberValue }); + public static LeagueRoleValue AdminValue { get; } = new(Admin, new[] { OrganizerValue, StewardValue }); + /// + /// Owner of the league + /// Full privilige including right to delete + /// + public const string Owner = "Owner"; + public static LeagueRoleValue OwnerValue { get; } = new(Owner, new[] { AdminValue }); /// /// Array of all available league roles /// public static LeagueRoleValue[] RolesAvailable { get; } = new[] { + OwnerValue, AdminValue, OrganizerValue, StewardValue, diff --git a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj index 316c5d8..bdc9f43 100644 --- a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj +++ b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj @@ -18,7 +18,7 @@ Library net6.0 iRLeagueApiCore.Common - 0.6.1 + 0.6.2-dev.1 Simon Schulze Simon Schulze enable diff --git a/test/iRLeagueApiCore.Common.Tests/LeagueRolesTests.cs b/test/iRLeagueApiCore.Common.Tests/LeagueRolesTests.cs index 82e4004..552e6d7 100644 --- a/test/iRLeagueApiCore.Common.Tests/LeagueRolesTests.cs +++ b/test/iRLeagueApiCore.Common.Tests/LeagueRolesTests.cs @@ -3,11 +3,13 @@ namespace iRLeagueApiCore.Common.Tests; public class LeagueRolesTests { [Theory] - [InlineData("Admin", true, true, true, true)] - [InlineData("Organizer", false, true, false, true)] - [InlineData("Steward", false, false, true, true)] - [InlineData("Member", false, false, false, true)] + [InlineData(LeagueRoles.Owner, true, true, true, true, true)] + [InlineData(LeagueRoles.Admin, false, true, true, true, true)] + [InlineData(LeagueRoles.Organizer, false, false, true, false, true)] + [InlineData(LeagueRoles.Steward, false, false, false, true, true)] + [InlineData(LeagueRoles.Member, false, false, false, false, true)] public void ShouldHaveRoles(string roleName, + bool owner, bool admin, bool organizer, bool steward, @@ -17,6 +19,7 @@ public void ShouldHaveRoles(string roleName, var role = LeagueRoles.GetRoleValue(roleName); var roles = new[] { role }; + LeagueRoles.CheckRole(LeagueRoles.OwnerValue, roles).Should().Be(owner); LeagueRoles.CheckRole(LeagueRoles.AdminValue, roles).Should().Be(admin); LeagueRoles.CheckRole(LeagueRoles.OrganizerValue, roles).Should().Be(organizer); LeagueRoles.CheckRole(LeagueRoles.StewardValue, roles).Should().Be(steward); @@ -24,10 +27,11 @@ public void ShouldHaveRoles(string roleName, } [Theory] - [InlineData("Admin", new string[0])] - [InlineData("Organizer", new[] { "Admin" })] - [InlineData("Steward", new[] { "Admin" })] - [InlineData("Member", new[] { "Admin", "Organizer", "Steward" })] + [InlineData(LeagueRoles.Owner, new string[0])] + [InlineData(LeagueRoles.Admin, new[] { LeagueRoles.Owner })] + [InlineData(LeagueRoles.Organizer, new[] { LeagueRoles.Owner, LeagueRoles.Admin })] + [InlineData(LeagueRoles.Steward, new[] { LeagueRoles.Owner, LeagueRoles.Admin })] + [InlineData(LeagueRoles.Member, new[] { LeagueRoles.Owner, LeagueRoles.Admin, LeagueRoles.Organizer, LeagueRoles.Steward })] public void ShouldBeImplicitOf(string roleName, string[] implicitOfRoleNames) { // Setup From b8b7db9f37ff79c40002ea3d6459d2a7b307b090 Mon Sep 17 00:00:00 2001 From: Simon Schulze Date: Thu, 4 May 2023 07:59:02 +0200 Subject: [PATCH 2/2] bump version to 0.6.2 --- src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj index bdc9f43..f9569a1 100644 --- a/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj +++ b/src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj @@ -18,7 +18,7 @@ Library net6.0 iRLeagueApiCore.Common - 0.6.2-dev.1 + 0.6.2 Simon Schulze Simon Schulze enable