I'm looking for a way to lock certain pages for users. The homepage for instance sould not have a delete option and the document type can only exist once. The content however should be editable for the user.
Is there a way to manage these poperties?
Kind regards,
Frans
edit: I do know that I can prevent deletion per page per user but I am looking for some sort of a global setting for all users except admin for example
And here is a eventhandler to allow certain doctypes only once in your site
namespace Customer.Cms.Events
{
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
/// <summary>
/// Allow document types to be created once
/// </summary>
public class AllowOnce : ApplicationEventHandler
{
/// <summary>
/// Initializes a new instance of the <see cref="AllowOnce"/> class.
/// </summary>
public AllowOnce()
{
ContentService.Creating += this.ContentServiceCreating;
}
/// <summary>
/// Gets the content types that are allowed once under the parent
/// </summary>
private IEnumerable<string> ContentTypes
{
get
{
return new[]
{
"Homepage",
"Settings"
};
}
}
/// <summary>
/// The content service_ creating.
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void ContentServiceCreating(IContentService sender, Umbraco.Core.Events.NewEventArgs<IContent> e)
{
if (this.ContentTypes.Contains(e.Entity.ContentType.Alias))
{
if (e.ParentId == -1 && e.Entity.ContentType.Alias == DocumentTypes.Homepage.Alias)
{
// only allow one homepage
e.Cancel = true;
}
else
{
IContent parent = sender.GetById(e.ParentId);
if (parent != null)
{
if (parent.Children().Any(x => x.ContentType.Alias == e.Entity.ContentType.Alias))
{
e.Cancel = true;
}
}
}
}
}
}
}
Prevent deletion and prevent double homepage
Hi,
I'm looking for a way to lock certain pages for users. The homepage for instance sould not have a delete option and the document type can only exist once. The content however should be editable for the user.
Is there a way to manage these poperties?
Kind regards,
Frans
edit: I do know that I can prevent deletion per page per user but I am looking for some sort of a global setting for all users except admin for example
I used a eventhandler for that. This prevents deleting and unpublishing for certain doctypes
Dave
And here is a eventhandler to allow certain doctypes only once in your site
Hi Dawoe,
Thanks for the fast reply!
I'll try this solution in our next site.
Kind regards,
Frans
is working on a reply...