SP.RoleDefinition object
Defines a single role definition, including a name, description, and set of rights.
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
var object = new SP.RoleDefinition()
Members
The RoleDefinition object has the following members.
Constructor
The RoleDefinition object has the following constructor.
Constructor |
Description |
---|---|
Initializes a new instance of the SP.RoleDefinition object. |
Methods
The RoleDefinition object has the following methods.
Method |
Description |
---|---|
Deletes the role definition. |
|
Updates the role definition with changes that have been made to its properties. |
Properties
The RoleDefinition object has the following properties.
Property |
Description |
---|---|
Gets or sets a value that specifies the base permissions for the role definition. |
|
Gets or sets a value that specifies the description of the role definition. |
|
Gets a value that specifies whether the role definition is displayed. |
|
Gets a value that specifies the Id of the role definition. |
|
Gets or sets a value that specifies the role definition name. |
|
Gets or sets a value that specifies the order position of the object in the site collection Permission Levels page. |
|
Gets a value that specifies the type of the role definition. |
Example
The following example creates an input button on an application page that creates a new permission level and adds a user to a specific list with that permission level.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">
function runCode() {
var clientContext = new SP.ClientContext();
var siteColl = clientContext.get_site();
var site = clientContext.get_web();
// Set up permissions.
var permissions = new SP.BasePermissions();
permissions.set(SP.PermissionKind.viewListItems);
permissions.set(SP.PermissionKind.addListItems);
permissions.set(SP.PermissionKind.editListItems);
permissions.set(SP.PermissionKind.deleteListItems);
// Create a new role definition.
var roleDefinitionCreationInfo = new SP.RoleDefinitionCreationInformation();
roleDefinitionCreationInfo.set_name('Manage List Items');
roleDefinitionCreationInfo.set_description('Allows a user to manage list items');
roleDefinitionCreationInfo.set_basePermissions(permissions);
var roleDefinition = siteColl.get_rootWeb().get_roleDefinitions().add(roleDefinitionCreationInfo);
// Create a new RoleDefinitionBindingCollection.
var newBindings = SP.RoleDefinitionBindingCollection.newObject(clientContext);
// Add the role to the collection.
newBindings.add(roleDefinition);
// Get the list to work with and break permissions so its permissions can be managed directly.
var targetList = site.get_lists().getByTitle('Announcements');
targetList.breakRoleInheritance(true, false);
// Get the RoleAssignmentCollection for the target list.
var assignments = targetList.get_roleAssignments();
// Add the user to the target list and assign the use to the new RoleDefinitionBindingCollection.
var roleAssignment = assignments.add(site.get_currentUser(), newBindings);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Security modified');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<input id="Button1" type="button" value="Run Code" onclick="runCode()" />
</asp:Content>
REST resource endpoint
See RoleDefinition resource for more information.
Endpoint URI structure
http://<sitecollection>/<site>/_api/web/roledefinitions(roledefinitionid)
HTTP requests
This resource supports the following HTTP commands:
DELETE syntax
DELETE http://<sitecollection>/<site>/_api/web/roledefinitions(roledefinitionid)
MERGE syntax
MERGE http://<sitecollection>/<site>/_api/web/roledefinitions(roledefinitionid)
POST syntax
POST http://<sitecollection>/<site>/_api/web/roledefinitions(roledefinitionid)
PUT syntax
PUT http://<sitecollection>/<site>/_api/web/roledefinitions(roledefinitionid)