अनुमतियों के साथ नोट सहयोगियों को जोड़ना और हटाना

नोट बनाने वाला व्यक्ति, उसका मालिक होता है. मालिक, उपयोगकर्ताओं या ग्रुप को दी गई अनुमतियों का इस्तेमाल करके, सहयोगी जोड़ सकता है. सहयोगियों को नोट में बदलाव करने का ऐक्सेस मिल जाता है. एपीआई का इस्तेमाल करके, सहयोगी की अनुमतियां भी रद्द की जा सकती हैं. इस पेज पर, अनुमतियों का इस्तेमाल करके सहयोगियों को जोड़ने और हटाने का तरीका बताया गया है.

सहयोगियों को जोड़ने की अनुमतियां जोड़ना

यहां दिए गए सैंपल में, किसी नोट में सहयोगी जोड़ने के लिए, उपयोगकर्ता या ग्रुप के लिए अनुमतियों का इस्तेमाल करने का तरीका बताया गया है:

REST

अनुमति असाइन किए गए पैरंट नोट और permission के साथ, notes.permissions.batchCreate() को कॉल करें. ध्यान दें कि सदस्य (उपयोगकर्ता, ग्रुप) को सिर्फ़ 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 Groups 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

अनुमति वाले पैरंट नोट और permission के साथ, notes.permissions.batchDelete() को कॉल करें.

Java

/**
 * Deletes all permissions of a given note excluding the owner. The owner
 * can't 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) {
    // The note owner can't be removed from the permissions. Trying to
    // remove the owner causes an exception.
    if (!permission.getRole().equals("OWNER")) {
      permissionsToDelete.add(permission.getName());
    }
  }

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