This project is read-only.

Media Library: restrict a user to a specific folder

Topics: Core, Customizing Orchard
Jan 27, 2014 at 6:43 PM
Hey all,

It was spoken about once here...

But I have a need to limit users to specific folders.
Hopefully with a token of their username.

Are there any grassroots to this effort?
Jan 28, 2014 at 8:21 AM

I have the exactly same requirement here. How could this be achieved?

Additionally it would be useful to restrict upload/media picker field to a contem item specific Directory (question found
Jan 28, 2014 at 3:02 PM
Yea, that would help me out with a few things as well.
But if I had user based media folders, I can live for now.

I'm looking into the problem now, it's going to take a custom module, but I don't think it will be that hard.
Jan 28, 2014 at 4:43 PM
Yep I need to filter the visible folder list based on user. I'm wondering whether it can be achieved with a filter or maybe overriding the media library admin controller?
Something like using this attribute on a custom controller:

[OrchardSuppressDependency("Orchard.MediaLibrary.Controllers.AdminController")] in a module maybe...?

Some investigation to be done, but if anybody stumbles on a solution to this i'd be very greatfyul for a prod in the right direction :-)
Jan 28, 2014 at 8:22 PM
It's a combination of replacing the MediaLibraryService using the OrchardSupressDependencyAttribute and adding a new permission. And some custom permission handling logic.

I'm working on it, I'll release it when I'm done.
Jan 28, 2014 at 8:31 PM
StanleyGoldman - thanks for sharing this awesome news.
Looking forward for your release.
Jan 29, 2014 at 9:05 AM
Yep Sounds good Stanley! Likewise will be much appreciated!
Jan 29, 2014 at 9:37 AM
Nailed it, that totally works! :-) good work on sussing it out Stanley! As you say, just a [OrchardSuppressDependency("Orchard.MediaLibrary.Services.MediaLibraryService")] attribute on your custom medialibraryservice and then free to tinker to our hearts content! :-)
Jan 29, 2014 at 2:01 PM
Edited Jan 29, 2014 at 2:54 PM
I got it working.
I can't release the module as a whole, as there is one small benign change to core needed to facilitate.
Hopefully I can get Sebastien to agree to it.

It overrides the MediaLibraryService and adds a new Permission: ManageAllMediaContent.

After enabling this module, it will force all users to a directory in the Media folder /Users/Username

If they are given the permission ManageAllMediaContent they will be allowed to interact with the whole Media Library.

I'm sure there is a ramification somewhere, so please test it out first.

EDIT: Updated Url
Jan 29, 2014 at 4:38 PM
Jan 29, 2014 at 10:33 PM
Hello Stanley,

thank you so much - this works excellently here.
Hope Sebastian will agree to the core changes to see this as a relased feature.
Again, great Job, thanks.
Feb 4, 2014 at 3:41 PM
Feb 8, 2014 at 1:27 AM
Mar 10, 2014 at 6:59 PM
May 26, 2014 at 11:12 PM
Edited May 26, 2014 at 11:12 PM
Hello Stanley.

still love your great module :)
I have currently an issue I am not able to solve:

when Media Library is opened for a user, the node "Recent" is automatically selected. However, not your RecentMediaItems Action is called but

And this brings up thumbnails of all Images of the root Folder and ist subfolders.

If I manually click on the "Recent" node your Action RecentMediaItems is called and everything works fine (only the recent media items of the user are shown or None for new users).

Do you have any idea? Did I miss something?

Jun 3, 2014 at 9:47 PM
My bad dude, been busy.

Will take a look later tonight.
Jun 4, 2014 at 8:42 PM
So that branch is based off the current 1.8.x and pulls in my changes needed for a "UserMediaLibrary" as well as some other MediaLibrary fixes that are kinda relevant/useful.
Jul 16, 2014 at 10:18 PM

I manually merged your changes in my 1.8.1 Installation and it works now!
Thanks a lot!
Mar 11, 2015 at 4:22 PM

just had an issue with your great module: if user Name ends with a dot . it will run into an exception when clicking on the menu item for the user media library.
Reason is that Windows trims a trailing dot while creating a Directory.

Fix in you module file UserMediaLibraryService.cs (additions are formatted in bold):
  1. in private string UserRootFolder
    return storageProvider.Combine(MainUserRootFolder, authenticatedUser.UserName_.TrimEnd('.')__);
  2. in public MediaFolder GetRootMediaFolder()
    return mediaLibraryService.GetMediaFolders(MainUserRootFolder).FirstOrDefault(folder => folder.Name == authenticatedUser.UserName_.TrimEnd('.')__);
Beside this issue module works great. Have a productive system with more than 900 users here and faced no other issues yet.
Mar 11, 2015 at 4:24 PM
the changes where not formatted bold..... I have added the two .Trim('.')