I am building a custom module and as part of the installation I'd like to create a set of secure folders in the portal directory. I have used code from previous questions to create the folder, but then the problem arises when I try to set the permissions.
I am creating a folder like so:
var portalSettings = PortalController.Instance.GetCurrentPortalSettings();
var folderMapping = FolderMappingController.Instance.GetFolderMapping(portalSettings.PortalId, "Secure");
var folder = FolderManager.Instance.AddFolder(new FolderMappingInfo
{
FolderProviderType = folderMapping.FolderProviderType,
FolderMappingID = folderMapping.FolderMappingID,
Priority = folderMapping.Priority,
PortalID = portalSettings.PortalId,
}, folderPath);
To set permissions, it seems that the FolderPermissionController has been deprecated and replaced with the new FolderManager provider. However, the FolderManager provider only has a SetFolderPermission method to create new permissions and one to AddAllUserReadPermission, but not one to remove any permissions.
After I create the folder, I give registered users view permissions like so:
var permissionController = new PermissionController();
var readPermission = permissionController.GetPermissionByCodeAndKey("SYSTEM_FOLDER", "READ").Cast
().Single();
var registeredUserRole = new RoleController().GetRoleByName(folder.PortalID, "Registered Users");
var allUserRole = new RoleController().GetRoleByName(folder.PortalID, "All Users");
FolderManager.Instance.SetFolderPermission(folder, readPermission.PermissionID, registeredUserRole.RoleID);
But I can't seem to remove permissions, and the default seems to add view permissions to ALL USERS when the folder is created. So I tried something like this that didn't work:
FolderManager.Instance.SetFolderPermission(folder, -1, allUserRole.RoleID);
When I try and use the deprecated FolderPermissionController to add or remove any permissions, it doesn't make any changes.
So, in short, what interface should be used to change folder permissions and how can you remove permissions for secure and regular folders?