2

好的,我正在为我们的 Intranet 编写一个 Google Apps 脚本,并且我希望能够显示 Google Drive 上文件夹中的文件列表。但是,我只想显示用户有权访问的文件。

有一个方法,getViewers,它将返回一个字符串列表:

https://developers.google.com/apps-script/class_file#getViewers

这样做的问题是,虽然它返回权限列表中个人的电子邮件地址,但它返回组名称。这不太理想,因为无法使用GroupsManager获取组对象——它只需要组 ID。

尽管如此,我还是可以做一些事情。我尝试过的一件事是:

var files = DocsList.getFolderById('0B_Zfq-SOMETHINGIJUSTMADEUP').getFiles();
for (f = 0; f < files.length; f++){
    var viewers = files[f].getViewers();
    var flag = false;
    // userGroups is the list of group objects, from this session's user
    for (i=0; i < usersGroups.length; i++){
        var groupName = userGroups[i].getName();
        if (viewers.indexOf(groupName) > -1){
            flag = true;
        }
    }
    if (flag){
        // print the link to file within the HTML template
    }
}

但是由于显而易见的原因,加载页面需要很长时间。它在 5 分钟内加载。我真正需要的是能够从该getViewers方法中获取组电子邮件地址列表。它为个人用户返回电子邮件,但为组返回组名,这似乎真的很奇怪。有谁知道任何解决方案或解决方法?

4

1 回答 1

0

Your best bet will probably be to use a cache with the groupIds mapped to group name and then use that instead of the GroupManager service otherwise it will be an age every time the script runs. Depending on how 'live' the docs list is for the Intranet site, you could speed things up also using a cache for the directory map.

If the permissions of files and directory listing are VERY changeable then the cache could be pre-populated by a helper script running on a time-based-trigger to suit your needs.

This is a good suggestion to add on the issue tracker as a Feature Request.

于 2012-12-30T12:54:37.030 回答