Merge remote-tracking branch 'origin/temp8' into temp8-nuget-pkgs

This commit is contained in:
Stephan
2018-09-06 13:57:34 +02:00
91 changed files with 1727 additions and 191 deletions

View File

@@ -194,7 +194,7 @@ namespace Umbraco.Web.Editors
: Request.CreateNotificationValidationErrorResponse(result.Exception.Message);
}
public CreatedContentTypeCollectionResult PostCreateCollection(int parentId, string collectionName, string collectionItemName, string collectionIcon, string collectionItemIcon)
public CreatedContentTypeCollectionResult PostCreateCollection(int parentId, string collectionName, bool collectionCreateTemplate, string collectionItemName, bool collectionItemCreateTemplate, string collectionIcon, string collectionItemIcon)
{
var storeInContainer = false;
var allowUnderDocType = -1;
@@ -213,20 +213,38 @@ namespace Umbraco.Web.Editors
// create item doctype
var itemDocType = new ContentType(parentId);
itemDocType.Name = collectionItemName;
itemDocType.Alias = collectionItemName.ToSafeAlias();
itemDocType.Alias = collectionItemName.ToSafeAlias(true);
itemDocType.Icon = collectionItemIcon;
// create item doctype template
if (collectionItemCreateTemplate)
{
var template = CreateTemplateForContentType(itemDocType.Alias, itemDocType.Name);
itemDocType.SetDefaultTemplate(template);
}
// save item doctype
Services.ContentTypeService.Save(itemDocType);
// create collection doctype
var collectionDocType = new ContentType(parentId);
collectionDocType.Name = collectionName;
collectionDocType.Alias = collectionName.ToSafeAlias();
collectionDocType.Alias = collectionName.ToSafeAlias(true);
collectionDocType.Icon = collectionIcon;
collectionDocType.IsContainer = true;
collectionDocType.AllowedContentTypes = new List<ContentTypeSort>()
{
new ContentTypeSort(itemDocType.Id, 0)
};
// create collection doctype template
if (collectionCreateTemplate)
{
var template = CreateTemplateForContentType(collectionDocType.Alias, collectionDocType.Name);
collectionDocType.SetDefaultTemplate(template);
}
// save collection doctype
Services.ContentTypeService.Save(collectionDocType);
// test if the parent id exist and then allow the collection underneath
@@ -272,16 +290,7 @@ namespace Umbraco.Web.Editors
//create a default template if it doesnt exist -but only if default template is == to the content type
if (ctSave.DefaultTemplate.IsNullOrWhiteSpace() == false && ctSave.DefaultTemplate == ctSave.Alias)
{
var template = Services.FileService.GetTemplate(ctSave.Alias);
if (template == null)
{
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
if (tryCreateTemplate == false)
{
Logger.Warn<ContentTypeController>("Could not create a template for the Content Type: {ContentTypeAlias}, status: {CreateTemplateResult}", ctSave.Alias, tryCreateTemplate.Result.Result);
}
template = tryCreateTemplate.Result.Entity;
}
var template = CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
// If the alias has been manually updated before the first save,
// make sure to also update the first allowed template, as the
@@ -311,6 +320,26 @@ namespace Umbraco.Web.Editors
return display;
}
private ITemplate CreateTemplateForContentType(string contentTypeAlias, string contentTypeName)
{
var template = Services.FileService.GetTemplate(contentTypeAlias);
if (template == null)
{
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(contentTypeAlias, contentTypeName);
if (tryCreateTemplate == false)
{
Logger.Warn<ContentTypeController>(
"Could not create a template for the Content Type: {0}, status: {1}",
() => contentTypeAlias,
() => tryCreateTemplate.Result.StatusType);
}
template = tryCreateTemplate.Result.Entity;
}
return template;
}
/// <summary>
/// Returns an empty content type for use as a scaffold when creating a new type
/// </summary>

View File

@@ -206,9 +206,9 @@ namespace Umbraco.Web.Editors
// works since that is based on aliases.
var allAliases = Services.ContentTypeService.GetAllContentTypeAliases();
var exists = allAliases.InvariantContains(contentTypeSave.Alias);
if ((exists) && (ctId == 0 || ct.Alias != contentTypeSave.Alias))
if (exists && (ctId == 0 || !ct.Alias.InvariantEquals(contentTypeSave.Alias)))
{
ModelState.AddModelError("Alias", "A content type, media type or member type with this alias already exists");
ModelState.AddModelError("Alias", Services.TextService.Localize("editcontenttype/aliasAlreadyExists"));
}
// execute the externam validators

View File

@@ -195,6 +195,7 @@ namespace Umbraco.Web.Editors
// so to do that here, we'll need to check if this current user is an admin and if not we should exclude all user who are
// also admins
var hideDisabledUsers = UmbracoConfig.For.UmbracoSettings().Security.HideDisabledUsersInBackoffice;
var excludeUserGroups = new string[0];
var isAdmin = Security.CurrentUser.IsAdmin();
if (isAdmin == false)
@@ -217,6 +218,14 @@ namespace Umbraco.Web.Editors
filterQuery.Where(x => x.Name.Contains(filter) || x.Username.Contains(filter));
}
if (hideDisabledUsers)
{
if (userStates == null || userStates.Any() == false)
{
userStates = new[] { UserState.Active, UserState.Invited, UserState.LockedOut, UserState.Inactive };
}
}
long pageIndex = pageNumber - 1;
long total;
var result = Services.UserService.GetAll(pageIndex, pageSize, out total, orderBy, orderDirection, userStates, userGroups, excludeUserGroups, filterQuery);

View File

@@ -5,8 +5,9 @@ using System.Linq;
using System.Web;
using Examine;
using Examine.LuceneEngine.SearchCriteria;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web.Composing;
@@ -82,6 +83,45 @@ namespace Umbraco.Web
// return the corresponding url segment, or null if none
var cultureInfo = content.GetCulture(culture);
return cultureInfo?.UrlSegment;
}
public static bool IsAllowedTemplate(this IPublishedContent content, int templateId)
{
if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == true)
return content.TemplateId == templateId;
if (content.TemplateId != templateId && UmbracoConfig.For.UmbracoSettings().WebRouting.ValidateAlternativeTemplates == true)
{
// fixme - perfs? nothing cached here
var publishedContentContentType = ApplicationContext.Current.Services.ContentTypeService.GetContentType(content.ContentType.Id);
if (publishedContentContentType == null)
throw new NullReferenceException("No content type returned for published content (contentType='" + content.ContentType.Id + "')");
return publishedContentContentType.IsAllowedTemplate(templateId);
}
return true;
}
public static bool IsAllowedTemplate(this IPublishedContent content, string templateAlias)
{
// fixme - perfs? nothing cached here
var template = ApplicationContext.Current.Services.FileService.GetTemplate(templateAlias);
return = template == null ? false : content.IsAllowedTemplate(template.Id);
}
#endregion
#region IsComposedOf
/// <summary>
/// Gets a value indicating whether the content is of a content type composed of the given alias
/// </summary>
/// <param name="content">The content.</param>
/// <param name="alias">The content type alias.</param>
/// <returns>A value indicating whether the content is of a content type composed of a content type identified by the alias.</returns>
public static bool IsComposedOf(this IPublishedContent content, string alias)
{
return content.ContentType.CompositionAliases.Contains(alias);
}
#endregion

View File

@@ -642,10 +642,15 @@ namespace Umbraco.Web.Security
var provider = _membershipProvider;
string username;
if (provider.IsUmbracoMembershipProvider())
{
var member = GetCurrentPersistedMember();
// If a member could not be resolved from the provider, we are clearly not authorized and can break right here
if (member == null)
return false;
username = member.Username;
// If types defined, check member is of one of those types
var allowTypesList = allowTypes as IList<string> ?? allowTypes.ToList();
if (allowTypesList.Any(allowType => allowType != string.Empty))
@@ -664,6 +669,9 @@ namespace Umbraco.Web.Security
else
{
var member = provider.GetCurrentUser();
// If a member could not be resolved from the provider, we are clearly not authorized and can break right here
if (member == null)
return false;
username = member.UserName;
}

View File

@@ -30,6 +30,8 @@ namespace Umbraco.Web.Trees
[HttpQueryStringFilter("queryStrings")]
public async Task<SectionRootNode> GetApplicationTrees(string application, string tree, FormDataCollection queryStrings, bool onlyInitialized = true)
{
application = application.CleanForXss();
if (string.IsNullOrEmpty(application)) throw new HttpResponseException(HttpStatusCode.NotFound);
var rootId = Constants.System.Root.ToString(CultureInfo.InvariantCulture);
@@ -37,7 +39,7 @@ namespace Umbraco.Web.Trees
//find all tree definitions that have the current application alias
var appTrees = Services.ApplicationTreeService.GetApplicationTrees(application, onlyInitialized).ToArray();
if (appTrees.Length == 1 || string.IsNullOrEmpty(tree) == false )
if (string.IsNullOrEmpty(tree) == false || appTrees.Length <= 1)
{
var apptree = string.IsNullOrEmpty(tree) == false
? appTrees.SingleOrDefault(x => x.Alias == tree)

View File

@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Umbraco.Core;
@@ -21,7 +22,7 @@ namespace Umbraco.Web.WebApi
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(((DateTime)value).ToString(_dateTimeFormat));
writer.WriteValue(((DateTime)value).ToString(_dateTimeFormat, CultureInfo.InvariantCulture));
}
}
}