3

I'm trying to catch the moment when a user hits the Publish button in the publish popup screen in the GUI. This is a GUI-driven event, which is important for me because I have some logic that is tied to the group memberships of the user who clicks the button. For this reason, I cannot use any of the events that are fired by the publisher service. For those events, the session user is always 'NT Authority\System'.

The following code does not seem to work, or rather, I cannot get it to start debugging. I have attached to the dllhost, dllhst3g and TcmServiceHost processes, but although the breakpoints become active, they are never hit.

[TcmExtension("PreventPublishing")]
public class PreventPublishing : TcmExtension
{
    public PreventPublishing()
    {
        EventSystem.Subscribe<RepositoryLocalObject, PublishingEventArgs>(OnItemPublish, EventPhases.Initiated);
    }

    private void OnItemPublish(RepositoryLocalObject item, PublishingEventArgs args, EventPhases phase)
    {
        User user = item.Session.User;
        if (user.IsSystemAdministrator)
            return;
        throw new PublisherException(new LocalizableMessage("Only system administrators are allowed to publish"));
    }
}

Any clues?

1
  • Is there a reason why you don't want to accomplish the "Only system administrators are allowed to publish" functionality through Tridion's authorization (Rights, Scope and Permissions)? Simply remove the Publish to Content Distributor right on that user's group, or set security on each Publish Target. Commented Jan 25, 2014 at 1:59

2 Answers 2

4

PublishingEventArgs is an abstract class which contains all the events related to publishing items. Try PublishEventArgs, which are related specifically to publishing an item.

BTW, why can't you use publisher events? You can get user who is publishing by looking at PublishTransaction.Creator property

1
  • I chose the abstract class on purpose, because I want to handle all publishing-related events. This is possible, I have done it in the past. I didn't know about the Creator property, that would be a good alternative, thanks! I would still prefer to catch the publishing while the GUI is still active, so I can throw an exception that the user can see rightaway.
    – Quirijn
    Commented Jan 24, 2014 at 22:24
2

My conclusion is that it is not possible to catch the event of 'user is actually clicking on the publish button' with the event system.

Alternatives are:

  • Build a GUI extension which catches this event

  • Catch the event inside the publisher, and use the PublishTransaction.Creator property to find the identity of the user who initiated the publish action.

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.