4

We have many Sitecore admin users in Sitecore. I want Full site publish only allowed to some admin users and not to all admin users.

We can't hide the "Publish Site" option as some of the admin require to access it. When any other admin user, who is not from authorized admin user list, try to publish the full site, I want to cancel the publish operation itself. Below is the code which I am referring to cancel the operation on publish:begin event, but unfortunately, its not cancelling the publishing operation?

public void OnPublishStart(object sender, EventArgs args)
    {
        try
        {
            Publisher publisher = Sitecore.Events.Event.ExtractParameter(args, 0) as Publisher;

            if (publisher.Options.Mode == PublishMode.Full || publisher.Options.Mode == PublishMode.Smart || publisher.Options.Mode == PublishMode.Incremental)
            {
                ((SitecoreEventArgs)args).Result.Cancel = true;

                publisher = null;
                args = null;
                sender = null;

                return;
            }
        }
        catch (Exception ex)
        {
            Log.Error("Error : " + ex.ToString(), this);
        }
    }

Do anybody have any workaround to cancel the publish site operation programmatically?

1
  • 1
    I don't think you can really cancel the publish, but you simply shouldn't have so many admin users. Normally you should be able to create roles and assign all necessary rights that way - I would suggest to review your security setup..
    – Gatogordo
    Commented May 12, 2017 at 8:29

1 Answer 1

5

You need to have code in the publish item process to do it

You won't be able to just "find" the task running and abort or delete it in any way - you have to get "in there" and interact with the task directly.

There are ways. The most creative I've found, essentially works like this:

  1. Have a Singleton class instantiated, as part of your <initialize> pipeline
  2. Insert a bit of code into the publishItem pipeline, checking if it should terminate (by checking on the Singleton)
  3. If so, throw an exception. This is the only way to abort the publish thread

With this in place, all you need is to tell the Singleton you want publishing terminated.

All of this is demonstrated in Mike Edward's Glass.PublishViewer module on GitHub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.