Umbraco - 阻止用户编辑页面名称

Gav*_*vin 3 umbraco umbraco7

有没有人有任何建议的策略来阻止用户编辑页面名称?

我正在Umbraco开发一个网站,其中各个合作伙伴都有自己的特定页面,他们可以专门编辑.通过标准Umbraco权限控制对此页面的访问.但是我们发现其中一些用户一直在编辑页面标题,但我们希望将它们限制为只能编辑内容.

我无法通过内置权限看到任何明显的方法来控制它.

也许可以插入一些页面预保存代码来检查用户是否具有某些权限,如果不是,则页面名称被设置为预编辑状态?

任何建议/指针都非常感谢.

Mar*_*ski 8

是的,您可以连接到Umbraco ContentService事件并检查Name是否已更改,是否对此特定节点执行某些操作.您还可以添加一些额外的检查以确定是否允许用户更改名称(例如,您可以通过角色或任何其他需要来控制此名称).

示例代码如下所示:

public class UmbracoEvents : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Saving += ContentService_Saving;
    }

    private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IContent> e)
    {
        foreach (var changedItem in e.SavedEntities)
        {
            var currentVersion = sender.GetById(changedItem.Id);
            if (!currentVersion.Name.InvariantEquals(changedItem.Name))
            {
                // Additional checks here (or in the above condition) - role / property / etc...
                item.Name = currentVersion.Name;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您也可以在此处阅读有关特定事件的更多信息:https://our.umbraco.org/documentation/reference/events/contentservice-events.