Skip to content

Commit

Permalink
Merge pull request #4418 from kjac/v8-feature-allow-all-at-root
Browse files Browse the repository at this point in the history
V8: Allow all content types at root if none are explicitly allowed
  • Loading branch information
Warren Buckley committed Feb 7, 2019
2 parents 2c0fc73 + 9579b42 commit 4a2b611
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Umbraco.Web/Editors/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,10 @@ private IContent ValidateMoveOrCopy(MoveOrCopy model)
}
if (model.ParentId < 0)
{
//cannot move if the content item is not allowed at the root
if (toMove.ContentType.AllowedAsRoot == false)
//cannot move if the content item is not allowed at the root unless there are
//none allowed at root (in which case all should be allowed at root)
var contentTypeService = Services.ContentTypeService;
if (toMove.ContentType.AllowedAsRoot == false && contentTypeService.GetAll().Any(ct => ct.AllowedAsRoot))
{
throw new HttpResponseException(
Request.CreateNotificationValidationErrorResponse(
Expand Down
6 changes: 5 additions & 1 deletion src/Umbraco.Web/Editors/ContentTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ public IEnumerable<ContentTypeBasic> GetAllowedChildren(int contentId)
IEnumerable<IContentType> types;
if (contentId == Constants.System.Root)
{
types = Services.ContentTypeService.GetAll().Where(x => x.AllowedAsRoot).ToList();
var allContentTypes = Services.ContentTypeService.GetAll().ToList();
bool AllowedAsRoot(IContentType x) => x.AllowedAsRoot;
types = allContentTypes.Any(AllowedAsRoot)
? allContentTypes.Where(AllowedAsRoot).ToList()
: allContentTypes;
}
else
{
Expand Down
6 changes: 4 additions & 2 deletions src/Umbraco.Web/Editors/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,10 @@ private IMedia ValidateMoveOrCopy(MoveOrCopy model)
}
if (model.ParentId < 0)
{
//cannot move if the content item is not allowed at the root
if (toMove.ContentType.AllowedAsRoot == false)
//cannot move if the content item is not allowed at the root unless there are
//none allowed at root (in which case all should be allowed at root)
var mediaTypeService = Services.MediaTypeService;
if (toMove.ContentType.AllowedAsRoot == false && mediaTypeService.GetAll().Any(ct => ct.AllowedAsRoot))
{
var notificationModel = new SimpleNotificationModel();
notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedAtRoot"), "");
Expand Down

0 comments on commit 4a2b611

Please sign in to comment.