Copied to clipboard

Flag this post as spam?

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


  • Mikael Mørup 297 posts 326 karma points
    Nov 24, 2009 @ 10:29
    Mikael Mørup
    1

    Undelete in media section ?

    One  of my clients managed to delete a branch of the media library in their Umbraco site that should not have been deleted.

    I checked the recycle bin in the content tree, but of course it was not there.

    is there any way to undelete Media ?

     

     

     

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Nov 24, 2009 @ 10:33
    Niels Hartvig
    2

    No - you have to restore a SQL + file backup. In v4.1 there'll be a recycle bin in the Media library.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 24, 2009 @ 10:36
    Dirk De Grave
    0

    Mikael,

    Recycle bin for media will be available as from v4.1 release on... However, do check whether files still exist on disk. (Media docs are gone forever and will have to be re-created). PITA, but as said, v4.1 will include a recycle bin for media items (in media section)

     

    Cheers,

    /Dirk

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 24, 2009 @ 10:39
    Sebastiaan Janssen
    2

    It is not very difficult to accidentally delete complete folders in 4.0. I've recently made an event handler that prevents editors at least from removing folders in the media section. It's not ideal, but it helps me a lot:

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.media;
    
    namespace Omega.EventHandlers
    {
        public class PreventFolderDeletionHandler : ApplicationBase
        {
            public PreventFolderDeletionHandler()
            {
                Media.BeforeDelete += PreventDeleteByEditor;
            }
    
            private static void PreventDeleteByEditor(Media sender, DeleteEventArgs e)
            {
                if (User.GetCurrent().UserType.Alias == "editor" && sender.ContentType.Alias == "Folder")
                    e.Cancel = true;
            }
        }
    }
  • Mikael Mørup 297 posts 326 karma points
    Nov 24, 2009 @ 10:48
    Mikael Mørup
    0

    Cool to hear it's in 4.1

    Fortunately the branch they deleted only had a few files in it, and even more fortunatly when it happend i was away for two weeks to take care of my new born son, so someone else had to deal with it :-)

  • Olly Berry 47 posts 68 karma points
    Dec 10, 2009 @ 13:13
    Olly Berry
    0

    Sebastiaan - this looks like exactly what I'm looking for - where do I put the event handler?

     

    Thanks,

     

    Olly

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Dec 10, 2009 @ 13:20
    Sebastiaan Janssen
    0

    Olly, the eventhandler is a seperate project that I make in visual studio. The output is a dll file that gets copied into the umbraco\bin folder. 

    I've blogged about how I set up my projects, have a look at the "UmbracoModules" especially.

    Don't forget to add some references to your project, I'm not sure which ones are needed here but currently I reference umbraco\bin\umbraco.dll, cms.dll, interfaces.dll and businesslogic.dll in my EventHandlers project.

  • Olly Berry 47 posts 68 karma points
    Dec 10, 2009 @ 14:01
    Olly Berry
    0

    Thanks again Sebastiaan (you're my main man today!!)

    In fact I've left it uncompiled for now and copied my "EventHandlers.cs" file to the app_code folder which is also working nicely : )

  • kristian schneider 190 posts 351 karma points
    Dec 10, 2009 @ 21:10
    kristian schneider
    0

    I've made a functionality similar to sebastians that checks the current user and if they are not in the right group I'll remove the delete functionality from the rightclick menu.

    I'll post the code tomorow morning.

  • kristian schneider 190 posts 351 karma points
    Dec 11, 2009 @ 07:58
    kristian schneider
    4

    This is how I've done it:

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using umbraco;
    using umbraco.BusinessLogic;
    using umbraco.BusinessLogic.Actions;
    using umbraco.cms.businesslogic.media;
    using umbraco.cms.presentation.Trees;
    using umbraco.interfaces;

    namespace Kraftvaerk.OLF.EventHandlers
    {
    public class PreventeMediaDeleteEventhandler : ApplicationBase
    {

    public PreventeMediaDeleteEventhandler()
    {
    BaseTree.BeforeNodeRender += new BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender);
    }

    void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
    {
    if (node.NodeType == "media" && (User.GetCurrent().UserType.Alias!="Administrator" && User.GetCurrent().UserType.Alias!="admin"))
    {
    try
    {
    node.Menu.Remove(ActionDelete.Instance);
    }
    catch(Exception ex)
    {
    Log.Add(LogTypes.Error, 0, "Something happen in BaseTree_BeforeNodeRender: "+ ex);
    }
    }
    }
    }
    }
  • Olly Berry 47 posts 68 karma points
    Dec 11, 2009 @ 11:02
    Olly Berry
    0

    Very nice!

  • Bjørn Fridal 274 posts 784 karma points
    Dec 15, 2009 @ 09:41
    Bjørn Fridal
    0

    Good stuff, just what I was looking for.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 09:08
    Jeroen Breuer
    0

    I'm trying the same thing for saving a document type but can't get it to work.

    Now I've got the following code:

        public class MaashorstEvents : ApplicationBase
        {
            public MaashorstEvents()
            {
                Document.BeforeSave += new Document.SaveEventHandler(Document_BeforeSave);
            }       
    protected void Document_BeforeSave(Document sender, SaveEventArgs e)
            {
                e.Cancel = true;
            }
        
        }

    This code is supposed to cancel every save or save and publish, but the code still get's saved. I debugged it and e.cancel = true is being hit. Does anybody know what I'm doing wrong?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 09:10
    Jeroen Breuer
    0

    Edit:

    I'm not trying to save a document type, but a document/node.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Dec 16, 2009 @ 09:20
    Richard Soeteman
    0

    Hi Jeroen,

    This is because some properties automatically gets saved when using the setter property,. so Document.Getproperty("SomeProperty").value = "update" will save the value, not Document.Save Aaron Powell wrote a blogpost about this.

    Cheers,

    Richard

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 09:24
    Jeroen Breuer
    0

    Thanks for the info Richard! However this still doesn't solve my problem. I've got a default page with some textboxes (like a normal Runway Textpage), but I want to prevent the user from saving the data (so he can only view it). How can I do this if the data is saved when the property is set?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Dec 16, 2009 @ 10:24
    Richard Soeteman
    1

    Hi Jeroen,

    I think you can't do that easily, You need to disable the textbox so the user can't edit the textbox. It can be done using the venets system,  but it's a hack. Last week I did something similar for a client and I will blog about it later, don't expect something fancy. If you want to tryu something for yourself now. You have to look into the

    ContentControl

     

    .AfterContentControlLoad event

    Cheers,

    Richard

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 10:27
    Jeroen Breuer
    0

    Thanks Richard I'll look into it. It's a shame it can't be done easier. Hopefully this will change in Umbraco 4.1.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 10:54
    Jeroen Breuer
    0

    Isn't it an easier solution instead of disabling the textboxes to just disable the save and publish button? Is this possible, because I just want the user to view content but not save it. Is there an event in which I can disable these buttons?

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Dec 16, 2009 @ 11:06
    Casey Neehouse
    0

    @jeroen,

    You could write a simple data type control that places a transparent overlay on the window.  It won't stop edits completely (tab key move to a control), but will hinder them.

    The trick with this method is allowing tab clicks and disabling tab button traversal of controls.

    Another option is to just disable/hide the save buttons on each tab if you can find them.

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    Dec 16, 2009 @ 11:08
    Casey Neehouse
    0

    Ahh, great minds think alike..

    Not sure of any events, but, you may be able to loop the controls, and find them that way.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 16, 2009 @ 11:16
    Dirk De Grave
    0

    It sure's not possible in a pre 4.0.3 release, that's what's been told to me. Haven't tried to disable the save button (on the menu bar) in the v4.0.3 version tho (Can't find that tweet atm)

     

    Cheers,

    /Dirk

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Dec 16, 2009 @ 11:29
    Richard Soeteman
    1

    Hi Jeroen,

    You can disable the menubuttons  in the same event.

    Cheers,

    Richard

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 16, 2009 @ 13:21
    Jeroen Breuer
    2

    Thank you Richard you saved my day!

    Now I've got the following code:

        public class MaashorstEvents : ApplicationBase
        {

            public MaashorstEvents()
            {
                ContentControl.AfterContentControlLoad += new ContentControl.AfterContentControlLoadEventHandler(ContentControl_AfterContentControlLoad);
            }
            protected void ContentControl_AfterContentControlLoad(ContentControl contentControl, ContentControlLoadEventArgs e)
            {
                int id = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
                Document document = new Document(id);
                if (document.Creator.Id != 0)
                {
                    foreach (Control control in contentControl.Controls)
                    {
                        if (control is TabPage)
                        {
                            ((TabPage)control).Menu.Attributes["style"] = "Display: none;";
                        }
                    }
                }
            }
        }

    This code disables the entire menu if the creator of a document is not the admin (just a sample). The code isn't perfect though. ((TabPage)control).Menu is of type ScrollingMenu and in this are the save and save/publish buttons (type: MenuImageButton) but I can't seem to find them (are saved in private variables) and disable them.

    I used "Display: none;" to hide the menu because if you set visible = false the menu will not be rendered and all the richtext editor properties will be empty (probably because some tinymce things aren't rendered). Well this is a start and at least a user can now view data but not edit it :).

  • David Conlisk 432 posts 1008 karma points
    Jun 18, 2010 @ 13:22
    David Conlisk
    0

    Jereon,

    Your code gave me a good starting point for something similar. I want to hide the Save and Save and Publish buttons for all users. I decided to use some jQuery to hide the buttons from all users. Here is my code for anyone who needs it. It registers a block of jQuery that hides any editorIcon whose alt text contains the word Save - this means that Save and Save and Publish are hidden, but Preview is not.

        public class myEvents : ApplicationBase
        {
            public myEvents()
            {
                ContentControl.AfterContentControlLoad += new ContentControl.AfterContentControlLoadEventHandler(ContentControl_AfterContentControlLoad);
            }
            protected void ContentControl_AfterContentControlLoad(ContentControl contentControl, ContentControlLoadEventArgs e)
            {
                Page page = HttpContext.Current.Handler as Page;

                if (page != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<script type='text/javascript'>");
                    sb.Append(" jQuery(function(){");
                    sb.Append("     $('.editorIcon[alt~=Save]').hide();");
                    sb.Append("  });");
                    sb.Append("</script>");
                    page.RegisterStartupScript("HideSaveAndPublish", sb.ToString());
                }
            }
        }

     

    David

Please Sign in or register to post replies

Write your reply to:

Draft