|
API examples for newer versions
Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.
|
The following example assigns a specific role to a widget (the widget will be usable by users belonging to the given role).
private bool AddWidgetToRole()
{
// Get role, widget and permission object
RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMSContext.CurrentSiteID);
WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");
PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AllowedFor", "Widgets", null);
// If all exist
if ((role != null) && (widget != null) && (permission != null))
{
// Add role to widget
WidgetRoleInfoProvider.AddRoleToWidget(role.RoleID, widget.WidgetID, permission.PermissionId);
return true;
}
return false;
}
|
The following example removes the relationship between a specific role and a widget.
private bool RemoveWidgetFromRole()
{
// Get role, widget and permission object
RoleInfo role = RoleInfoProvider.GetRoleInfo("CMSDeskAdmin", CMSContext.CurrentSiteID);
WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");
PermissionNameInfo permission = PermissionNameInfoProvider.GetPermissionNameInfo("AllowedFor", "Widgets", null);
// If all exist
if ((role != null) && (widget != null) && (permission != null))
{
// Remove role from widget
WidgetRoleInfoProvider.RemoveRoleFromWidget(role.RoleID, widget.WidgetID, permission.PermissionId);
return true;
}
return false;
}
|
The following example sets the security level for a widget (allows it to be used by all authenticated users).
private bool SetSecurityLevel()
{
// Get widget object
WidgetInfo widget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget");
// If widget exists
if (widget != null)
{
// Set security access type
widget.AllowedFor = SecurityAccessEnum.AuthenticatedUsers;
WidgetInfoProvider.SetWidgetInfo(widget);
return true;
}
return false;
}
|