List Access Rights

List Access Rights

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil
  • System.Xml.XmlNode
  • System.Xml.XmlNodeList
  • System.Xml.XmlAttribute

Configuration Settings

<configuration>
<sitecore>
<accessRights>
<rights defaultType="Sitecore.Security.AccessControl.AccessRight, Sitecore.Kernel">
        <add name="field:read" comment="Read right for fields." title="Field Read" />
        <add name="field:write" comment="Write right for fields." title="Field Write" modifiesData="true" />
        <add name="item:read" comment="Read right for items." title="Read" />
        <add name="item:write" comment="Write right for items." title="Write" modifiesData="true" />
        <add name="item:rename" comment="Rename right for items." title="Rename" modifiesData="true" />
        <add name="item:create" comment="Create right for items." title="Create" modifiesData="true" />
        <add name="item:delete" comment="Delete right for items." title="Delete" modifiesData="true" />
        <add name="item:admin" comment="Admin right for items." title="Administer" modifiesData="true" />
        <add name="language:read" comment="Read right for languages." title="Language Read" />
        <add name="language:write" comment="Write right for languages." title="Language Write" modifiesData="true" />
        <add name="site:enter" comment="The right to enter a site." title="Site Enter" />
        <add name="insert:show" comment="Determines if the user can see the insert option" title="Show in Insert" />
        <add name="workflowState:delete" comment="The right to delete an item based on its workflow state." title="Workflow State Delete" />
        <add name="workflowState:write" comment="The right to write an item based on its workflow state." title="Workflow State Write" modifiesData="true" />
        <add name="workflowCommand:execute" comment="The right to execute a workflow command." title="Workflow Command Execute" />
        <add name="*" comment="Wildcard right. For internal use only." />
</rights>

C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

string accessRights = "/sitecore/accessRights/rights";
System.Xml.XmlNode accessRightsNode = Sitecore.Configuration.Factory.GetConfigNode(accessRights, true);
if (accessRightsNode == null) return;

System.Xml.XmlNodeList accessRightsList = accessRightsNode.ChildNodes;
if (accessRightsList == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string itemName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", itemName);
output.RenderEndTag(); //P

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Border, "0");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Cellpadding, "2");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Table);
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Thead);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Name");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Title");
output.RenderEndTag(); //Th
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Th);
output.Write("Description");
output.RenderEndTag(); //Th
output.RenderEndTag(); //Thead
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tbody);

foreach (System.Xml.XmlNode accessRight in accessRightsList)
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Tr);
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    System.Xml.XmlAttribute attribName = accessRight.Attributes["name"];
    if (attribName != null)
        output.Write("{0}", attribName.Value);
    output.RenderEndTag(); //Td

    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    System.Xml.XmlAttribute attribTitle = accessRight.Attributes["title"];
    if (attribTitle != null)
        output.Write("{0}", attribTitle.Value);
    output.RenderEndTag(); //Td
    
    output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Align, "left");
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Td);
    System.Xml.XmlAttribute attribComment = accessRight.Attributes["comment"];
    if (attribComment != null)
        output.Write("{0}", attribComment.Value);
    output.RenderEndTag(); //Td
    output.RenderEndTag(); //Tr
}
output.RenderEndTag(); //Tbody
output.RenderEndTag(); //Table
output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: List Access Rights

Name Title Description
field:read Field Read Read right for fields.
field:write Field Write Write right for fields.
item:read Read Read right for items.
item:write Write Write right for items.
item:rename Rename Rename right for items.
item:create Create Create right for items.
item:delete Delete Delete right for items.
item:admin Administer Admin right for items.
language:read Language Read Read right for languages.
language:write Language Write Write right for languages.
site:enter Site Enter The right to enter a site.
insert:show Show in Insert Determines if the user can see the insert option
workflowState:delete Workflow State Delete The right to delete an item based on its workflow state.
workflowState:write Workflow State Write The right to write an item based on its workflow state.
workflowCommand:execute Workflow Command Execute The right to execute a workflow command.
profile:customize Customize Profile Key Values The right to input out of range values of profile keys, that belong to this profile.
* Wildcard right. For internal use only