Categories update and simplification

This commit is contained in:
Sebastiaan Janssen
2016-03-13 13:02:00 +01:00
parent 602c524f70
commit ef8e1cd45c
6 changed files with 73 additions and 21 deletions
@@ -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<string>("mainNotification");
if (string.IsNullOrWhiteSpace(notification))
@@ -84,17 +84,17 @@
{
foreach (var tag in CurrentPage.Parent.Children)
{
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Parent.Name - @tag.Name</option>
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option>
}
}
else
{
<option class="all" value="@categories.Id">All categories</option>
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)
{
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Parent.Name - @tag.Name</option>
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Name</option>
}
}
}
@@ -4,7 +4,7 @@
<div class="utility-actions">
@if (Members.IsLoggedIn())
{
if (Model.Content.NewTopicsAllowed())
if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed())
{
<a href="#" class="button create-new-thread" data-controller="topic">
<i class="icon-Add"></i><span>Create new</span>
@@ -52,7 +52,7 @@
<!-- FLAG SPAM END -->
@if (topic != null)
{
if (Model.Content.NewTopicsAllowed() == false)
if (Model.Content.AncestorOrSelfIsArchived() || Model.Content.NewTopicsAllowed() == false)
{
<div class="alertbar__yellow" style="margin-bottom: 10px;">
@Html.Raw(notification)
@@ -83,7 +83,7 @@
if (Members.IsLoggedIn())
{
if (Model.Content.NewTopicsAllowed())
if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed())
{
<div class="replybutton">
<a href="#" class="button green large reply forum-reply" data-author="@topic.AuthorName" data-topic="@topic.Id" data-controller="comment"><i class="icon-Reply-arrow"></i>&nbsp;Reply to topic</a>
@@ -20,15 +20,9 @@
<div class="col-sm-3 col-xs-6">
<select name="topic-category" id="topic-category" class="markdown-control">
<option value="" selected="" disabled="">Choose a category</option>
@foreach (var main in Model.Content.AncestorOrSelf(2).Children)
@foreach (var cat in Model.Content.AncestorOrSelf(2).Children.Where(m => m.NewTopicsAllowed()))
{
foreach (var cat in main.Children)
{
if (cat.NewTopicsAllowed())
{
<option class="@cat.Name.ToLower().Replace(" ", "")" value="@cat.Id">@cat.Parent.Name - @cat.Name</option>
}
}
<option class="@cat.Name.ToLower().Replace(" ", "")" value="@cat.Id">@cat.Name</option>
}
</select>
</div>
+30 -3
View File
@@ -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<string>("UserName"));
var memberRoles = new List<string>();
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<bool>("forumAllowNewTopics");
return forum.GetPropertyValue<bool>("forumAllowNewTopics");
}
public static bool IsArchived(this IPublishedContent forum)
{
const string archivedProperty = "archived";
return forum.HasProperty(archivedProperty) && forum.GetPropertyValue<bool>(archivedProperty);
}
public static bool AncestorOrSelfIsArchived(this IPublishedContent forum)
{
const string archivedProperty = "archived";
if (forum.GetPropertyValue<bool>(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<bool>(propertyAlias))
return true;
return GetBoolValueRecursive(content.Parent, contentTypeAlias, propertyAlias);
}
}
}
+31
View File
@@ -24,6 +24,7 @@ namespace OurUmbraco.Our
CommunityHome();
OverrideYouTrack();
UaaSProjectCheckbox();
ForumArchivedCheckbox();
}
private void EnsureMigrationsMarkerPathExists()
@@ -238,5 +239,35 @@ namespace OurUmbraco.Our
LogHelper.Error<MigrationsHandler>(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<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
}
}
}
}