Rights Properties

Rights Properties

Workflow Permissions

  • The WorkflowStateWrite right did not return true when tested for the IsWorkflowStateRight property
  • The WorkflowStateDelete right did not return true when tested for the IsWorkflowStateRight property
  • The WorkflowCommandExecute right did not return true when tested for the IsWorkflowCommandRight property

Controls featured in this example:

  • Sitecore Sublayout (Web User Control)

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Security.AccessControl.AccessRight
  • Sitecore.Security.AccessControl.AccessRightCollection
  • Sitecore.Security.AccessControl.AccessRightManager
  • System.EventArgs
  • System.String
  • System.Text.StringBuilder
  • System.Web.UI.WebControls.ListItem

ASCX File Markup

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RightsProperties.ascx.cs" Inherits="Website.layouts.TIC.Sublayouts.RightsProperties" %>
<%@ register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div style="font-weight:bold; width:100%; clear:both">
    <asp:Label ID="lblHeading" runat="server" Text="C# Web Control Real-time Output" />
</div>

<div style="font-size:x-small; width:100%; clear:both">  
<div style="font-weight:bold">
    <asp:Literal ID="litItem" runat="server"></asp:Literal>
</div>
<div>
    <p><asp:Label ID="lblItem" runat="server" Text="Select an Access Right" Font-Bold="True" /></p>
</div>
<div>
<asp:DropDownList ID="ddlRights" runat="server" AutoPostBack="True" 
    Height="20px" 
    Width="214px" onselectedindexchanged="ddlRights_SelectedIndexChanged">
</asp:DropDownList>  
</div>
<div>
    <asp:Literal ID="Literal1" runat="server" />
</div>
</div>

C# User Control Code

protected void Page_Load(object sender, System.EventArgs e)
        {
Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

if (!IsPostBack)
{
    Sitecore.Security.AccessControl.AccessRightCollection rights = Sitecore.Security.AccessControl.AccessRightManager.GetAccessRights();
    if (rights == null) return;

    var sortedList = (from entry in rights orderby entry.Name ascending select entry);
    foreach (Sitecore.Security.AccessControl.AccessRight right in sortedList)
    {
        ddlRights.Items.Add(new System.Web.UI.WebControls.ListItem(right.Title, right.Name));
    }
    Sitecore.Security.AccessControl.AccessRight initialRight = Sitecore.Security.AccessControl.AccessRight.ItemRead;
    ddlRights.SelectedValue = initialRight.Name;
    ddlRights_SelectedIndexChanged(this, System.EventArgs.Empty);
}
        }

protected void ddlRights_SelectedIndexChanged(object sender, System.EventArgs e)
        {
Sitecore.Security.AccessControl.AccessRight right = null;
string selectRight = ddlRights.SelectedValue;
if (selectRight != System.String.Empty)
{
    switch (selectRight)
    { 
        case "field:read":
 right = Sitecore.Security.AccessControl.AccessRight.FieldRead;
 break;
        case "field:write":
 right = Sitecore.Security.AccessControl.AccessRight.FieldWrite;
 break;
        case "insert:show":
 right = Sitecore.Security.AccessControl.AccessRight.InsertShow;
 break;
        case "item:admin":
 right = Sitecore.Security.AccessControl.AccessRight.ItemAdmin;
 break;
        case "item:create":
 right = Sitecore.Security.AccessControl.AccessRight.ItemCreate;
 break;
        case "item:delete":
 right = Sitecore.Security.AccessControl.AccessRight.ItemDelete;
 break;
        case "item:read":
 right = Sitecore.Security.AccessControl.AccessRight.ItemRead;
 break;
        case "item:rename":
 right = Sitecore.Security.AccessControl.AccessRight.ItemRename;
 break;
        case "item:write":
 right = Sitecore.Security.AccessControl.AccessRight.ItemWrite;
 break;
        case "language:read":
 right = Sitecore.Security.AccessControl.AccessRight.LanguageRead;
 break;
        case "language:write":
 right = Sitecore.Security.AccessControl.AccessRight.LanguageWrite;
 break;
        case "site:enter":
 right = Sitecore.Security.AccessControl.AccessRight.SiteEnter;
 break;
        case "WorkflowCommand:Execute":
 right = Sitecore.Security.AccessControl.AccessRight.WorkflowCommandExecute;
 break;
        case "WorkflowState:Delete":
 right = Sitecore.Security.AccessControl.AccessRight.WorkflowStateDelete;
 break;
        case "WorkflowState:Write:":
 right = Sitecore.Security.AccessControl.AccessRight.WorkflowStateWrite;
 break;
        default:
 right = Sitecore.Security.AccessControl.AccessRight.FieldRead;
 break;
    }
}
System.Text.StringBuilder builder = new System.Text.StringBuilder();
builder.Append("Name: " + "<b>" + right.Name.ToString() + "</b><br/>");
builder.Append("Title: " + "<b>" + right.Title.ToString() + "</b><br/>");
builder.Append("Is Field Right? " + "<b>" + right.IsFieldRight.ToString() + "</b><br/>");
builder.Append("Is Item Right? " + "<b>" + right.IsItemRight.ToString() + "</b><br/>");
builder.Append("Is Language Right? " + "<b>" + right.IsLanguageRight.ToString() + "</b><br/>");
builder.Append("Is Site Right? " + "<b>" + right.IsSiteRight.ToString() + "</b><br/>");
builder.Append("Is Wildcard? " + "<b>" + right.IsWildcard.ToString() + "</b><br/>");
builder.Append("Is Workflow Command Right? " + "<b>" + right.IsWorkflowCommandRight.ToString() + "</b><br/>");
builder.Append("Is Workflow State Right? " + "<b>" + right.IsWorkflowStateRight.ToString() + "</b><br/>");
builder.Append("Modifies Data? " + "<b>" + right.ModifiesData.ToString() + "</b>");

Literal1.Text = builder.ToString();
 
        }


C# Web Control Real-time Output

Select an Access Right