gpt4 book ai didi

sitecore - 高级用户访问 Sitecore 回收站

转载 作者:行者123 更新时间:2023-12-02 07:26:52 25 4
gpt4 key购买 nike

有谁知道允许特定角色的用户查看 Sitecore 回收站中所有项目的解决方案?

目前,只有管理员可以查看所有已删除的项目。用户只能看到他们已删除的项目。

最佳答案

没有开箱即用的方法,SqlArchive.GetEntries 检查 user.IsAdministrator 以显示存档中的所有条目。

您需要实现自定义存档提供程序并覆盖 GetEntries 方法以从角色开始工作。

例子:

public class CustomSqlArchive : SqlArchive
{
public CustomSqlArchive(string name, Database database)
: base(name, database)
{
}

protected override IEnumerable<ArchiveEntry> GetEntries(User user, int pageIndex, int pageSize, ID archivalId)
{
Assert.IsNotNull(archivalId, "archivalId");
var arrayList = new ArrayList(new[] { "archiveName", this.Name });
var str1 = "SELECT * FROM \r\n (SELECT {0}Archive{1}.{0}ArchivalId{1}, {0}Archive{1}.{0}ItemId{1}, {0}ParentId{1}, {0}Name{1}, {0}OriginalLocation{1}, \r\n {0}ArchiveDate{1}, {0}ArchivedBy{1}, ROW_NUMBER() OVER(ORDER BY {0}ArchiveDate{1} DESC, {0}ArchivalId{1}) as {0}RowNumber{1}\r\n FROM {0}Archive{1} \r\n WHERE {0}ArchiveName{1} = {2}archiveName{3}";

var showAllItems = user.IsInRole("Super User Role") || user.IsAdministrator;

if (user != null && !showAllItems)
{
str1 = str1 + " AND {0}ArchivalId{1} IN (SELECT {0}ArchivalId{1}\r\n FROM {0}ArchivedVersions{1} WHERE {0}ArchivedBy{1} = {2}archivedBy{3}) ";
arrayList.AddRange(new[] { "archivedBy", user.Name });
}

if (archivalId != ID.Null)
{
str1 = str1 + " AND {0}ArchivalId{1} = {2}archivalId{3}";
arrayList.Add("archivalId");
arrayList.Add(archivalId);
}

var str2 = str1 + ") {0}ArchiveWithRowNumbers{1}";
if (pageSize != int.MaxValue)
{
str2 = str2 + " WHERE {0}RowNumber{1} BETWEEN {2}firstRow{3} AND {2}lastRow{3}";
var num1 = (pageIndex * pageSize) + 1;
int num2 = pageSize == int.MaxValue ? int.MaxValue : (pageIndex + 1) * pageSize;
arrayList.AddRange(new[] { "firstRow", num1.ToString(), "lastRow", num2.ToString() });
}

return this.GetEntries(str2 + " ORDER BY {0}ArchiveDate{1} DESC, {0}ArchivalId{1}", arrayList.ToArray());
}
}

然后您需要将自定义提供程序添加到配置中:

<archives defaultProvider="custom" enabled="true">
<providers>
<clear />
<add name="custom" type="Sitecore.Data.Archiving.SqlArchiveProvider, Sitecore.Kernel" database="*" />
<add name="sql" type="Sitecore.Data.Archiving.SqlArchiveProvider, Sitecore.Kernel" database="*" />
<add name="switcher" type="Sitecore.Data.Archiving.SwitchingArchiveProvider, Sitecore.Kernel" />
</providers>
</archives>

然后添加一个名为 super 用户角色的角色,并将您希望拥有该访问权限的任何用户作为成员。

** 注意 - 代码未经测试 **

关于sitecore - 高级用户访问 Sitecore 回收站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27298727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com