SP へSecurableObject オブジェクト (sp.js)

セキュリティの権限を割り当てることができるオブジェクトです。

**適用対象:**apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.SecurableObject()

メンバー

SecurableObjectオブジェクトでは、次のメンバーがあります。

Constructor

SecurableObjectオブジェクトでは、次のコンスがあります。

コンストラクター

説明

SecurableObject

Initializes a new instance of the SP.SecurableObject object.

メソッド

SecurableObjectオブジェクトでは、次の方法があります。

メソッド

説明

breakRoleInheritance

Creates unique role assignments for the securable object.

initPropertiesFromJson

resetRoleInheritance

Resets the role inheritance for the securable object and inherits role assignments from the parent securable object.

プロパティ

SecurableObjectオブジェクトでは、次のプロパティがあります。

プロパティ

説明

firstUniqueAncestorSecurableObject

Gets the object where role assignments for this object are defined.

hasUniqueRoleAssignments

Gets a value that specifies whether the role assignments are uniquely defined for this securable object or inherited from a parent securable object.

roleAssignments

Gets the role assignments for the securable object.

注釈

既定のスカラー プロパティの種類を設定するのには、 HasUniqueRoleAssignmentsプロパティが含まれていません。

次の例では、新しいアクセス許可レベルを作成し、そのアクセス許可レベルに特定のリストにユーザーを追加するアプリケーション ページの [入力] ボタンを作成します。

<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 a securable object to work with (the Announcements list), and use the SecurableObject.BreakPermissions method to break permissions so they can be managed directly.
       var listSecurableObject = site.get_lists().getByTitle('Announcements');
       listSecurableObject.breakRoleInheritance(true, false);

       // Use the SecurableObject.roleAssignments property to get the RoleAssignmentCollection for the list.
       var assignments = listSecurableObject.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>