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)
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;
}
}
}
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, 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.
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.
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); }
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?
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.
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?
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
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?
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.
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)
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 :).
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;
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 ?
No - you have to restore a SQL + file backup. In v4.1 there'll be a recycle bin in the Media library.
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
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:
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 :-)
Sebastiaan - this looks like exactly what I'm looking for - where do I put the event handler?
Thanks,
Olly
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.
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 : )
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.
This is how I've done it:
Very nice!
Good stuff, just what I was looking for.
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:
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?
Edit:
I'm not trying to save a document type, but a document/node.
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
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?
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
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.
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?
@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.
Ahh, great minds think alike..
Not sure of any events, but, you may be able to loop the controls, and find them that way.
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
Hi Jeroen,
You can disable the menubuttons in the same event.
Cheers,
Richard
Thank you Richard you saved my day!
Now I've got the following code:
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 :).
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.
David
is working on a reply...