1

I'm trying to create a frontend interface for users to manage the permissions of some content for other users.

The code seems to work fine in theory, it executes without any errors and if I look at the items in the backend permissions view I see the permissions I expect there. However, on the view page for the item in question, the permissions don't seem to update.

I know the permissions work on the view generally because if I update them to what I expect using the interface it behaves as I expect, even though the values seem to be exactly the same.

Here's the code:

private string SetDocumentStage(Guid id, string stage, string role = "") {
    DynamicModuleManager manager = DynamicModuleManager.GetManager(providerName);
    Type itemType = TypeResolutionService.ResolveType(documentTypeName);
    DynamicContent liveItem = manager.GetDataItem(itemType, id);                    

    if(liveItem == null)
    {
        return "Item with ID {" + id.ToString() + "} not found.";
    }

    DynamicContent item = manager.Lifecycle.GetMaster(liveItem) as DynamicContent;                    

    // Before making any changes, restore inheritance so we start with a clean slate.
    manager.RestorePermissionsInheritance(item);                     

    string roleNameForView = stage == "Public" ? "Everyone" : role;

    // The default state is admin, so no further changes needed if it's admin.
    if (stage != "Admin")
    {                        
        // In non-admin stages, we should grant either everyone or the working group view permissions.
        // Then, grant just the working group modify permissions, to represent the elevated permissions they need.
        try
        {
            item.ManagePermissions().ForRole(roleNameForView).Grant().View();
            item.ManagePermissions().ForRole(role).Grant().Modify();
        } catch(Exception e)
        {
            return "Error setting permissions. Most likely the role name provided does not exist.";
        }                        
    }

    manager.SaveChanges();

    return "Successfully changed stage to " + stage + ".";
}

Any assistance anyone can provide would be appreciated.

2
  • Wonder if manager.SaveChanges() is enough. Usually you also have to publish the item after you've made changes to it. Source: progress.com/documentation/sitefinity-cms/… Commented Jun 13, 2024 at 23:37
  • 1
    It does seem like that was the issue. Do you want to submit this as an answer so I can approve it? Commented Jun 14, 2024 at 13:50

1 Answer 1

0

In addition to manager.SaveChanges() you also need to Publish the item.

ILifecycleDataItem publishedAlbumItem = dynamicModuleManager.Lifecycle.Publish(albumItem);
albumItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");

dynamicModuleManager.SaveChanges();

source: https://www.progress.com/documentation/sitefinity-cms/example-get-and-set-parent-items

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.