Kentico CMS 6.0 Developer's Guide

Managing permission inheritance

Managing permission inheritance

Previous topic Next topic Mail us feedback on this topic!  

Managing permission inheritance

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example breaks permission inheritance on document level of a single document.

 

private bool BreakPermissionInheritance()

{

  // 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/API-Example-subpage", culture);

 

  if (node != null)

   {

      // Create an instance of ACL provider

      AclProvider acl = new AclProvider(tree);

 

      // Break permission inheritance (without copying parent permissions)

      bool copyParentPermissions = false;

       acl.BreakInherintance(node, copyParentPermissions);

 

      return true;

   }

 

  return false;

}

 

The following example restores permission inheritance on document level of a single document.

 

private bool RestorePermissionInheritance()

{

  // 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/API-Example-subpage", culture);

 

  if (node != null)

   {

      // Create an instance of ACL provider

      AclProvider acl = new AclProvider(tree);

 

      // Restore permission inheritance

       acl.RestoreInheritance(node);

 

      return true;

   }

 

  return false;

}