How to fix the Error "User public is not authorized to approve the page in current step".

kentico team nextscape asked on July 14, 2022 13:51

When we wrote a programme to copy the page data of the default culture to another culture and publish the pages of the other culture in the same way as the default culture, we got the following error at the timing of calling the publish method.

ERROR in Workflow_Publish_After: User public is not authorized to approve the page in current step. Stack Trace: 場所 CMS.DocumentEngine.WorkflowManager.MoveToNextStepInternal(TreeNode node, String comment, WorkflowTransitionTypeEnum transitionType)

I checked the data in MembershipContext.AuthenticatedUser and found the following user.Email: user.FullName: Public Anonymous User user.SiteIndependentPrivilegeLevel:None

When only one culture was published manually, the content was as follows user.Email:administrator@localhost.local user.FullName: Global Administrator user.SiteIndependentPrivilegeLevel:GlobalAdmin

I think I can just overwrite it with GlobalAdmin just before publishing programmatically, but has anyone ever done that?

Correct Answer

Brenden Kehren answered on July 15, 2022 15:24

Log into Kentico, navigate to the Scheduled Task and edit it. Towards the bottom, you can select a user to execute the task under. Change that to global admin. This could resolve your problem.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on July 14, 2022 14:57

In your program, you need to make sure you're performing that page creation/copy in the context of a user who has permissions. Is the program a scheduled task? If so, in the scheduled task you can simply choose there to run the task under a given user. In this case, use a user who has permission to copy pages in the content tree.

0 votesVote for this answer Mark as a Correct answer

kentico team nextscape answered on July 15, 2022 07:29 (last edited on July 15, 2022 15:38)

Hi, Brenden.

Thank you for your answer. We will add further information for you.

First, the code is as follows.

protected override void OnInit() 
{ 
    base.OnInit(); 
    WorkflowEvents.Publish.After += Workflow_Publish_After; 

...

private void UpdateRolandProductOfCultures(WorkflowEventArgs e, ref string logMessage) 
{ 
    this.UpdateSelfCulture(e, ref logMessage); 
    if (e.PublishedDocument.IsDefaultCulture) 
    { 
        this.OverrideFromGlobal(e, ref logMessage); 
    } 
} 

... 

private void OverrideFromGlobal(WorkflowEventArgs e, ref string logMessage) 
{ 
    var globalPages = ProductProvider.GetProduct(e.PublishedDocument.NodeGUID, e.PublishedDocument.DocumentCulture, e.PublishedDocument.NodeSiteName); 
    foreach (var page in globalPages) 
    { 
        foreach (Product cultureVersion in page.CultureVersions) 
        { 
                if (cultureVersion.IsDefaultCulture) 
                { 
                    continue; 
                } 

                cultureVersion.CheckOut(); 
                cultureVersion.DocumentPublishFrom = page.DocumentPublishFrom; 
                cultureVersion.DocumentPublishTo = page.DocumentPublishTo; 
                cultureVersion.Update(); 
                cultureVersion.CheckIn(); 
                cultureVersion.Publish(); 
            } 

Then, when we log the contents of MembershipContext.AuthenticatedUser in the Workflow_Publish_After event when it is executed without setting "Publish From", we get the following results.

  • MembershipContext.AuthenticatedUser -- user.Email:(email of admin) -- user.FullName: Global Administrator -- user.SiteIndependentPrivilegeLevel:GlobalAdmin

For a scheduled publish, the following results - MembershipContext.AuthenticatedUser -- user.Email: -- user.FullName: Public Anonymous User -- user.SiteIndependentPrivilegeLevel:None

I got to the point where I was sure I had no privileges, but then I couldn't figure out how to run a scheduled publish with the privileges of a GlobalAdmin.

If so, in a scheduled task you can simply choose there to run the task under a given user. In this case, use a user who has permission to copy pages in the content tree. In this case, use a user who has permission to copy pages in the content tree.

If so, and you have responded to the above answer, what exactly should I do?

0 votesVote for this answer Mark as a Correct answer

kentico team nextscape answered on July 16, 2022 09:13

Thank you for getting back to me so quickly with an answer.

You say. Schedule tasks->Tasks->(select individual site in 'Site:')->Content publishing->In 'Use context of user' select Global Administorator

Is this correct?

In fact, when I did that, I was able to publish correctly, including other cultures. Thanks very much from Japan.

I thought about setting the same permissions for Public Anonymous User as Administrator, but the way you showed me seems to be safer, with no impact on other processes.

Best regards.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.