This page follows the previous section's example and sets the rights, roles, and inheritance options for a user on an object.
<!-- #include file="RetrieveIStore.csp" -->
<!-- #include file=helper_js.csp -->
<!-- #include file=ceconstjs.inc -->
function SetInheritance(IStore, UserID, ReportID) {
Reports = IStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_ID="+ReportID);
SecurityInfo = Report.SecurityInfo;
// Get the ObjectPrincipal object, or create it by adding the user
Principal = SecurityInfo.ObjectPrincipals.Item("#"+UserID);
Principal = SecurityInfo.ObjectPrincipals.Add(UserID);
Principal.Role = ceRoleAdvanced;
// Set the inheritance flags according to the user's selections.
if (Request.Form.Item("InheritFromFolders") == "on") {
Principal.AdvancedInheritFolders = true;
Principal.AdvancedInheritFolders = false;
if (Request.Form.Item("InheritFromGroups") == "on") {
Principal.AdvancedInheritGroups = true;
Principal.AdvancedInheritGroups = false;
function SetRole(IStore, UserID, ReportID)
Reports = IStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_ID="+ReportID);
SecurityInfo = Report.SecurityInfo;
// Get the ObjectPrincipal object, or create it by adding the user
Principal = SecurityInfo.ObjectPrincipals.Item("#"+UserID);
Principal = SecurityInfo.ObjectPrincipals.Add(UserID);
//Assign the new role according to the user's selection.
var NewRole = parseInt(Request.Form.Item("Role"));
function SetRights(IStore, UserID, ReportID)
Reports = IStore.Query("Select TOP 1* From CI_INFOOBJECTS Where SI_ID="+ReportID);
SecurityInfo = Report.SecurityInfo;
Principal = SecurityInfo.ObjectPrincipals.Item("#" + UserID);
Principal = SecurityInfo.ObjectPrincipals.Add(UserID);
// Force Advanced rights in order to set rights explicitly.
Principal.Role = ceRoleAdvanced;
for (k=1;k<=SecurityInfo.KnownRights.Count;k++)
// Get the ID of each right that is possible for the report object.
RightID = SecurityInfo.KnownRights.Item(k).ID;
PrincipalRight = Principal.Rights.Item("#" + RightID);
// If the try block failed, the right is inherited or "Not Specified".
// Add such rights to the explicit rights collection, even if they will be removed below.
PrincipalRight = Principal.Rights.Add(RightID);
// Grant, deny, or delete the right according to the user's selection.
switch (String(Request.Form.Item(String(RightID))))
Principal.Rights.Delete("#" + RightID);
Principal.Rights.Delete("#" + RightID);
Response.Write("Could not set the right:" + SecurityInfo.KnownRights.Item(k).Description + " " + e.description + "<BR>");
Response.Redirect ("Start.csp");
UserID = parseInt(Request.QueryString.Item("UserID"));
ReportID = parseInt(Request.QueryString.Item("ReportID"));
Response.Write ("<H2>Setting rights for this user</H2><HR>");
// Call the function appropriate to the user's action.
if (Request.Form.Item("SetRole") == "Set") SetRole(IStore, UserID, ReportID);
if (Request.Form.Item("SetRights") == "Set") SetRights(IStore, UserID, ReportID);
if (Request.Form.Item("SetInheritance") == "Set") SetInheritance(IStore, UserID, ReportID);
Response.Write ("<form action='ViewRights.csp' method=post name='Rights'>");
Response.Write("<input type=hidden name='UserID' value='" + UserID + "'>");
Response.Write("<input type=hidden name='ReportID' value='" + ReportID + "'>");
Response.Write ("<input type=submit name='Back' value='View changes'>");
Crystal Decisions, Inc. http://www.crystaldecisions.com Support services: http://support.crystaldecisions.com |