권한이 있는 메모 공동작업자 추가 및 삭제

메모 작성자는 메모의 소유자입니다. 소유자는 다른 사용자를 추가할 수 있습니다. 개별 사용자 또는 그룹에 부여된 권한을 사용하여 공동작업자를 추가할 수 있습니다. 공동작업자에게는 메모에 대한 수정 액세스 권한이 부여됩니다. 또한 공동작업자는 권한이 취소되었습니다. 이 페이지에서는 추가 및 삭제 방법을 설명합니다. 공유할 수 있습니다.

공동작업자를 추가할 권한 추가

다음 샘플은 사용자 또는 그룹에 권한을 사용하여 공동작업자를 메모에 추가합니다.

REST

전화걸기 notes.permissions.batchCreate() 권한이 할당된 상위 메모와 permission가 있습니다. 참고: 구성원 (사용자, 그룹)에게는 WRITER 역할만 할당할 수 있습니다.

자바

/**
 * Grants write access to a user and to a Google group for the given note.
 *
 * @param note The note whose permissions will be updated.
 * @param userEmail Email address of the user that will be added to the permissions of the note.
 * @param groupEmail Email address of the Google group that will be added to the permissions of
 *     the note.
 * @throws IOException
 * @return The response of the create permissions request.
 */
private BatchCreatePermissionsResponse addPermissions(
    Note note, String userEmail, String groupEmail) throws IOException {
  String noteName = note.getName();
  CreatePermissionRequest userPermission =
      new CreatePermissionRequest()
          .setParent(noteName)
          .setPermission(new Permission().setEmail(userEmail).setRole("WRITER"));

  CreatePermissionRequest groupPermission =
      new CreatePermissionRequest()
          .setParent(noteName)
          .setPermission(new Permission().setEmail(groupEmail).setRole("WRITER"));

  BatchCreatePermissionsRequest batchCreatePermissionsRequest =
      new BatchCreatePermissionsRequest()
          .setRequests(Arrays.asList(userPermission, groupPermission));

  return keepService
      .notes()
      .permissions()
      .batchCreate(noteName, batchCreatePermissionsRequest)
      .execute();
}

공동작업자를 삭제할 수 있는 권한 취소

다음 샘플은 권한을 사용하여 모든 공동작업자를 삭제하는 방법을 보여줍니다. 메모:

REST

전화걸기 notes.permissions.batchDelete() 권한이 할당된 상위 메모와 permission

자바

/**
 * Deletes all permissions of a given note excluding the owner. Owner of the note cannot be
 * removed from a note's permissions.
 *
 * @param note The note whose permissions will be deleted.
 * @throws IOException
 */
private void deletePermissions(Note note) throws IOException {
  List<Permission> notePermissions =
      keepService.notes().get(note.getName()).execute().getPermissions();

  // List of users, groups or families that will be deleted from the permissions of the note.
  List<String> permissionsToDelete = new ArrayList<>();

  for (Permission permission : notePermissions) {
    // Note owner cannot be removed from the permissions of the note. Trying to remove the note
    // owner from the permissions will cause an exception.
    if (!permission.getRole().equals("OWNER")) {
      permissionsToDelete.add(permission.getName());
    }
  }

  keepService
      .notes()
      .permissions()
      .batchDelete(
          note.getName(), new BatchDeletePermissionsRequest().setNames(permissionsToDelete))
      .execute();
}