diff --git a/SharedLibraryCore/BaseController.cs b/SharedLibraryCore/BaseController.cs index 495b6d674..8a87e856e 100644 --- a/SharedLibraryCore/BaseController.cs +++ b/SharedLibraryCore/BaseController.cs @@ -12,6 +12,7 @@ using System.Security.Claims; using System.Threading.Tasks; using Data.Context; using Data.Models; +using SharedLibraryCore.Configuration; namespace SharedLibraryCore { @@ -31,22 +32,21 @@ namespace SharedLibraryCore private static string SocialLink; private static string SocialTitle; protected List Pages; + protected ApplicationConfiguration AppConfig { get; } public BaseController(IManager manager) { Manager = manager; + Localization ??= Utilities.CurrentLocalization.LocalizationIndex; + AppConfig = Manager.GetApplicationSettings().Configuration(); - if (Localization == null) + if (AppConfig.EnableSocialLink && SocialLink == null) { - Localization = Utilities.CurrentLocalization.LocalizationIndex; - } - - if (Manager.GetApplicationSettings().Configuration().EnableSocialLink && SocialLink == null) - { - SocialLink = Manager.GetApplicationSettings().Configuration().SocialLinkAddress; - SocialTitle = Manager.GetApplicationSettings().Configuration().SocialLinkTitle; + SocialLink = AppConfig.SocialLinkAddress; + SocialTitle = AppConfig.SocialLinkTitle; } + Pages = Manager.GetPageList().Pages .Select(page => new Page { @@ -56,7 +56,7 @@ namespace SharedLibraryCore ViewBag.Version = Manager.Version; ViewBag.IsFluid = false; - ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes; + ViewBag.EnableColorCodes = AppConfig.EnableColorCodes; ViewBag.Language = Utilities.CurrentLocalization.Culture.TwoLetterISOLanguageName; Client ??= new EFClient() @@ -126,11 +126,13 @@ namespace SharedLibraryCore SignInAsync(new ClaimsPrincipal(claimsIdentity)).Wait(); } - var communityName = Manager.GetApplicationSettings().Configuration().CommunityInformation?.Name; - var shouldUseCommunityName = !string.IsNullOrWhiteSpace(communityName) && !communityName.Contains("IW4MAdmin"); + var communityName = AppConfig.CommunityInformation?.Name; + var shouldUseCommunityName = !string.IsNullOrWhiteSpace(communityName) + && !communityName.Contains("IW4MAdmin") + && AppConfig.CommunityInformation.IsEnabled; ViewBag.Authorized = Authorized; - ViewBag.Url = Manager.GetApplicationSettings().Configuration().WebfrontUrl; + ViewBag.Url = AppConfig.WebfrontUrl; ViewBag.User = Client; ViewBag.Version = Manager.Version; ViewBag.SocialLink = SocialLink ?? ""; @@ -139,9 +141,10 @@ namespace SharedLibraryCore ViewBag.Localization = Utilities.CurrentLocalization.LocalizationIndex; ViewBag.CustomBranding = shouldUseCommunityName ? communityName - : Manager.GetApplicationSettings().Configuration().WebfrontCustomBranding ?? "IW4MAdmin"; - ViewBag.EnableColorCodes = Manager.GetApplicationSettings().Configuration().EnableColorCodes; - ViewBag.EnablePrivilegedUserPrivacy = Manager.GetApplicationSettings().Configuration().EnablePrivilegedUserPrivacy; + : AppConfig.WebfrontCustomBranding ?? "IW4MAdmin"; + ViewBag.EnableColorCodes = AppConfig.EnableColorCodes; + ViewBag.EnablePrivilegedUserPrivacy = AppConfig.EnablePrivilegedUserPrivacy; + ViewBag.Configuration = AppConfig; base.OnActionExecuting(context); } diff --git a/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs b/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs index 71fca4cc7..f546d0395 100644 --- a/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs +++ b/SharedLibraryCore/Configuration/CommunityInformationConfiguration.cs @@ -1,4 +1,6 @@ -namespace SharedLibraryCore.Configuration +using System.Linq; + +namespace SharedLibraryCore.Configuration { public class CommunityInformationConfiguration { @@ -28,6 +30,8 @@ IconUrl = "https://raw.githubusercontent.com/edent/SuperTinyIcons/master/images/svg/youtube.svg" } }; + + public bool IsEnabled { get; set; } } public class SocialAccountConfiguration diff --git a/WebfrontCore/Extensions/WebfrontExtensions.cs b/WebfrontCore/Extensions/WebfrontExtensions.cs index 8c55aea9f..ec5807e88 100644 --- a/WebfrontCore/Extensions/WebfrontExtensions.cs +++ b/WebfrontCore/Extensions/WebfrontExtensions.cs @@ -5,6 +5,7 @@ namespace WebfrontCore.Extensions public static class WebfrontExtensions { public static bool ShouldUseFallbackBranding(this ApplicationConfiguration appConfig) => - string.IsNullOrWhiteSpace(appConfig?.CommunityInformation?.Name) || appConfig.CommunityInformation.Name.Contains("IW4MAdmin"); + string.IsNullOrWhiteSpace(appConfig?.CommunityInformation?.Name) || + appConfig.CommunityInformation.Name.Contains("IW4MAdmin") || !appConfig.CommunityInformation.IsEnabled; } } \ No newline at end of file diff --git a/WebfrontCore/Views/About/Index.cshtml b/WebfrontCore/Views/About/Index.cshtml index 37d075048..eb8c41b83 100644 --- a/WebfrontCore/Views/About/Index.cshtml +++ b/WebfrontCore/Views/About/Index.cshtml @@ -1,6 +1,12 @@ -@model WebfrontCore.ViewModels.CommunityInfo +@using SharedLibraryCore.Configuration +@model WebfrontCore.ViewModels.CommunityInfo @{ - var allRules = Model.ServerRules.Prepend(new KeyValuePair(ViewBag.Localization["WEBFRONT_ABOUT_GLOBAL_RULES"], Model.GlobalRules)); + IEnumerable> allRules = new []{new KeyValuePair(ViewBag.Localization["WEBFRONT_ABOUT_GLOBAL_RULES"], Model.GlobalRules)}; + var serverRules = Model.ServerRules?.Where(server => server.Value != null && server.Value.Any()).ToList(); + if (serverRules?.Any() ?? false) + { + allRules = allRules.Union(serverRules); + } }
@@ -22,7 +28,7 @@

@ViewBag.Localization["WEBFRONT_ABOUT_TITLE"]

- @foreach (var social in Model.CommunityInformation.SocialAccounts) + @foreach (var social in Model.CommunityInformation.SocialAccounts ?? new SocialAccountConfiguration[0]) { } -

@ViewBag.Localization["WEBFRONT_ABOUT_COMMUNITY_GUIDELINES"]

+ @if (allRules.Any(rule => rule.Value.Any())) + { +

@ViewBag.Localization["WEBFRONT_ABOUT_COMMUNITY_GUIDELINES"]

+ } @foreach (var (serverName, rules) in allRules) { - if (rules?.Length == 0) + if (!rules.Any()) { continue; } diff --git a/WebfrontCore/Views/Shared/_Layout.cshtml b/WebfrontCore/Views/Shared/_Layout.cshtml index fe57c7ed1..b249b59e5 100644 --- a/WebfrontCore/Views/Shared/_Layout.cshtml +++ b/WebfrontCore/Views/Shared/_Layout.cshtml @@ -37,8 +37,11 @@ - - + @if (ViewBag.Configuration.CommunityInformation.IsEnabled) + { + + + }