November Happy Hour will be moved to Thursday December 5th.

Media content access not updating via code

Vote:
 

Hey, I am trying to update the permission for media uploaded, via code. During debugging I can see it's showing me the updated values. But I guess I am doing something wrong while saving the persmission. Please see below code and let me know what wrong here or how I can fix it.

// Here type of mediaReference is ContentReference and _securityRepository is IContentSecurityRepository

var mediaSecurityDescriptor = _securityRepository.Get(mediaReference).CreateWritableClone() as IContentSecurityDescriptor;
if (mediaSecurityDescriptor != null)
{
    if (mediaSecurityDescriptor.IsInherited) mediaSecurityDescriptor.ToLocal();
    mediaSecurityDescriptor.AddEntry(new AccessControlEntry("Everyone", AccessLevel.Read, SecurityEntityType.Role));
    _securityRepository.Save(mediaReference, mediaSecurityDescriptor, SecuritySaveType.None);
}

See the below screenshot, in which it's clearly visible the the values are updating. I add the Everyone role which on added as permission in CMS.

 

This is after updates

 

Please advice why it's not updating.

#333603
Nov 29, 2024 18:20
Vote:
 

Hi Praful.

I suspect you need to use "SecuritySaveType.Replace" rather than "None" or "MergeChildPermissions" so the line where you save the permissions would become:

_securityRepository.Save(mediaReference, mediaSecurityDescriptor, SecuritySaveType.Replace);
#333721
Dec 02, 2024 14:51
Praful Jangid - Dec 04, 2024 11:46
Hey Paul, this worked for me.
Not sure how I missed it. I remember I tested with all the options. But probably I may have been checking permission on wrong item before. :D
Thanks for help.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.