Skip to content

Commit

Permalink
Refactor tenant configuration (#103)
Browse files Browse the repository at this point in the history
* Add ISiteContext.Position for sort order of tenant lists (e.g. in navigation)
* Add rules for teams' home venue
   Default:
   TournamentContext.TeamRuleSet.HomeVenue.MustBeSet == true
* Update nuget packages for TournamentManager
  • Loading branch information
axunonb authored Aug 19, 2023
1 parent 0e9b9ef commit aab6132
Show file tree
Hide file tree
Showing 17 changed files with 1,156 additions and 988 deletions.
330 changes: 170 additions & 160 deletions League.Demo/Configuration/Tenant.Default.Development.config

Large diffs are not rendered by default.

329 changes: 169 additions & 160 deletions League.Demo/Configuration/Tenant.Default.Production.config

Large diffs are not rendered by default.

330 changes: 170 additions & 160 deletions League.Demo/Configuration/Tenant.OtherOrg.Development.config

Large diffs are not rendered by default.

329 changes: 169 additions & 160 deletions League.Demo/Configuration/Tenant.OtherOrg.Production.config

Large diffs are not rendered by default.

330 changes: 170 additions & 160 deletions League.Demo/Configuration/Tenant.TestOrg.Development.config

Large diffs are not rendered by default.

330 changes: 170 additions & 160 deletions League.Demo/Configuration/Tenant.TestOrg.Production.config

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions League.Demo/Seed/Insert-Initial-Data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Data for the 'dbo.IdentityRole' table (Records 1 - 2) */

SET IDENTITY_INSERT dbo.IdentityRole ON;
GO
INSERT INTO dbo.IdentityRole (Id, Name)
VALUES
(1, N'SystemManager'),
(2, N'TournamentManager')
GO
SET IDENTITY_INSERT dbo.IdentityRole OFF;
GO

/* Data for the 'dbo.MatchRule' table (Records 1 - 1) */

SET IDENTITY_INSERT dbo.MatchRule ON;
GO
INSERT INTO dbo.MatchRule (Id, Name, NumOfSets, BestOf, PointsMatchWon, PointsMatchLost, PointsMatchWonAfterTieBreak, PointsMatchLostAfterTieBreak, PointsMatchTie, RankComparer, CreatedOn, ModifiedOn)
VALUES
(1, N'3 sets to win, tie-break rule', 3, 1, 3, 0, 2, 1, 0, 1, GETDATE(), GETDATE())
SET IDENTITY_INSERT dbo.MatchRule OFF;
GO

/* Data for the 'dbo.SetRule' table (Records 1 - 1) */

SET IDENTITY_INSERT dbo.SetRule ON;
GO
INSERT INTO dbo.SetRule (Id, Name, NumOfPointsToWinRegular, NumOfPointsToWinTiebreak, PointsDiffToWinRegular, PointsDiffToWinTiebreak, PointsSetLost, PointsSetTie, PointsSetWon, MaxTimeouts, MaxSubstitutions, CreatedOn, ModifiedOn)
VALUES
(1, N'Indoor set rule', 25, 15, 2, 2, 0, 0, 1, 2, 6, GETDATE(), GETDATE()),
(1, N'Beach set rule', 21, 15, 2, 2, 0, 0, 1, 2, 0, GETDATE(), GETDATE())
GO
SET IDENTITY_INSERT dbo.SetRule OFF;
GO

/* Data for the 'dbo.RoundType' table (Records 1 - 1) */

SET IDENTITY_INSERT dbo.RoundType ON;
GO
INSERT INTO dbo.RoundType (Id, Name, Description, CreatedOn, ModifiedOn)
VALUES
(1, N'Female', N'Female teams', GETDATE(), GETDATE()),
(2, N'Male', N'Male teams', GETDATE(), GETDATE()),
(3, N'Mixed', N'Mixed teams', GETDATE(), GETDATE())
GO
SET IDENTITY_INSERT dbo.RoundType OFF;
GO


/* Data for the 'dbo.User' table (Records 1 - 1) */

SET IDENTITY_INSERT dbo.[User] ON;
GO
INSERT INTO dbo.[User] (Id, Guid, UserName, PasswordHash, Email, EmailConfirmedOn, PhoneNumber, PhoneNumberConfirmedOn, LastLoginOn, AccessFailedCount, LockoutEndDateUtc, Gender, Title, FirstName, MiddleName, LastName, Nickname, PhoneNumber2, Email2, Birthday, Remarks, CreatedOn, ModifiedOn)
VALUES
(1, N'49afc1e5-d439-40d7-bb13-ce994a825069', N'sysadmin', NULL, N'admin@axuno.net', '20230817', N'', NULL, NULL, 0, NULL, N'm', N'', N'admin', N'', N'admin', N'', N'', N'', NULL, NULL, '20230817', '20230817')
GO
SET IDENTITY_INSERT dbo.[User] OFF;
GO

/* Data for the 'dbo.IdentityUserRole' table (Records 1 - 1) */

SET IDENTITY_INSERT dbo.IdentityUserRole ON;
GO
INSERT INTO dbo.IdentityUserRole (Id, UserId, RoleId)
VALUES
(1, 1, 1)
GO
SET IDENTITY_INSERT dbo.IdentityUserRole OFF;
GO
1 change: 1 addition & 0 deletions League.Demo/Views/Home/Overview.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ViewData.Description(Localizer["Leagues using volleyball-league.demo"].Value);
var tenants = TenantStore.GetTenants().Values
.Where(tc => !string.IsNullOrEmpty(tc.Identifier) && !tc.SiteContext.HideInMenu && !tc.IsDefault)
.OrderBy(tc => tc.SiteContext.Position)
.ToList();
}
<div>
Expand Down
4 changes: 2 additions & 2 deletions League/ApiControllers/Cron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ private void QueueJobs(DateTime referenceDateUtc)
{
var smt = _sendMailTask.CreateNewInstance();

if (_tenantContext.SiteContext.MatchNotifications.DaysBeforeNextmatch != DoNotExecute)
if (_tenantContext.SiteContext.MatchNotifications.DaysBeforeNextMatch != DoNotExecute)
{
smt.SetMessageCreator(new AnnounceNextMatchCreator
{
Parameters =
{
CultureInfo = CultureInfo.DefaultThreadCurrentUICulture ?? CultureInfo.CurrentCulture,
ReferenceDateUtc =
referenceDateUtc.AddDays(_tenantContext.SiteContext.MatchNotifications.DaysBeforeNextmatch * -1),
referenceDateUtc.AddDays(_tenantContext.SiteContext.MatchNotifications.DaysBeforeNextMatch * -1),
IcsCalendarBaseUrl = TenantLink.ActionLink(nameof(Calendar), nameof(Match), null,
scheme: TenantLink.HttpContext.Request.Scheme) ?? string.Empty
}
Expand Down
2 changes: 1 addition & 1 deletion League/Components/MainNavigationComponentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class NavigationNode
/// </summary>
public string IconCssClass { get; set; } = string.Empty;
/// <summary>
/// The css class to use the menu entry.
/// The css class to use for the menu entry.
/// </summary>
public string CssClass { get; set; } = string.Empty;
/// <summary>
Expand Down
12 changes: 9 additions & 3 deletions League/Components/MainNavigationNodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ protected virtual async Task CreateStandardNavigationNodes()

leagues.ChildNodes.Add(new MainNavigationComponentModel.NavigationNode
{Text = Localizer["Home"], Url = "/welcome", Key = "League_Welcome"});

foreach (var tenant in TenantStore.GetTenants().Values)

leagues.ChildNodes.Add(new MainNavigationComponentModel.NavigationNode
{ Text = Localizer["League Overview"], Url = "/overview", Key = "League_Overview" });

leagues.ChildNodes.Add(new MainNavigationComponentModel.NavigationNode
{ Text = "Separator", Key = "League_Separator" });

foreach (var tenant in TenantStore.GetTenants().Values.OrderBy(t => t.SiteContext.Position))
{
if (!string.IsNullOrEmpty(tenant.Identifier) && !tenant.SiteContext.HideInMenu)
{
Expand All @@ -145,7 +151,7 @@ protected virtual async Task CreateStandardNavigationNodes()
});
}
}
leagues.ChildNodes.Add(new MainNavigationComponentModel.NavigationNode { Text = Localizer["League Overview"], Url = "/overview", Key = "LeagueOverview" });

#endregion

#region ** Team Infos **
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Node keys after "RightAlignSeparator" shall be aligned to the right margin of the navigation bar
if (node.Key.Equals("RightAlignSeparator", StringComparison.InvariantCultureIgnoreCase))
{
ViewData["dropdown-menu-end"] = " dropdown-menu-end"; // for dropdown in NavigationNodeChildDropdownPartial
ViewData["dropdown-menu-end"] = " dropdown-menu-end"; // for dropdown in NavigationNodeChildDropdownPartial: right align the dropdown menu
<li class="ms-md-auto"></li>
}

Expand Down
13 changes: 7 additions & 6 deletions League/Views/Shared/NavigationNodeChildDropdownPartial.cshtml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
@using League.Components
@model (League.Components.MainNavigationComponentModel MainNav, League.Components.MainNavigationComponentModel.NavigationNode Node)
@if (Model.MainNav != null && Model.Node.HasVisibleChildNodes())
@if (Model.Node.HasVisibleChildNodes())
{
<ul class="dropdown-menu shadow@(ViewData["dropdown-menu-end"])" style="margin-top: -0.3rem">
@foreach (var childNode in Model.Node.ChildNodes)
{
if (!childNode.ShouldShow())
if (childNode.Text == "Separator")
{
<li>
<hr class="dropdown-divider">
</li>
continue;
}

if (childNode.Text == "Separator")
if (!childNode.ShouldShow())
{
<li>
<span class="dropdown-divider"></span>
</li>
continue;
}

if (childNode.HasVisibleChildNodes())
{
<li>
Expand Down
11 changes: 7 additions & 4 deletions TournamentManager/TournamentManager/MultiTenancy/ISiteContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#nullable enable

namespace TournamentManager.MultiTenancy;
namespace TournamentManager.MultiTenancy;

public interface ISiteContext
{
Expand All @@ -9,6 +7,11 @@ public interface ISiteContext
/// </summary>
ITenant? Tenant { get; set; }

/// <summary>
/// Determines the position, for the <see cref="ITenant"/> within tenant lists (e.g. navigation).
/// </summary>
int Position { get; set; }

/// <summary>
/// The value of the Url segment used to identify the site. May be NULL or empty string.
/// </summary>
Expand Down Expand Up @@ -44,4 +47,4 @@ public interface ISiteContext
/// Notifications sent before and after matches.
/// </summary>
MatchNotifications MatchNotifications { get; set; }
}
}
17 changes: 11 additions & 6 deletions TournamentManager/TournamentManager/MultiTenancy/SiteContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
namespace TournamentManager.MultiTenancy;
namespace TournamentManager.MultiTenancy;

/// <summary>
/// Provides site-specific data.
Expand All @@ -12,6 +11,12 @@ public class SiteContext : ISiteContext
[YAXLib.Attributes.YAXDontSerialize]
public ITenant? Tenant { get; set; }

/// <summary>
/// Determines the position, for the <see cref="ITenant"/> within tenant lists (e.g. navigation).
/// </summary>
[YAXLib.Attributes.YAXComment("The position of the tenant within tenant lists (e.g. navigation).")]
public int Position { get; set; }

/// <summary>
/// The value of the Url segment used to identify the site. May be empty for the default tenant.
/// </summary>
Expand Down Expand Up @@ -60,12 +65,12 @@ public class Email
/// <summary>
/// "From" mailbox address for the contact form
/// </summary>
[YAXLib.Attributes.YAXComment("")]
[YAXLib.Attributes.YAXComment("\"From\" mailbox address for the contact form\"")]
public MailAddress ContactFrom { get; set; } = new();
/// <summary>
/// "To" mailbox address for the contact form
/// </summary>
[YAXLib.Attributes.YAXComment("\"From\" mailbox address for the contact form")]
[YAXLib.Attributes.YAXComment("\"To\" mailbox address for the contact form")]
public MailAddress ContactTo { get; set; } = new();
/// <summary>
/// General "To" mailbox address for emails generated programmatically
Expand Down Expand Up @@ -111,7 +116,7 @@ public class MatchNotifications
/// Number of days before the next match will be announced. 0 for none, negative number days.
/// </summary>
[YAXLib.Attributes.YAXComment("Number of days before the next match will be announced. 0 for none, negative number days.")]
public int DaysBeforeNextmatch { get; set; } = 0;
public int DaysBeforeNextMatch { get; set; } = 0;

/// <summary>
/// Number of days to remind 1st time for missing match results. 0 for none, positive number of days.
Expand All @@ -124,4 +129,4 @@ public class MatchNotifications
/// </summary>
[YAXLib.Attributes.YAXComment("Number of days to remind 2nd time for missing match results. 0 for none, positive number of days.")]
public int DaysForMatchResultReminder2 { get; set; } = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ public class TeamRules
/// <summary>
/// Rules for teams' home match time
/// </summary>
[YAXLib.Attributes.YAXComment("Rules for the HomeMatchTime of a team")]
public HomeMatchTime HomeMatchTime { get; set; } = new();

/// <summary>
/// Rules for the <see cref="HomeVenue"/> of a team.
/// </summary>
[YAXLib.Attributes.YAXComment("Rules for the HomeVenue of a team.")]
public HomeVenue HomeVenue { get; set; } = new();
}

/// <summary>
Expand Down Expand Up @@ -183,4 +190,21 @@ public class HomeMatchTime
/// </summary>
[YAXLib.Attributes.YAXComment("If true, entries not in 'DaysOfWeekRange' are errors (else: warning)")]
public bool ErrorIfNotInDaysOfWeekRange { get; set; } = false;
}
}

/// <summary>
/// Rules for the <see cref="HomeVenue"/> of a team.
/// </summary>
[YAXLib.Attributes.YAXComment("Rules for the HomeVenue of a team.")]
public class HomeVenue
{
/// <summary>
/// If <see langword="true"/>, the <see cref="HomeVenue"/> must be set, i.e. cannot be null/unspecified.
/// If <see langword="false"/>, when auto-creating fixtures the team will only have away-matches (is always the guest team).
/// </summary>
[YAXLib.Attributes.YAXComment("""
If true, the HomeVenue must be set, i.e. cannot be null/unspecified.
If false, when auto-creating fixtures the team will only have away-matches (i.e. is always the guest team).
""")]
public bool MustBeSet { get; set; } = true;
}
9 changes: 5 additions & 4 deletions TournamentManager/TournamentManager/TournamentManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Volleyball League is an open source sports platform that brings everything neces
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EPPlus" Version="6.2.6" />
<PackageReference Include="EPPlus" Version="6.2.8" />
<PackageReference Include="NLog" Version="5.2.3" />
<PackageReference Include="NuGetizer" Version="1.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -28,10 +29,10 @@ Volleyball League is an open source sports platform that brings everything neces
<PackageReference Include="OxyPlot.SkiaSharp" Version="2.1.2" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.16" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.2" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.18" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="YAXLib" Version="4.1.0" />
<PackageReference Include="YAXLib" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit aab6132

Please sign in to comment.