|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example grants the Modify permissions permission to the CMSEditor user on document level for a single document.
private bool SetUserPermissions() { // Create an instance of the Tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get default culture code string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");
// Get the API Example document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);
if (node != null) { // Get the user UserInfo user = UserInfoProvider.GetUserInfo("CMSEditor");
if (user != null) { // Prepare allowed / denied permissions int allowed = 0; int denied = 0; allowed += Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.ModifyPermissions)));
// Create an instance of ACL provider AclProvider acl = new AclProvider(tree);
// Set user permissions acl.SetUserPermissions(node, allowed, denied, user);
return true; } }
return false; } |
The following example grants the Modify permission to the CMSEditor role on document level for a single document.
private bool SetRolePermissions() { // Create an instance of the Tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get default culture code string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");
// Get the API Example document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);
if (node != null) { // Get the role ID RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSEditor", CMSContext.CurrentSiteName);
if (role != null) { // Prepare allowed / denied permissions int allowed = 0; int denied = 0; allowed += Convert.ToInt32(Math.Pow(2, Convert.ToInt32(NodePermissionsEnum.Modify)));
// Create an instance of ACL provider AclProvider acl = new AclProvider(tree);
// Set role permissions acl.SetRolePermissions(node, allowed, denied, role.RoleID);
return true; } }
return false; } |
The following example removes all document level permissions granted to both users and roles on document level for a single document.
private bool DeletePermissions() { // Create an instance of the Tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get default culture code string culture = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSDefaultCultureCode");
// Get the API Example document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", culture);
if (node != null) { // Create an instance of ACL provider AclProvider acl = new AclProvider(tree);
// Get ID of ACL used on API Example document int nodeACLID = ValidationHelper.GetInteger(node.GetValue("NodeACLID"), 0);
// Delete all ACL items acl.ClearACLItems(nodeACLID);
return true; }
return false; } |