我创建了一些非管理员的Sitecore用户,并为他们分配了少量角色。当这些用户默认访问Sitecore门户时,他们不会显示隐藏的项目,他们必须转到查看选项卡并手动配置它。有没有办法我可以配置这些用户默认情况下通过对这些用户之间共享的用户角色进行一些配置来查看隐藏的项目。
答案 0 :(得分:7)
此信息由Sitecore.Shell.UserOptions.View.ShowHiddenItems
属性检索,该属性从UserProfile
获取此数据(如果已加载配置文件,则从RegistryCache
获取此数据。)
分别为每个用户存储用户配置文件信息,并以二进制列的形式保存在数据库中。无法从用户角色获取此选项。
你仍然可以编写一个脚本来循环你所提到的角色中的所有用户,并在这些用户的个人资料中设置值:
public static void SetHiddenItemsValue(User user)
{
string key = "/Current_User/UserOptions.View.ShowHiddenItems";
string value = "true";
if (!(user != null))
return;
key = StringUtil.Left(key, 250);
key = key.Replace("Current_User", user.Name);
user.Profile[key] = value;
user.Profile.Save();
RegistryCache registryCache = CacheManager.GetRegistryCache(Sitecore.Context.Site);
if (registryCache == null)
return;
registryCache.Clear();
}
答案 1 :(得分:4)
Maras的另一个选择是您可以挂钩security:loggedin
事件并设置该值。
您的课程需要继承Sitecore.Pipelines.LoggedIn.LoggedInProcessor
这需要做以下事情:
public override void Process(LoggedInArgs args)
{
var user = Sitecore.Security.Accounts.User.FromName(args.Username, true);
var key = "/" + args.Username + "/UserOptions.View.ShowHiddenItems";
// if user needs to be in a specific role only, check that here
// if (user.IsInRole("yourrolename"))
if (String.IsNullOrEmpty(user.Profile[key]))
{
user.Profile[key] = "true";
user.Profile.Save();
}
}