Example 3: Add permissions for a group of users to access a file |
This example allows access to a document for a group of users. It assumes a group and a workspace exist, the latter with a single document, and group ("mygroup") exists; these are described in the preceding example.
Resource.Workspaces workspaces = apiSession.GetWorkspacesResource(); // Create a json object for the document search, and accept its defaults. // Adjust if needed. ListDocumentsVdrJson listDocumentsJson = new ListDocumentsVdrJson(); // Make the call to get the list of documents PagingItemListJson<BaseJson> documentList = workspaces.ListDocumentsV30(roomId, listDocumentsJson);
Default to true value for all permission. Set the group name and EntityType.GROUP as well. Note the nested json objects that are created and then set on other, enclosing json objects.
PermittedEntityFromUserJson groupPermission = new PermittedEntityFromUserJson { Address = groupName, EntityType = EntityType.GROUP }; List<PermittedEntityFromUserJson> permissionsList = new List<PermittedEntityFromUserJson> { groupPermission }; // Adjust permissions as needed PermissionSetJson permissionSet = new PermissionSetJson { DownloadOriginal = YesNoDefault.YES, DownloadControlled = YesNoDefault.YES, Copy = YesNoDefault.YES, Edit = YesNoDefault.YES, Print = YesNoDefault.YES, ProgrammaticAccess = YesNoDefault.YES, Spotlight = YesNoDefault.YES, Watermark = YesNoDefault.YES }; HashSet<string> documentGuids = new HashSet<string> { myDoc.Guid }; VdrAddPermissionsJson permissionsJson = new VdrAddPermissionsJson { PermittedEntities = permissionsList, PermissionSet = permissionSet, DocumentGuids = documentGuids };
Set the document GUID from the returned document list and make the call to set the permissions. A BulkOperationResultJson is returned, which has information on the success or failure(with errors encountered) for each document in the list(which in this case was just 1).
// Add permissions
BulkOperationResultJson result =
workspaces.AddPermissionsV30(roomId, permissionsJson);