如何限制Sitecore语言仅写入内容树的某些部分 [英] How to limit Sitecore Language Write to only certain parts of the content tree

查看:295
本文介绍了如何限制Sitecore语言仅写入内容树的某些部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的Sitecore实现中,我们有分支编辑,需要对英语和母语(例如德语)进行语言写入访问。但是,我们有内容树的某些部分,其中英文版本不应该由分支编辑器编辑,但是母语版本应该。



为了给出一个具体的例子,如果我们有一个产品页面上有一些关于它的全局信息(例如一个部件号)和一些可本地化的信息(例如描述字段),我们使用字段级安全锁定全局(部件号)字段,但需要一种方法,以确保德语编辑器,例如,可以创建一个德语版本的项目,并放入他们翻译的可本地化(描述)文本,但不能无意中切换到并更新该描述的英文版本。 / p>

我了解在某些角色的系统>语言中设置语言读/写。我们得到了那部分。我想知道的是,如果有一种方法可以有效地完成以下类型的场景,对于有英语和德语版本的写权限的假设内容编辑者:




  • 首页

    • 第1个项目(编辑者可以同时使用英文和德文版本)

    • ...子项目1

    • ...子项目2

    • 项目2 版本)

    • ...子项目1

    • ...子项目2




感谢您提出任何建议。

方案

据我所知,本地Sitecore安全模型在这方面是不足的。语言读/写访问不能本地化到内容树的给定部分。也就是说,如果您可以编辑语言,则可以对拥有写入权限的所有内容项进行此操作。



但是,我认为您可以使用是saveUi管道和getContentEditorWarnings管道的组合。



saveUi



这个管道你需要一个处理器,检查用户是否应该能够编辑当前语言的给定内容。我将留给你,如何配置/确定(XML配置?用户访问内容树的分支中特定于语言的项目?),但如果用户应该被拒绝访问,您可以防止保存。

  public class CheckLanguageWritePermission 
{
public string WorkflowStateID {get;组; }

public void Process(SaveArgs args)
{
Assert.ArgumentNotNull(args,args);
Assert.IsNotNull(args.Items,args.Items);
foreach(args.Items中的SaveArgs.SaveItem项)
{
Item item2 = Sitecore.Client.ContentDatabase.Items [item.ID,item.Language];
if(/ * user不应该有权限* /)
{
AbortSave(args);
return;
}
}
}

protected void AbortSave(SaveArgs args)
{
if(args.HasSheerUI)
{
SheerResponse.Alert(您没有以当前语言编辑此项目的权限。
SheerResponse.SetReturnValue(failed);
}
args.AbortPipeline();
}
}

getContentEditorWarnings >

由于您无法阻止用户使用此方法实际编辑内容(只是保存),因此您应该提供一个警告。

  public class CheckLanguageWritePermission 
{
//方法
public void Process(GetContentEditorWarningsArgs args)
{
Item item = args.Item;
if(/ *用户不应该有权限* /)
{
GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
warning.Title =您没有以当前语言编辑此项目的权限。
warning.IsExclusive = true;
}
}
}

但它确实防止对内容的不期望的编辑。如果版本控制/工作流程正在运行,您可以通过覆盖item:addversion和item:checkout的UI命令,完全阻止添加新版本。



确定访问权限可能很棘手,最好的解决方法取决于您的具体业务规则。


In our Sitecore implementation, we have branch editors who will need language write access to both English and their native language (e.g. German). However, we have certain portions of our content tree where the English version should not be editable by those branch editors, but the native language version should.

To give a specific example, if we have a product page that has some global information on it (e.g. a part number), and some localizable information on it (e.g. a description field), we're using field level security to lock down the global (part number) fields, but need a way to ensure that a German editor, for example, can create a German version of the item and put in their translated localizable (description) text, but cannot inadvertently switch to and update the English version of that description.

I understand about setting language read/write on the System > Languages for certain roles. We've got that part covered. What I am wondering about is if there's a way to effectively accomplish the following type of scenario, for a hypothetical content editor who has write access to English and German language versions:

  • Home
    • Item 1 (editor has write access to both English and German versions)
    • ...Sub Item 1
    • ...Sub Item 2
    • Item 2 (editor has write access to German versions only)
    • ...Sub Item 1
    • ...Sub Item 2

Thanks in advance for any suggestions.

解决方案

As far as I know, the native Sitecore security model is deficient in this regard. Language Read/Write access cannot be localized to a given part of the content tree. That is, if you can edit a language, you can do so on all content items for which you have write access.

However, I think you can accomplish your requirements using a combination of the saveUi pipeline and the getContentEditorWarnings pipeline.

saveUi

In this pipeline you'll need a processor that checks whether the user should be able to edit the given content in the current language. I'll leave it to you as to how this is configured / determined (XML configuration? user access to a language-specific item in a branch of the content tree?), but if the user should be denied access, you can prevent the save.

public class CheckLanguageWritePermission
    {
        public string WorkflowStateID { get; set; }

        public void Process(SaveArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.IsNotNull(args.Items, "args.Items");
            foreach (SaveArgs.SaveItem item in args.Items)
            {
                Item item2 = Sitecore.Client.ContentDatabase.Items[item.ID, item.Language];
                    if (/* user should not have permission*/)
                    {
                        AbortSave(args);
                        return;
                    }
            }
        }

        protected void AbortSave(SaveArgs args)
        {
            if (args.HasSheerUI)
            {
                SheerResponse.Alert("You do not have permission to edit this item in the current language.");
                SheerResponse.SetReturnValue("failed");
            }
            args.AbortPipeline();
        }
    }

getContentEditorWarnings

Since you can't prevent the user from actually editing content with this approach (just saving it), you should probably provide a warning that says as much.

public class CheckLanguageWritePermission
{
    // Methods
    public void Process(GetContentEditorWarningsArgs args)
    {
        Item item = args.Item;
        if (/* user should not have permission*/)
        {
            GetContentEditorWarningsArgs.ContentEditorWarning warning = args.Add();
            warning.Title = "You do not have permission to edit this item in the current language.";
            warning.IsExclusive = true;
        }
    }
}

It is not a perfect solution but it does prevent undesirable edits to content. If versioning/workflow is in play, you might be able to prevent the addition of new versions altogether by overriding the UI commands for item:addversion and item:checkout.

Determining access rights could be tricky, the best way to go about that would depend on your specific business rules.

这篇关于如何限制Sitecore语言仅写入内容树的某些部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆