Search code examples
imageumbraco7

Umbraco 7 protect images


If building an intranet, we would want users to be able to upload images for their own documents (eg, news items, blog entries and so on). However, access to media seems to allow users to also replace images on existing media.

Therefore, they could presumably replace furniture (eg, site logo etc) as these would all be in the media folder.

I understand that users can be given a starting folder for the media tree (similar to that for editing documents), however, this would mean editing every single user to set their starting point, as there doesn't seem to be any way of doing this en masse eg by roles or user grouping.

Is there another solution, eg saving furniture in another way so that only admins can edit them?


Solution

  • As far as I know, there isn't a way to assign actual rights to media items or folders.

    But actually, if you have a sure fire way of knowing which starting node to assign to which users, it's not that tricky to do it programmatically:

    var userService = UmbracoContext.Current.Application.Services.UserService;
    var mediaService = UmbracoContext.Current.Application.Services.MediaService;
    int total;
    
    foreach (var user in userService.GetAll(0, 1000, out total))
    {
        int targetMediaId = 0;
    
        switch(user.UserType.Id)
        {
            case 123:
                targetMediaId = 3;
                break;
            case 234:
                targetMediaId = 5;
                break;
        }
        user.StartMediaId = targetMediaId;
    
        userService.Save(user);
    }
    

    I've used UserType as an example of how you might know what to assign to who, as I don't know how you'll tell in the end. In principal you could "easily" go as far as, I dunno, create a media folder per user and assign it as their starting media node.