以编程方式访问 Sitecore 用户的工作箱

发布于 2024-11-17 22:28:15 字数 117 浏览 1 评论 0原文

我想从 C# 访问用户的工作箱,以便我可以循环访问其工作箱中的所有项目并更新每个版本的项目的工作流程状态。

我正在使用 Sitecore 6.2.0(修订版 101105)

感谢您的关注!

I would like to access a user's workbox from C# so that I can loop through all of the items in his workbox and update the workflow state for each version of the items.

I'm using Sitecore 6.2.0 (rev. 101105)

Thank you for your attention!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风也等你 2024-11-24 22:28:15

编辑:以下代码需要在主上下文下运行 - “从 sitecore 管理内部”。如果您从 Web 上下文(网站上的页面)运行它并且 Context.Database 是“web”,那么您需要将 Sitecore.Context.Database 的所有实例替换为 Factory.GetDatabase("master")


首先您需要获取所有工作流程

Sitecore.Context.Database.WorkflowProvider.GetWorkflows();

然后,对于每个工作流程,您需要获取所有状态:

workflow.GetStates();

然后,对于每个状态,您可以获得所有项目

var itemDataUris = workflow.GetItems(state);

GetItems 返回 dataUris 列表
因此,如果您当前使用相关用户登录,则可以执行

foreach (var dataUri in itemDataUris)
{
    var item = Context.Database.GetItem(dataUri);
    //check if the item is null (if null the user doesn't have access to it
    if (item != null)
       usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
}

如果以管理员身份运行并希望为其他用户获取该项目,您需要将上述代码包装在 UserSwitcher 中

Sitecore.Security.Accounts.UserSwitcher.Enter(Sitecore.Security.Accounts.User.FromName("sitecore\User", true));
foreach (var dataUri in itemDataUris)
    {
        var item = Context.Database.GetItem(dataUri);
        //check if the item is null (if null the user doesn't have access to it
        if (item != null)
           usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
    }
Sitecore.Security.Accounts.UserSwitcher.Exit();

希望有帮助!

EDIT: The following code needs to be run under under a master context - "From inside the sitecore admin". If you are running it from a web context (a page on the site) and Context.Database is "web" then you need to replace all instances of Sitecore.Context.Database with Factory.GetDatabase("master")


First you need to get all the workflows

Sitecore.Context.Database.WorkflowProvider.GetWorkflows();

Then foreach workflow you need to get all the states:

workflow.GetStates();

Then for each state you can get all the items

var itemDataUris = workflow.GetItems(state);

GetItems returns a list of dataUris
So if you are currently logged in with the user in question you can just do

foreach (var dataUri in itemDataUris)
{
    var item = Context.Database.GetItem(dataUri);
    //check if the item is null (if null the user doesn't have access to it
    if (item != null)
       usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
}

If are running as an admin and want to get the item for another user you need to wrap the above code in a UserSwitcher

Sitecore.Security.Accounts.UserSwitcher.Enter(Sitecore.Security.Accounts.User.FromName("sitecore\User", true));
foreach (var dataUri in itemDataUris)
    {
        var item = Context.Database.GetItem(dataUri);
        //check if the item is null (if null the user doesn't have access to it
        if (item != null)
           usersWorkflowItems.Add(item); //Here you also need to somehow add which state the item is in
    }
Sitecore.Security.Accounts.UserSwitcher.Exit();

Hope that helps!

贱贱哒 2024-11-24 22:28:15

不确定代码运行位置的上下文或运行频率,但您可以利用用户工作箱中的 RSS 源吗?

Not sure the context of where your code is running, or how often, but could you utilize the RSS feed from the user's workbox?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文