AI OnAI Off
Not sure if I understand your question. Do you mean you want to run the job manually using the Admin UI? then it should be using your current user
I thought so too, @quan The executing user has changed in v12 Scheduled Jobs - https://www.gulla.net/en/blog/scheduled-jobs-in-optimizely-cms-12/
To paraphrase Tomas' excellent article:
[ScheduledPlugIn(DisplayName = "My Scheduled Job")]
public class MyJob : ScheduledJobBase
{
private readonly IPrincipalAccessor _principalAccessor;
public MyJob (IPrincipalAccessor principalAccessor)
{
_principalAccessor = principalAccessor;
}
public override string Execute()
{
_principalAccessor.Principal = new GenericPrincipal(
new GenericIdentity("Some Dummy User"),
new[] { "WebEditors" }
);
// Do some suff that needs WebEditor privileges.
}
}
Problem: When attempting to update a page property from inside a Scheduled Job, I get an AccessDeniedException: EPiServer.Core.AccessDeniedException: 'Access was denied to content 1501_2939. The required access level was "Edit".' This is due to the page property having a PropertyEditRestriction that limits changes to the CmsAdmins or Administrator roles.
Note: My user is a member of the Administrators group, so running the Job manually should let me overcome this restriction.
I’m making a Scheduled Job to be run manually. I’d like it to run under the permissions of the current user. However, when I run the scheduled job and interrogate the CurrentPrincipal, it seems that the job is not running as my user, but as some sort of unauthenticated ‘blank’ user.
If I use the PrincipalInfo.CurrentPrincipal.IsInRole(Roles.Administrators), it’s false.
https://docs.developers.optimizely.com/content-management-system/docs/scheduled-jobs
Cheers,
Lance