เพิ่มและลบผู้ทำงานร่วมกันในโน้ตที่มีสิทธิ์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ผู้สร้างโน้ตจะเป็นเจ้าของโน้ตนั้น เจ้าของสามารถเพิ่มผู้ทำงานร่วมกันคนอื่นๆ โดยใช้สิทธิ์ที่มอบให้แก่ผู้ใช้หรือกลุ่มบุคคล
ผู้ทำงานร่วมกันจะได้รับสิทธิ์แก้ไขโน้ต นอกจากนี้ คุณยังเพิกถอนสิทธิ์ของผู้ทำงานร่วมกันได้โดยใช้ API หน้านี้อธิบายวิธีเพิ่มและลบผู้ทำงานร่วมกันโดยใช้สิทธิ์
เพิ่มสิทธิ์ในการเพิ่มผู้ทำงานร่วมกัน
ตัวอย่างต่อไปนี้แสดงวิธีใช้สิทธิ์ในผู้ใช้หรือกลุ่มเพื่อเพิ่มผู้ทำงานร่วมกันในหมายเหตุ
REST
เรียกใช้ 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();
}
เพิกถอนสิทธิ์เพื่อนำผู้ทำงานร่วมกันออก
ตัวอย่างต่อไปนี้แสดงวิธีใช้สิทธิ์เพื่อนำผู้ทำงานร่วมกันทั้งหมดออกจากโน้ต
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();
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-03-11 UTC
[null,null,["อัปเดตล่าสุด 2025-03-11 UTC"],[],[],null,["# Add and remove note collaborators with permissions\n\nThe creator of a note is the owner of that note. The owner can add other\ncollaborators using permissions granted to individual users or groups.\nCollaborators gain edit access to the note. Collaborators can also have their\npermissions revoked using the API. This page explains how to add and delete\ncollaborators using permissions.\n\nAdd permissions to add collaborators\n------------------------------------\n\nThe following sample shows how to use permissions on a user or group to add\ncollaborators to a note: \n\n### REST\n\nCall\n[notes.permissions.batchCreate()](/workspace/keep/api/reference/rest/v1/notes.permissions/batchCreate)\nwith the parent note assigned the permission and `permission`. Note that the\nmember (user, group) can only be assigned the `WRITER` role.\n\n### Java\n\n /**\n * Grants write access to a user and to a Google group for the given note.\n *\n * @param note The note whose permissions will be updated.\n * @param userEmail Email address of the user that will be added to the permissions of the note.\n * @param groupEmail Email address of the Google group that will be added to the permissions of\n * the note.\n * @throws IOException\n * @return The response of the create permissions request.\n */\n private BatchCreatePermissionsResponse addPermissions(\n Note note, String userEmail, String groupEmail) throws IOException {\n String noteName = note.getName();\n CreatePermissionRequest userPermission =\n new CreatePermissionRequest()\n .setParent(noteName)\n .setPermission(new Permission().setEmail(userEmail).setRole(\"WRITER\"));\n\n CreatePermissionRequest groupPermission =\n new CreatePermissionRequest()\n .setParent(noteName)\n .setPermission(new Permission().setEmail(groupEmail).setRole(\"WRITER\"));\n\n BatchCreatePermissionsRequest batchCreatePermissionsRequest =\n new BatchCreatePermissionsRequest()\n .setRequests(Arrays.asList(userPermission, groupPermission));\n\n return keepService\n .notes()\n .permissions()\n .batchCreate(noteName, batchCreatePermissionsRequest)\n .execute();\n }\n\nRevoke permissions to remove collaborators\n------------------------------------------\n\nThe following sample shows how to use permissions to remove all collaborators\nfrom a note: \n\n### REST\n\nCall\n[notes.permissions.batchDelete()](/workspace/keep/api/reference/rest/v1/notes.permissions/batchDelete)\nwith the parent note assigned the permission and `permission`.\n\n### Java\n\n /**\n * Deletes all permissions of a given note excluding the owner. Owner of the note cannot be\n * removed from a note's permissions.\n *\n * @param note The note whose permissions will be deleted.\n * @throws IOException\n */\n private void deletePermissions(Note note) throws IOException {\n List\u003cPermission\u003e notePermissions =\n keepService.notes().get(note.getName()).execute().getPermissions();\n\n // List of users, groups or families that will be deleted from the permissions of the note.\n List\u003cString\u003e permissionsToDelete = new ArrayList\u003c\u003e();\n\n for (Permission permission : notePermissions) {\n // Note owner cannot be removed from the permissions of the note. Trying to remove the note\n // owner from the permissions will cause an exception.\n if (!permission.getRole().equals(\"OWNER\")) {\n permissionsToDelete.add(permission.getName());\n }\n }\n\n keepService\n .notes()\n .permissions()\n .batchDelete(\n note.getName(), new BatchDeletePermissionsRequest().setNames(permissionsToDelete))\n .execute();\n }"]]