3

I am trying to add a new Group to an existing Publication and assign Component Management permission as shown in the snippet below.

While using the below mentioned code I do not receive any error but the security Group is not added to the access control list of the Publication.

PublicationData oPublicationData = (PublicationData)client.Read(
                                                      publicationId, new ReadOptions());
PublicationData pubData = SetRightsOnPublication(oPublicationData, trustee, 
                                                      Rights.ComponentManagement);
client.Update(pubData, new ReadOptions());

public static PublicationData SetRightsOnPublication(PublicationData oPublicationData, 
              TrusteeData trusteeId, Rights allowedRights, Rights deniedRights = Rights.None)
{
    var entries = oPublicationData.AccessControlList.AccessControlEntries.ToList();
    // First check if this trustee already has some permissions
    var entry = entries.SingleOrDefault(ace => ace.Trustee.IdRef == trusteeId.Id);
    if (entry != null)
    {
        // Remove this entry
        entries.Remove(entry);
    }

    entries.Add(new AccessControlEntryData
    {
        AllowedRights = allowedRights,
        DeniedRights = deniedRights,
        Trustee = new LinkToTrusteeData { IdRef = trusteeId.Id, Title = trusteeId.Title, 
                                          Description = trusteeId.Description }});
    oPublicationData.AccessControlList.AccessControlEntries = entries.ToArray();
    return oPublicationData;
}
3
  • Did you try to debug and check ? Nov 13, 2017 at 12:53
  • The logic looks very close to what I wrote in this blog post a while ago. blog.indivirtual.nl/… The only obvious difference is that I use Save instead of Update. That's probably better for a publication, because it's not versioned, but I don't expect that to be the problem. Maybe worth trying though. Nov 13, 2017 at 18:59
  • @DominicCronin... thank you for your reply and i did take help from what you wrote in the blog... i also tried using client.save but , that also did not work for me . Do you think i am missing something else here ?
    – akhila
    Nov 14, 2017 at 4:00

1 Answer 1

3

I have been struggling with a similar issue when setting permissions. The example from the link provided by Dominic led me in the right direction. I finally figured out when populating the new ArrayOfAccessControlEntryData object, new AccessControlEntryData objects have to be created. This is very strange, but if populated with the existing objects from the list, the changes were not saved into SDL. I assume the same issue could be true for setting rights on a publication.

See below for a working solution in a Java client:

    private void setOrganizationalItemPermissionsForTrustee(OrganizationalItemData organizationalItem, String trusteeId, String[] permissions) {
        // Create new access control entries array
        ArrayOfAccessControlEntryData accessControlEntries = new ArrayOfAccessControlEntryData();

        // Populate new access control entries array with access control entries we do not change
        organizationalItem.getAccessControlList().getAccessControlEntries().getAccessControlEntryData()
            .stream()
            .filter(p -> !p.getTrustee().getIdRef().equals(trusteeId))
            .forEach(p -> {
                // We have to create new AccessControlEntryData objects, otherwise changes are not saved :/
                AccessControlEntryData accessControlEntry = new AccessControlEntryData();
                accessControlEntry.setTrustee(p.getTrustee());
                accessControlEntry.getAllowedPermissions().addAll(p.getAllowedPermissions());
                accessControlEntries.getAccessControlEntryData().add(accessControlEntry);
            });

        // Create access control entry with new/updated permissions for provided trustee
        LinkToTrusteeData trustee = new LinkToTrusteeData();
        trustee.setIdRef(trusteeId);

        AccessControlEntryData updatedAccessControlEntry = new AccessControlEntryData();
        updatedAccessControlEntry.setTrustee(trustee);
        updatedAccessControlEntry.getAllowedPermissions().addAll(Arrays.asList(permissions));

        accessControlEntries.getAccessControlEntryData().add(updatedAccessControlEntry);

        // Set newly created access control entries array on organizational item
        organizationalItem.getAccessControlList().setAccessControlEntries(accessControlEntries);

        this.coreService.save(organizationalItem);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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