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

Umbraco - Preventing users editing the page name

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

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

我看不出有什么明显的方法可以通过 built-in 权限来控制它。

也许可以插入一些页面 pre-save 代码来检查用户是否具有特定权限,如果没有,页面名称将设置为 pre-edit 状态?

非常感谢任何建议/指点。

是的,您可以连接到 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;
            }
        }
    }
}

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