Allow locking folder structure (allow file upload/delete but block folder deletion)

May 5, 2013 at 12:20 AM
It would be great if there was the locking feature like this:

Allow only file upload and deletion but block deleting a folder, that is, keep the folder structure defined beforehand.
May 5, 2013 at 12:36 AM
Edited May 5, 2013 at 1:10 AM
I started implementing something. See the public IsLocked property in Root.
JsonResult IDriver.Remove(IEnumerable<string> targets)
    RemoveResponse answer = new RemoveResponse();

    foreach (var item in targets)
        FullPath fullPath = ParsePath(item);

        if (fullPath.Directory != null)
            if (!fullPath.Root.IsLocked)
                 return Error.Locked(fullPath.Directory.Name);


    return Json(answer);
Added a new Error too:
public static JsonResult Locked(string target)
    return Json(new { error = new string[] { "errLocked", target } });
Of course, I'll have to apply the same check in the Rename and Move driver methods... :) The Move method is not implemented yet so there's no need to bother with it.
May 6, 2013 at 9:26 AM
Edited May 6, 2013 at 10:14 AM
Hehehe There's an even easier path to follow than what I had thought. In the method public static DTOBase Create(DirectoryInfo directory, Root root) in DTOBase.cs you already set
Locked = root.IsReadOnly ? (byte)0 : (byte)1
Write = root.IsReadOnly ? (byte)0 : (byte)1
So one only has to change Locked to use the new Root IsLocked property:
Locked = root.IsLocked? (byte)0 : (byte)1
This is great because elFinder's JavaScript client code will take care of disabling the toolbar buttons accordingly.
May 6, 2013 at 10:12 AM
I also added...

public IEnumerable<string> LockedFolders { get; set; }

in Root.cs. This way I can do a check inside public static DTOBase Create(DirectoryInfo directory, Root root):
var locked = root.IsLocked || root.LockedFolders.Any(f => f == directory.Name);
and then lock per directory! AWESOME.

I just love open source projects. :D
May 7, 2013 at 7:46 AM
Hi, Leniel

Now i start implement thumbnails generation for connector, so I add your patch a bit later. And I think to add more features for access control. Original php connector allow control access by regex, file extensions, and even by custom rules.

Anyway, thanks for patch
Jun 16, 2013 at 5:55 PM
Fixed in 33805.
Oct 17, 2013 at 7:32 PM
Edited Oct 17, 2013 at 7:34 PM

What would be even more awesome is if we could define/pass a set of folders in the root to be locked, that is, let's say we have a structure like this:


We want to make MyFolder1, MyFolder2 and MyFolder3 locked folders in MyRoot so that users can't rename or delete these folders. They are pre-defined folders used in other parts of the application. The users are allowed to add/rename/delete files in these folders though.

Note that the user is still allowed to add new folders to MyRoot and these other folders (MyFolder4 and MyFolder5) are not locked, that is, they can be renamed and deleted.
Oct 17, 2013 at 8:06 PM
Edited Oct 17, 2013 at 11:27 PM
I managed to start implementing something like this in Root.cs:
/// <summary>
/// Gets or sets a list of root subfolders that should be locked (user can't remove, rename)  
/// </summary>
public List<string> LockedFolders { get; set; }
and in DTOBase.cs change the code in
 public static DTOBase Create(DirectoryInfo directory, Root root)
accordingly inside the else like this:

Locked = (root.LockedFolders.Any(f => f == directory.Name) || root.IsLocked) ? (byte)1 : (byte)0,

and in public static DTOBase Create(FileInfo info, Root root) change it to
  response.Locked =  (root.LockedFolders.Any(f => f == info.Directory.Name) || root.IsLocked) ? (byte)1 : (byte)0;
as you see it works in conjunction with root.IsLocked.

I'll submit a patch if you want...

By the way: wouldn't you like to migrate to GitHub? It's way better/simpler than CodePlex IMHO. :) Has a lot more options when it comes to managing code bases.

In the meantime I updated the code to match ElFinder latest version and added the LockedFolders property too here:
Oct 31, 2013 at 2:25 PM
Hi, leniel, sorry for huge delay with answer, I have a vacation and can not answer :)

I thought before about this possibility before in a slightly different way. I would like to add more options to the user for control over access to folders. Most likely it is to be a interface with a callback function to verify access. Thus the user can flexibly change the settings for folders or for example for files based on their extension, name or would something else. I think it will go into release 2.0, which I plan on December 2013, together with the ASP.NET Web Forms integration and eliminating the use of FileInfo and DirectoryInfo in core of connector. And maybe next release would be on GitHub :)
Oct 31, 2013 at 3:19 PM
Great news Evgeny!!! That would be awesome to have in ElFinder.Net.

Hope you're well!

God bless,

Sep 10, 2014 at 10:45 PM
Thanks, Evgeny, for a wonderful plug-in project! This looks great.
Thanks, Leniel, for this thread on customizing rights. I used this concept and added LockedFolders and WritableFolders, modifying my copies of both DTOBase and FileSystemDriver to get what I needed.

My Company (the two below are frozen; may have more than one root/company for user)
Shared Files Folder (even though this is frozen, it is writable so can create files and subfolders which are then unlocked and writable down the line)
Read-only Reports Folder (users can't change anything, though I'll add admin user roles later who can)

I set Locked based on either being exactly on the second tier in the LockedFolders or based on the WritableFolders of this second tier when on a lower folder (in DTOBase), and the Write flag based on being on or below this second tier (in FileSystemDriver answer.Files.Add loops). Roughly: If your parent is Writable, then you are not locked plus are writable. And if you are a locked first tier (so the folder names can't change), then you are locked but still have the ability (with Writable) to allow children to be writable and unlocked.

This is not very elegant, but until there is a better way, this works for me!

Sep 16, 2014 at 1:51 AM
I have revised my alteration to use full paths, so this is now generic and much more useful than before.

It handles:

Company 1
Shared Folder
Read-only Folder
as well as

Company 1
Client 1
    Shared Folder
    Read-only Folder
Client 2

One can mark any folder so that it cannot be deleted/renamed (locked), and any as locked (or not) but allowing internal/subfolder changes. I call that writable.

Pretty nice. If you are still working on this project, I could send you the changes (as I consider this an improvement).
Sep 25, 2014 at 2:08 PM
Edited Sep 26, 2014 at 12:08 AM
Hi gcarrier,

Sorry for a big delay with answer. Thanks for your feedback. Unfortunately I have not enough time to do this project, but if you have any improvements, I think the project will only benefit from. I added the acess for you, so you can easily commit files.

P.S. If you have any questions or other ideas please feel free to email me.