Quantcast
Channel: Forum
Viewing all articles
Browse latest Browse all 3613

Programmatically setting access rights for assets folder

$
0
0

Is there a way to programmatically restrict access to a assets folder?

I have tried the following code, which didn't affect the access rights:

var folder = _repository.GetDefault<ContentFolder>(SiteDefinition.Current.GlobalAssetsRoot);
folder.Name = "Restricted folder";
var contentReference = _repository.Save(folder, SaveAction.Publish, AccessLevel.NoAccess);
var folderSecurity = _securityRepository.Get(contentReference).CreateWritableClone() as IContentSecurityDescriptor;
if (folderSecurity != null)
{
    if (folderSecurity.IsInherited) folderSecurity.ToLocal();
    var webadminAccess = folderSecurity.Entries.SingleOrDefault(e => e.Name == "WebAdmins");
    if (webadminAccess != null) folderSecurity.RemoveEntry(webadminAccess);
    folderSecurity.AddEntry(new AccessControlEntry("WebAdmins", AccessLevel.Read));
    _securityRepository.Save(contentReference, folderSecurity, SecuritySaveType.ReplaceChildPermissions);
}

    


Viewing all articles
Browse latest Browse all 3613

Latest Images

Trending Articles



Latest Images