问题
Team Drive has five permission levels:
- Manager
- Content Manager
- Contributor
- Commenter
- Viewer
The Folder API, on the other hand, only has three functions for getting a user list of people on a folder:
getEditors()
getOwner()
getViewers()
This works fine if you're using a My Drive, because it has those exact same three levels:
- Is Owner
- Can organize, add, & edit
- Can view only
How do I get each of the 5 access levels in a Google Team Drive? If I do call those 3 functions, which access level do they correspond to on a Team Drive? (E.g. does getEditors
return everyone in the Manager
group?)
I see there is a Permission enum with the exact 5 permissions I'm looking for:
VIEW
EDIT
COMMENT
OWNER
ORGANIZER
... and I can call getAccess() to get the access level given a User
or email
. Problem is I don't know which email
s to pass to the function.
How do I get a list of people in any of the 5 categories (e.g. Content Manager
)? Or how do I get a list of all people that are on the Team Drive (e.g. so I know which emails to use with getAccess()
)?
回答1:
Here is a summary of the mappings between the permissions given in the Team Drive UI, the corresponding getAccess()
value, and the Folder API method you can call which contains that person:
+-----------------------+-------------+-------------------+
| Team Drive Permission | getAccess() | Folder API Method |
+-----------------------+-------------+-------------------+
| Manager | ORGANIZER | (None) |
| Content Manager | NONE | (None) |
| Contributor | EDIT | getEditors() |
| Commenter | COMMENT | getViewers() |
| Viewer | VIEW | getViewers() |
| (None) | NONE | (None) |
+-----------------------+-------------+-------------------+
Some results:
- There is no way to know who is a Content Manager on the Team Drive: Notice how it returns
NONE
for both Content Managers and people who aren't on the Team Drive. It is therefore impossible to know who is a Content Manager on the Team Drive using thegetAccess()
method, even if you know the person's email address. This may be a bug in the API? - You can easily get all Contributors: Simply call the
getEditors()
method. - You can get all Commenters and Viewers, but need to use
getAccess()
too: Since both Commenters and Viewers are return viagetViewers
, you'll need to cross reference this against the results returned in getAccess() to find the actual Commenters or Viewers. - There are no API methods to get the Manager or Content Managers: None of the standard API methods that return a set of users on a Folder will return anyone in the Manager or Content Manager group. You therefore need to know the email address of the managers, and can only use getAccess() to verify that they are indeed Managers.
getOwner()
always returnsnull
. Presumably this is because there are no single owners on Team Drives. It will returnnull
even if you have exactly 1 Manager and 0 Content Managers.
Therefore, there doesn't seem to be a way to find the OWNER
s or ORGANIZER
s on a Team Drive (presumably the Managers and Content Managers, respectively) using the standard API. Instead, you must already know what the email address associated with the user is, and call getAccess()
. This is unfortunate.
I was expecting the following workaround to work:
- Create a dummy file inside the Team Drive. Since file permissions inside a Team Drive map to exactly Edit, Comment, View, the
getEditors()
method should now expose the Manager and Content Managers. Since they have the Edit permission on the file, they should presumably be returned by thegetEditors()
method.
This unfortunately didn't work either. The results were exactly the same as the folder case. The Manager and Content Manager were hidden (i.e. none of the 3 methods returned them). The Content Manager's getAccess() was still NONE, etc.
To get the list of Managers and Content Managers, then, I believe the only option is to use the advanced API. In particular, it looks like teamDrivePermissionDetails[].role
on the Permissions object returns exactly the 5 states that map to Team Drive permissions:
- organizer
- fileOrganizer
- writer
- commenter
- reader
来源:https://stackoverflow.com/questions/54189752/how-do-i-get-the-managers-contributors-etc-of-a-google-team-drive