高级用户访问 Sitecore 回收站
Posted
技术标签:
【中文标题】高级用户访问 Sitecore 回收站【英文标题】:Power user access to Sitecore Recycle Bin 【发布时间】:2014-12-04 16:14:17 【问题描述】:是否有人知道允许特定角色的用户查看 Sitecore 回收站中所有项目的解决方案?
目前,只有管理员可以查看所有已删除的项目。用户只能看到他们已删除的项目。
【问题讨论】:
【参考方案1】:没有办法开箱即用,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 0Archive1.0ArchivalId1, 0Archive1.0ItemId1, 0ParentId1, 0Name1, 0OriginalLocation1, \r\n 0ArchiveDate1, 0ArchivedBy1, ROW_NUMBER() OVER(ORDER BY 0ArchiveDate1 DESC, 0ArchivalId1) as 0RowNumber1\r\n FROM 0Archive1 \r\n WHERE 0ArchiveName1 = 2archiveName3";
var showAllItems = user.IsInRole("Super User Role") || user.IsAdministrator;
if (user != null && !showAllItems)
str1 = str1 + " AND 0ArchivalId1 IN (SELECT 0ArchivalId1\r\n FROM 0ArchivedVersions1 WHERE 0ArchivedBy1 = 2archivedBy3) ";
arrayList.AddRange(new[] "archivedBy", user.Name );
if (archivalId != ID.Null)
str1 = str1 + " AND 0ArchivalId1 = 2archivalId3";
arrayList.Add("archivalId");
arrayList.Add(archivalId);
var str2 = str1 + ") 0ArchiveWithRowNumbers1";
if (pageSize != int.MaxValue)
str2 = str2 + " WHERE 0RowNumber1 BETWEEN 2firstRow3 AND 2lastRow3";
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 0ArchiveDate1 DESC, 0ArchivalId1", 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>
然后添加一个名为“超级用户角色”的角色,并将您希望拥有该访问权限的任何用户设置为成员。
** 注意 - 代码未经测试 **
【讨论】:
【参考方案2】:下面是与 Richard 的回答类似的方法,但不是复制 GetEntries()
中的所有逻辑,而是欺骗管理员用户。除了 CustomSqlArchive
本身之外,您还需要实现 SqlArchiveProvider
。
SQL 存档
public class CustomSqlArchive : SqlArchive
private const string PowerUserRole = @"sitecore\Power User";
private const string AdminUser = @"sitecore\Admin";
public AvidSqlArchive(string name, Database database) : base(name, database)
protected override IEnumerable<ArchiveEntry> GetEntries(User user, int pageIndex, int pageSize, ID archivalId)
if (user != null && Role.Exists(PowerUserRole) && user.IsInRole(PowerUserRole))
User admin = User.FromName(AdminUser, true);
return base.GetEntries(admin, pageIndex, pageSize, archivalId);
return base.GetEntries(user, pageIndex, pageSize, archivalId);
SQL 存档提供程序
public class CustomSqlArchiveProvider : SqlArchiveProvider
protected override Sitecore.Data.Archiving.Archive GetArchive(XmlNode configNode, Database database)
string attribute = XmlUtil.GetAttribute("name", configNode);
return !string.IsNullOrEmpty(attribute) ?
new CustomSqlArchive(attribute, database) :
null;
配置补丁
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<!-- Use custom archive that allows users in the "Power User" role to see other user's items by spoofing the admin user -->
<archives defaultProvider="sql" enabled="true">
<patch:attribute name="defaultProvider">custom</patch:attribute>
<providers>
<clear />
<add name="custom" type="Example.CustomSqlArchiveProvider, Example" database="*" />
<add name="sql" type="Sitecore.Data.Archiving.SqlArchiveProvider, Sitecore.Kernel" database="*" />
<add name="switcher" type="Sitecore.Data.Archiving.SwitchingArchiveProvider, Sitecore.Kernel" />
</providers>
</archives>
</sitecore>
</configuration>
【讨论】:
以上是关于高级用户访问 Sitecore 回收站的主要内容,如果未能解决你的问题,请参考以下文章
Sitecore Federated Experience Manager:新用户访问 FXM 模块