1

我正在尝试编写一个脚本,该脚本采用文件夹的当前编辑器并将其权限更改为仅在最低级别的文件夹中查看。一切正常,除了似乎将顶部文件夹(仅查看)的权限应用到所有子文件夹所需的时间太长。正因为如此,TOP_FOLDER 的编辑器(由于它是从 TOP_FOLDER 继承的,因此最初对所有子文件夹具有编辑访问权限)在我运行脚本时保留此访问权限,即使当我在 Drive 中执行完全相同的操作时他们都具有 View只有在我刷新页面后才能访问。

有没有人对如何解决这个问题有任何想法?

function fixFilePermissions() {

  var oldEditors = TOP_FOLDER.getEditors();

  TOP_FOLDER.addEditors(ADMINS);

  //remove All but the admins
  for each (var editor in oldEditors){
    //if editor is not an admin
    if(ADMINS.indexOf(editor) < 0){
      //remove editor
      TOP_FOLDER.removeEditor(editor);
      //add back as viewer
      TOP_FOLDER.addViewer(editor);
    }
  }

  recFixFilePermissions(TOP_FOLDER);

}


function recFixFilePermissions(folder){

  while(folder.getEditors().length > ADMINS.length){
    Utilities.sleep(200);
    Logger.log(folder.getEditors().length - ADMINS.length);
  }

  Logger.log("Folder: "+folder.getName());
  Logger.log("Editors: "+folder.getEditors());
  Logger.log("Viewers: "+folder.getViewers());


  if(folder.getFolders().length > 0){

    for each (subfolder in folder.getFolders()){
      recFixFilePermissions(subfolder);
    }

    Logger.log("Has Subfolder");    

  }else{

    for each (var person in folder.getViewers()){
      folder.addEditor(person);
      Logger.log("Gave " + person + " Edit Access to " + folder.getName());
    }
  }

}
4

0 回答 0