Hi all,
I want custom permissions for dynamic content once created. I used IDynamicContentCreatedEvent but when login with an account custom role (not administrator), I can't create dynamic. In CMS show "Database error". Anyone help me fix this issue.
This is my code
public static void DynamicContentCreatedEventHandler(IDynamicContentCreatedEvent eventInfo) { DynamicContent dynamicContentItem = eventInfo.Item; try { var providerName = String.Empty; var transactionName = "someTransactionName"; DynamicModuleManager manager = DynamicModuleManager.GetManager(providerName, transactionName); var hospitalitem = dynamicContentItem.GetRelatedItems("hospital").FirstOrDefault() as DynamicContent; string roles = "Role1,Role2,Role3"; if (dynamicContentItem != null) { dynamicContentItem.ManagePermissions().ClearAll(); if (!string.IsNullOrEmpty(roles)) { var roleArray = roles.Split(','); var roleManager = RoleManager.GetManager(); foreach (var role in roleArray) { var roleExists = roleManager.RoleExists(role); var roleItem = roleManager.GetRole(role); if (roleExists) { try { dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Grant() .View(); dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Grant() .Delete(); dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Deny() .ChangePermissions(); dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Deny() .ChangeOwner(); dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Grant() .Modify(); dynamicContentItem.ManagePermissions() .ForRole(roleItem.Id) .Deny(). Create(); } catch (Exception ex) { Log.Write(ex.ToString()); } } } } } } catch (Exception ex) { Log.Write(ex.ToString()); } }