Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Jan 28, 2016 @ 11:40
    Nik
    0

    Prevent users from Unpublishing

    Hi All,

    I could be being blind, but is there a permission to stop users from "Unpublishing" pages? There is one for publish but I couldn't spot one the other way.

    Nik

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 28, 2016 @ 13:15
    Ismail Mayat
    0

    Nik,

    In the past we have done this with content events so on the before unpublish you cancel the publish.

    Regards

    Ismail

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 29, 2016 @ 07:55
    Dave Woestenborghs
    1

    Hi Nik,

    I'm doing this as well with content events. Especially to prevent users from unpublishing or deleting nodes that are needed for a functioning website (e.g. homepage)

    Here is the code I have :

    public class BootManager : ApplicationEventHandler
    {                
            protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ContentService.UnPublishing += this.ContentServiceOnUnPublishing;
            }
    
             private void ContentServiceOnUnPublishing(IPublishingStrategy sender, PublishEventArgs<IContent> publishEventArgs)
            {
                var doctypes = new[]
                                   {
                                       "Website",
                                       "Homepage"
                                   };
    
                foreach (var entity in publishEventArgs.PublishedEntities)
                {
                    if (doctypes.Contains(entity.ContentType.Alias))
                    {                   
                        publishEventArgs.CancelOperation(new EventMessage("Warning", "This page can not be unpublished", EventMessageType.Warning));
                    }
                }
            }
    }
    

    You can see i'm trying to show a warning message to the user when the unpublish is cancelled. However that is not working because of bug in Umbraco. The unpublishing is cancelled, but you don't have feedback to the user

    The bug is found here : http://issues.umbraco.org/issue/U4-7757

    Vote it up if you wan't to have it fixed.

    Dave

  • Zac 223 posts 575 karma points
    Nov 16, 2016 @ 11:30
    Zac
    0

    I also have this issue in 7.5.4 when trying to CancelOperation for a Media trashing event.

Please Sign in or register to post replies

Write your reply to:

Draft