إضافة المتعاونين في الملاحظات وإزالتهم الذين لديهم أذونات

ويكون منشئ الملاحظة هو مالكها. يمكن للمالك إضافة حسابات أخرى المتعاونين الذين يستخدمون الأذونات الممنوحة لمستخدمين أو مجموعات فردية. يحصل المتعاونون على الإذن بتعديل الملاحظة. يمكن للمتعاونين أيضًا الأذونات التي تم إبطالها باستخدام واجهة برمجة التطبيقات. تشرح هذه الصفحة كيفية الإضافة والحذف والمتعاونين باستخدام الأذونات.

إضافة أذونات لإضافة متعاونين

يعرض النموذج التالي كيفية استخدام الأذونات على مستخدم أو مجموعة لإضافة الأذونات. المتعاونين في ملاحظة:

راحة

اتصل notes.permissions.batchCreate() مع منح الملاحظة الرئيسية الإذن وpermission. لاحظ أن يمكن إسناد الدور "WRITER" فقط إلى العضو (مستخدم، مجموعة).

Java

/**
 * 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();
}

إبطال الأذونات لإزالة المتعاونين

يعرض النموذج التالي كيفية استخدام الأذونات لإزالة جميع المتعاونين. من ملاحظة:

راحة

اتصل notes.permissions.batchDelete() مع منح الملاحظة الرئيسية الإذن وpermission.

Java

/**
 * 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();
}