diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml b/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml index c4217dbf..f816e318 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml +++ b/OurUmbraco.Site/Views/MacroPartials/Forum/Forum.cshtml @@ -17,7 +17,7 @@ bool.TryParse(Request["noreplies"], out noreplies); var cat = -1; - if (CurrentPage.Level > 3) + if (CurrentPage.Level > 2) { cat = CurrentPage.Id; } @@ -47,9 +47,9 @@ var pages = (totalTopics / pageSize) + 1; - var categories = CurrentPage.AncestorOrSelf(2); + var categories = Model.Content.AncestorOrSelf(2); } -@if (Model.Content.NewTopicsAllowed() == false) +@if (Model.Content.NewTopicsAllowed() == false || Model.Content.AncestorOrSelfIsArchived()) { var notification = Model.Content.GetPropertyValue("mainNotification"); if (string.IsNullOrWhiteSpace(notification)) @@ -84,17 +84,17 @@ { foreach (var tag in CurrentPage.Parent.Children) { - + } } else { - foreach (var main in categories.Children) + foreach (var tag in categories.Children) { - foreach (var tag in main.Children) + if (tag.ContentType.Alias == "Forum" && tag.IsArchived() == false) { - + } } } diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml b/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml index f4016140..2788aeb4 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml +++ b/OurUmbraco.Site/Views/MacroPartials/Forum/ForumActions.cshtml @@ -4,7 +4,7 @@
@if (Members.IsLoggedIn()) { - if (Model.Content.NewTopicsAllowed()) + if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed()) { Create new diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/Thread.cshtml b/OurUmbraco.Site/Views/MacroPartials/Forum/Thread.cshtml index 6bc36db6..70726877 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/Thread.cshtml +++ b/OurUmbraco.Site/Views/MacroPartials/Forum/Thread.cshtml @@ -52,7 +52,7 @@ @if (topic != null) { - if (Model.Content.NewTopicsAllowed() == false) + if (Model.Content.AncestorOrSelfIsArchived() || Model.Content.NewTopicsAllowed() == false) {
@Html.Raw(notification) @@ -83,7 +83,7 @@ if (Members.IsLoggedIn()) { - if (Model.Content.NewTopicsAllowed()) + if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed()) {
 Reply to topic diff --git a/OurUmbraco.Site/Views/MacroPartials/Forum/TopicForm.cshtml b/OurUmbraco.Site/Views/MacroPartials/Forum/TopicForm.cshtml index 1bf72ef8..9d1cd0a7 100644 --- a/OurUmbraco.Site/Views/MacroPartials/Forum/TopicForm.cshtml +++ b/OurUmbraco.Site/Views/MacroPartials/Forum/TopicForm.cshtml @@ -20,15 +20,9 @@
diff --git a/OurUmbraco/Forum/Extensions/ForumExtensions.cs b/OurUmbraco/Forum/Extensions/ForumExtensions.cs index cb8b4833..0dcf55ad 100644 --- a/OurUmbraco/Forum/Extensions/ForumExtensions.cs +++ b/OurUmbraco/Forum/Extensions/ForumExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.Security; @@ -158,10 +159,10 @@ namespace OurUmbraco.Forum.Extensions { var roles = Roles.GetRolesForUser(member.GetPropertyValue("UserName")); var memberRoles = new List(); - + foreach (var role in roles) { - if(role == "standard" || role.StartsWith("201") || role.ToLowerInvariant().Contains("vendor".ToLowerInvariant()) || role.ToLowerInvariant().Contains("wiki".ToLowerInvariant()) || role.ToLowerInvariant().Contains("potentialspam".ToLowerInvariant()) || role.ToLowerInvariant().Contains("newaccount".ToLowerInvariant())) + if (role == "standard" || role.StartsWith("201") || role.ToLowerInvariant().Contains("vendor".ToLowerInvariant()) || role.ToLowerInvariant().Contains("wiki".ToLowerInvariant()) || role.ToLowerInvariant().Contains("potentialspam".ToLowerInvariant()) || role.ToLowerInvariant().Contains("newaccount".ToLowerInvariant())) continue; if (role == "CoreContrib") @@ -178,7 +179,33 @@ namespace OurUmbraco.Forum.Extensions public static bool NewTopicsAllowed(this IPublishedContent forum) { - return forum.Level <= 3 || forum.GetPropertyValue("forumAllowNewTopics"); + return forum.GetPropertyValue("forumAllowNewTopics"); + } + + public static bool IsArchived(this IPublishedContent forum) + { + const string archivedProperty = "archived"; + return forum.HasProperty(archivedProperty) && forum.GetPropertyValue(archivedProperty); + } + + public static bool AncestorOrSelfIsArchived(this IPublishedContent forum) + { + const string archivedProperty = "archived"; + if (forum.GetPropertyValue(archivedProperty)) + return true; + + return GetBoolValueRecursive(forum, "Forum", archivedProperty); + } + + private static bool GetBoolValueRecursive(IPublishedContent content, string contentTypeAlias, string propertyAlias) + { + if (content.Parent.ContentType.Alias != contentTypeAlias) + return false; + + if (content.Parent.GetPropertyValue(propertyAlias)) + return true; + + return GetBoolValueRecursive(content.Parent, contentTypeAlias, propertyAlias); } } } diff --git a/OurUmbraco/Our/MigrationsHandler.cs b/OurUmbraco/Our/MigrationsHandler.cs index 243c3fbf..23290ec8 100644 --- a/OurUmbraco/Our/MigrationsHandler.cs +++ b/OurUmbraco/Our/MigrationsHandler.cs @@ -24,6 +24,7 @@ namespace OurUmbraco.Our CommunityHome(); OverrideYouTrack(); UaaSProjectCheckbox(); + ForumArchivedCheckbox(); } private void EnsureMigrationsMarkerPathExists() @@ -238,5 +239,35 @@ namespace OurUmbraco.Our LogHelper.Error(string.Format("Migration: '{0}' failed", migrationName), ex); } } + + private void ForumArchivedCheckbox() + { + var migrationName = MethodBase.GetCurrentMethod().Name; + + try + { + var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt"); + if (File.Exists(path)) + return; + + var contentTypeService = UmbracoContext.Current.Application.Services.ContentTypeService; + var projectContentType = contentTypeService.GetContentType("Forum"); + var propertyTypeAlias = "archived"; + if (projectContentType.PropertyTypeExists(propertyTypeAlias) == false) + { + var checkbox = new DataTypeDefinition("Umbraco.TrueFalse"); + var checkboxPropertyType = new PropertyType(checkbox, propertyTypeAlias) { Name = "Archived" }; + projectContentType.AddPropertyType(checkboxPropertyType, "Forum Information"); + contentTypeService.Save(projectContentType); + } + + string[] lines = { "" }; + File.WriteAllLines(path, lines); + } + catch (Exception ex) + { + LogHelper.Error(string.Format("Migration: '{0}' failed", migrationName), ex); + } + } } }