Kentico CMS 6.0 Developer's Guide

Managing project security

Managing project security

Previous topic Next topic Mail us feedback on this topic!  

Managing project security

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 configures the security settings of a project.

 

private bool SetSecurity()
{

  // Get the project
  ProjectInfo project = ProjectInfoProvider.GetProjectInfo("MyNewProject", CMSContext.CurrentSiteID, 0);

 
    if (project != null)
    {
        // Set properties
        project.AllowCreate = SecurityAccessEnum.AllUsers;
        project.AllowDelete = SecurityAccessEnum.Owner;
        project.AllowRead = SecurityAccessEnum.AuthorizedRoles;
 
        ProjectInfoProvider.SetProjectInfo(project);
 
        return true;
    }
 
    return false;
}

 

The following example assigns a project permission to a role.

 

private bool AddAuthorizedRole()
{

  // Get the project
  ProjectInfo project = ProjectInfoProvider.GetProjectInfo("MyNewProject", CMSContext.CurrentSiteID, 0);
  RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMSContext.CurrentSiteID);
  PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AccessToProject","ProjectManagement",null);

 
    if ((project != null) && (role != null) && (permission != null))
    {

      // Add relationship
      ProjectRolePermissionInfoProvider.AddRelationship(project.ProjectID, role.RoleID, permission.PermissionId);

 
        return true;
    }
 
    return false;
}

 

The following example removes a project permission from a role.

 

private bool RemoveAuthorizedRole()
{

  // Get the project
  ProjectInfo project = ProjectInfoProvider.GetProjectInfo("MyNewProject", CMSContext.CurrentSiteID, 0);
  RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMSContext.CurrentSiteID);
  PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AccessToProject", "ProjectManagement", null);

 

    if ((project != null) && (role != null) && (permission != null))
    {

      // Remove relationship
      ProjectRolePermissionInfoProvider.RemoveRelationship(project.ProjectID, role.RoleID, permission.PermissionId);

            
        return true;
    }
 
    return false;
}