/** * 给某个用户针对某个文档赋予读的权限 * @param userId 用户ID * @param docId 文档ID */ public void assignReadPermissionToDocument(String userId, String docId) { Document doc = this.fetchDocumentById(docId); AccessPermissionList apl = doc.get_Permissions(); AccessPermission ap = Factory.AccessPermission.createInstance(); ap.set_GranteeName(userId); ap.set_AccessType(AccessType.ALLOW); ap.set_AccessMask(AccessLevel.VIEW_AS_INT); apl.add(ap); doc.set_Permissions(apl); doc.save(RefreshMode.REFRESH); } /** * 给某个用户针对某个文档赋予读写权限 * @param userId 用户ID * @param docId 文档ID */ public void assignRWPermissionToDocument(String userId, String docId) { Document doc = this.fetchDocumentById(docId); AccessPermissionList apl = doc.get_Permissions(); AccessPermission ap = Factory.AccessPermission.createInstance(); ap.set_GranteeName(userId); ap.set_AccessType(AccessType.ALLOW); ap.set_AccessMask(AccessLevel.MAJOR_VERSION_DOCUMENT_AS_INT); apl.add(ap); doc.set_Permissions(apl); doc.save(RefreshMode.REFRESH); } /** * Revokes a specified user's access permission from the document * * @param os * @param userId * If a user's grantee name is "[email protected]", then his user * id is "xx" * @param docId */ public void revokeAccessPermissionFromDocument(String userId, String docId) { Document doc = this.fetchCurrentVersionDocument(docId); AccessPermissionList apl = doc.get_Permissions(); for (int i = 0; i < apl.size(); i++) { AccessPermission ap = (AccessPermission) apl.get(i); String granteeName = ap.get_GranteeName().split("@")[0]; if (granteeName.equals(userId)) { apl.remove(i); } } doc.set_Permissions(apl); doc.save(RefreshMode.REFRESH); }