1

Sitecore で、自分が作成したアイテムのみを表示および編集できるロール/ユーザーを作成する方法はありますか? そうでない場合、どうすればこれを可能にできますか?

4

3 に答える 3

1

これを修正するために、sitecore/events config の下に item:created イベントを追加しました。

<event name="item:created" xdt:Transform="Replace" xdt:Locator="Match(name)">
              <handler type="Sirano.Dev.ItemEventHandlers.CustomItemEventHandler, Sirano.Dev" method="OnItemCreated" />
</event>

このイベントは、次のコードを実行します。

    protected void OnItemCreated(object sender, EventArgs args)
    {
        if (args == null)
        {
            return;
        }
        var parameters = Event.ExtractParameters(args);
        var item = ((ItemCreatedEventArgs)parameters[0]).Item;
        if (item == null)
        { 
            return; 
        }

        var user = Sitecore.Context.User;

        var accessRules = item.Security.GetAccessRules();

        accessRules.Helper.AddAccessPermission(user,
           AccessRight.ItemRead,
           PropagationType.Any,
           AccessPermission.Allow);

        accessRules.Helper.AddAccessPermission(user,
           AccessRight.ItemWrite,
           PropagationType.Any,
           AccessPermission.Allow);

        item.Editing.BeginEdit();
        item.Security.SetAccessRules(accessRules);
        item.Editing.EndEdit();
    }
于 2016-03-17T15:25:54.787 に答える
0

私はまさにこの機能を構築し終えました。すぐに使えるものは何もありませんが、これを解決する方法はいくつかあります。

  • 項目:保存イベント ハンドラー (事後に発生する「保存」ではなく「保存」に注意してください)、または
  • UI で [保存] ボタンが実行されたときに実行される saveUI パイプライン用のプロセッサを作成します。
  • getContentEditorWarnings パイプラインのプロセッサを作成する

この最後の方法では、Sitecore UI を無効にしてユーザーにメッセージを表示できますが、コードや API がアイテムを変更するのを防ぐことはできません。これは私たちにとって理想的でした。私たちのプロセッサは、機能をサイトの特定の領域に制限することを可能にするサブ要素として (構成内の) パスのリストを受け入れました (マーケティング コントロール パネルへのアクセスを制御していました)。

<getContentEditorWarnings>これは、部分を注入したパイプラインの抜粋です。

....
<processor type="Sitecore.Pipelines.GetContentEditorWarnings.CanWrite, Sitecore.Kernel"/>
<processor type="PingWorks.Pipelines.GetContentEditorWarnings.EditorIsFromAuthorGroup, PingWorks.Pipelines.GetContentEditorWarnings" patch:source="PingWorks.Pipelines.GetContentEditorWarnings.config">
  <ignoredRoles hint="list:AddIgnoredRole">
    <role>sitecore\_UserBase</role>
  </ignoredRoles>
  <paths hint="list:AddPath">
    <path>/sitecore/system/Marketing Control Panel/Taxonomies/</path>
    <path>/sitecore/system/Marketing Control Panel/Campaigns/</path>
    <path>/sitecore/system/Marketing Control Panel/Engagement Plans/</path>
    <path>/sitecore/system/Marketing Control Panel/Experience Analytics/</path>
    <path>/sitecore/system/Marketing Control Panel/FXM/</path>
    <path>/sitecore/system/Marketing Control Panel/Outcomes/</path>
    <path>/sitecore/system/Marketing Control Panel/Path Analyzer/</path>
    <path>/sitecore/system/Marketing Control Panel/Personalization/</path>
    <path>/sitecore/system/Marketing Control Panel/Test Lab/</path>
    <path>/sitecore/system/Marketing Control Panel/Experience Explorer/</path>
    <path>/sitecore/system/Marketing Control Panel/Analytics Filters/</path>
  </paths>
</processor>
<processor type="Sitecore.Pipelines.GetContentEditorWarnings.CanWriteWorkflow, Sitecore.Kernel"/>
...

パイプライン エグゼキュータがサブ要素を使用して作成するインスタンスのプロパティを入力するために Sitecore 構成ファクトリを使用する方法と、この場合はおよびメソッドを介してList<string>プロパティに文字列を追加する方法に注意してください。::AddIgnoredRole()::AddPath()

私たちの特定のケースでは、編集者が元の作成者と同じ役割グループのメンバーである場合にのみ編集を許可したかったのですが、あなたのロジックは私たちのものよりもさらに単純です. 私たちのケースでは、管理者ユーザーのオーバーライドも追加し、ロールの検索結果を保存するカスタム キャッシュを追加して処理を高速化しました。

処理の大部分は割愛しますが、その核心は::Process()メソッドにあります (現在ソースにアクセスできないため、このコードを反映する必要がありました)。

public void Process(GetContentEditorWarningsArgs args)
{
    string displayName;
    this._item = args.Item;
    if (!this._isValidForProcessing())
        return;

    User user = null;
    List<string> creatorRoles = this._getRolesForUser(this._item.Statistics.CreatedBy, out user);
    List<string> editorRoles = this._getRolesForUser(Context.User);

    // compare creator's roles with current editor to find a match
    if ( creatorRoles.Any() && editorRoles.Any() && editorRoles.Any( r => creatorRoles.Contains(r) ) )
        return;

    // if we haven't already aborted, add a warning to display and block editing
    GetContentEditorWarningsArgs.ContentEditorWarning cew = args.Add();
    cew.IsExclusive = true;
    cew.Key = "EditorIsFromAuthorGroup";
    cew.Title = "Editing restricted";
    cew.Text = $"Editing for this item is restricted. Editors must share a role with the original author, in this case <{user?.DisplayName ?? "Unknown Author"}>.";
}

private bool _isValidForProcessing()
{
    if (this._item == null)
        return false;

    if (Context.IsAdministrator)
        return false;

    if (!this._paths.Any<string>((string p) => this._item.Paths.FullPath.ToLower().StartsWith(p)))
        return false;

    return true;
}

必要な場所で良いスタートを切るには、おそらくこれで十分です。

于 2016-03-17T11:56:01.527 に答える
0

簡単に言うと、Sitecore のロックおよび編集機能を使用できます。ユーザーは、ワークフロー グループの [レビュー] > [編集] でロックできます。編集が完了したら、保存してチェックインをクリックします。ログインしたユーザーが自分のロックされたアイテムを表示したい場合、ユーザーはコンテンツ ツリーの左側を右クリックし、[ロックされたアイテム] を選択して、ロックされたアイテムのガターを表示します。[レビュー] > [マイ アイテム] からすべてのロックされたアイテムを表示することもできます。これによってアクセス権が変更されることはありません。ただし、管理者以外のユーザーがアイテムのロックを解除できないようにします。

于 2016-03-17T16:09:25.840 に答える