9

I would like to set access rights to allow the 'Everyone' group read access on categories using the Core Service. I don't know what values to use in the setValue method, but I guess one value is the group ID and the other is the rights?.

string categoryUri = "tcm:3-804-512";
CategoryData category = (CategoryData)client.Read(categoryUri, new ReadOptions());
AccessControlEntryData[] aclList = category.AccessControlList.AccessControlEntries;
   // How to set the access control on an entry?
6

First we get the category, and the AccessControlEntries as a list.

CategoryData category = client.Read("tcm:3-804-512", new ReadOptions());
List<AccessControlEntryData> accessControlEntries = 
                                 category.AccessControlList.AccessControlEntries.ToList();

Next we create a new AccessControlEntryData instance representing "Everyone", and assign it Read permissions.

AcessControlEntryData access = new AccessControlEntryData();
access.Trustee = new LinkToTrusteeData { IdRef = "tcm:0-1-65568" };
access.AllowedPermissions = Permissions.Read;

Next we add the new access entry to our List, and then set the List as an array back to the category's AccessControlList.AccessControlEntries property.

accessControlEntries.Add(access);
category.AccessControlList.AccessControlEntries = accessControlEntries.ToArray();

And of course finally save. :)

client.Save(category, null);

Hope that helps!

Update:

In the above example, if Everyone is already in the AccessControlEntries, your AllowedPermissions attribute will be added to the Permission flags. It does not replace the existing value, which could cause some confusion depending on what you are trying to set and whether or not it already exists. It would probably be better to check first to see if Everyone was already a part of the AccessControlEntries if you wish to fully replace the existing value.

List<AccessControlEntryData> accessControlEntries 
                         = category.AccessControlList.AccessControlEntries.ToList();
AccessControlEntryData access = accessControlEntries
                                 .Where(a => a.Trustee.Title.Equals("Everyone"))
                                 .FirstOrDefault();

if (access == null)
{
    access = new AccessControlEntryData();
    access.Trustee = new LinkToTrusteeData { IdRef = "tcm:0-1-65568" };
    accessControlEntries.Add(access);
}
access.AllowedPermissions = Permissions.Read;

category.AccessControlList.AccessControlEntries = accessControlEntries.ToArray();

If you wish to remove an entry, you can actually set the permissions to None;

access.AllowedPermissions = Permissions.None;

Also for anyone reading this who hasn't worked with Bit Flags, you can set multiple permissions like this:

access.AllowedPermissions = Permissions.Read | Permissions.Write;
  • One thing to note here in 2011 is if you remove a permission in the GUI the AccessControlEntryData still has the items you removed in there - just with no permissions. – Neil Mar 20 '14 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.