Sitefinity 对动态内容项设置权限不起作用

问题描述 投票:0回答:1

我正在尝试为用户创建一个前端界面来管理其他用户的某些内容的权限。

该代码在理论上似乎工作正常,它执行时没有任何错误,如果我查看后端权限视图中的项目,我会看到我期望的权限。但是,在相关项目的查看页面上,权限似乎没有更新。

我知道权限通常在视图上起作用,因为如果我使用界面将它们更新为我期望的内容,它就会按照我的预期运行,即使这些值似乎完全相同。

这是代码:

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 + ".";
}

任何人可以提供的任何帮助将不胜感激。

c# permissions sitefinity
1个回答
0
投票

除了 manager.SaveChanges() 之外,您还需要发布项目。

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

dynamicModuleManager.SaveChanges();

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

© www.soinside.com 2019 - 2024. All rights reserved.