Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

OK, I've looked everywhere for the answer for this and don't seem to be able to find it.

We are trying to get our Google Drive organised so that the right people get access to the right things without a lot of explicit sharing. We have a top-level folder called "Company" with sub-folders for "Admin", "Finance", "HR", "Engineering" and so on. The sub-folders have more restrictive permissions than the top-level one.

We've now got more or less everything in the right place, and mostly this works. The problem is where individual files or folders have their own permissions - they then don't seem to inherit the permissions from their folders. How do we reset the permissions for everything in each part of the hierarchy so they are the same as the parent folder?

On Windows Server or Mac OS X there is a clear distinction between "inherited" and "explicit" permissions for an item, and it is easy to remove the "explicit" permissions for all the items in a hierarchy. Where is this for GD?

share|improve this question

2 Answers 2

I have created a Google Apps Scripts webapp that should be close to what you want.

IMPORTANT! Before running this on any of your folders, make sure you test it on another account. Although the script seems to be working as intended, I cannot make any guarantee that it will not mess up your permissions. So go through the script carefully, check with the documentation for Google Apps Scripts, and test it thoroughly before running on any production data.

The script's UI is very rudimentary, so don't except anything fancy.

var selectedFolder;
var dialog;

function doGet() {
  var app = UiApp.createApplication();
  var heading = app.createHTML("<h1>Folders for</h1>");
  app.add(heading);
  var allFoldersIterator = DriveApp.getFolders();
  var text = app.createTextArea().setName("text").setId("output");
  app.add(text);
  var tree = app.createTree();
  var rootFolder = DriveApp.getRootFolder();
  var treeRoot = app.createTreeItem(rootFolder.getName()).setId(rootFolder.getId());
  var handler = app.createServerHandler("folderSelected");
  tree.addItem(treeRoot);
  tree.addSelectionHandler(handler);
  treeRoot.setState(true);
  createBranch(rootFolder, treeRoot, app);
  app.add(tree);
  var selectedFolderIdBox = app.createTextBox().setName("selectedFolderIdBox").setId("selectedFolderIdBox");
  app.add(selectedFolderIdBox);
  return app;
}

function createBranch(folder, branch, app) {
  var children = folder.getFolders();
  while (children.hasNext()) {
    child = children.next();
    Logger.log("Folder id: " + child.getId());
    var subBranch = app.createTreeItem(child.getName()).setId(child.getId());
    branch.addItem(subBranch);
    createBranch(child, subBranch, app);
  }
}

function folderSelected(eventInfo) {
  var app = UiApp.getActiveApplication();
  var parameter = eventInfo.parameter;
  Logger.log("Selected " + eventInfo.parameter.selected);
  selectedFolder = DriveApp.getFolderById(eventInfo.parameter.selected);
  var selectedFolderIdBox = app.getElementById("selectedFolderIdBox");
  selectedFolderIdBox.setValue(eventInfo.parameter.selected);
  var okHandler = app.createServerHandler("okResetPermissions");
  okHandler.addCallbackElement(selectedFolderIdBox);
  dialog = app.createDialogBox(true, true);
  var panel = app.createFlowPanel();
  dialog.add(panel);
  dialog.setId("confirmationDialog");
  dialog.setPopupPosition(100, 100).setSize(500, 500);
  panel.add(app.createLabel("Do you want to reset permissions for all files found in folder " + selectedFolder.getName() + " and its subfolders?\n (Click outside of the dialog box to cancel)"));
  panel.add(app.createButton("Do it!", okHandler));
  dialog.show();
  return app;
}

function okResetPermissions(eventInfo) {
  var selectedFolderId = eventInfo.parameter.selectedFolderIdBox;
  var selectedFolder = DriveApp.getFolderById(selectedFolderId);
  Logger.log("Resetting permissions on " + selectedFolder.getName());
  var app = UiApp.getActiveApplication();
  app.getElementById("confirmationDialog").hide();
  Logger.log("Confirmation dialog hidden");
  var progressIndicator = app.createDialogBox(false, true);
  progressIndicator.setId("progressIndicator");
  progressIndicator.setPopupPosition(100, 100).setSize(500, 500);
  var label = app.createLabel("Working ...");
  progressIndicator.add(label);
  progressIndicator.show();
  doResetPermissions(selectedFolder, function() {
    var app = UiApp.getActiveApplication();
    var progressIndicator = app.getElementById("progressIndicator");
    progressIndicator.hide();
    return app;
  });
  return app;
}

function doResetPermissions(selectedFolder, callback) {
  Logger.log("Resetting permissions on folder " + selectedFolder.getName());
  var sharingAccess = selectedFolder.getSharingAccess();
  var sharingPermission = selectedFolder.getSharingPermission();
  var files = selectedFolder.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    Logger.log("   Resetting permissions on file " + file.getName());
    file.setSharing(sharingAccess, sharingPermission);
    var viewers = file.getViewers();
    for (var i = 0; i < viewers.length; i++) {
      Logger.log("      Removing viewer " + viewers[i].getEmail());
      file.removeViewer(viewers[i]);
    }
    var editors = file.getEditors();
    for (var i = 0; i < editors.length; i++) {
      Logger.log("      Removing editor " + editors[i].getEmail());
      file.removeEditor(editors[i]);
    }
  }
  var children = selectedFolder.getFolders();
  while (children.hasNext()) {
    var child = children.next();
    doResetPermissions(child);
  }
  if (callback) {
    callback();
  }
}

To install this script, go to your Google Drive and click New → Google Apps Script. Paste in the code, and Publish → Distribute as web-app.
Set the script to Run as the logged-in user (or similar, my Google Drive is not in English).

When invoking the app, you will be shown the folder hierarchy of your Google Drive. Clicking on a folder will display an ugly-looking popup, where you can choose to execute a permission reset script for the folder and its subfolders (the function doResetPermissions in the code).
This function iterates through the folder and its subfolders. For each file it finds, it executes file.setSharing with values from the parent folder. It also calls file.removeViewer for all viewers registered, and file.removeEditor for all registered editors.

Check the documentation for removeViewer and removeEditor to be sure they do what you want.

Note that executing the script may take some time (depending on the size of your folder structure), and no feedback is given while it's working, except in the script runner logs (View → Logs).

share|improve this answer
    
CreateBrance is used within createBrance? Does that work? –  Jacob Jan Tuinstra Aug 12 at 13:11
1  
Yes, that should work fine. It is a recursive function. –  Vidar S. Ramdal Aug 12 at 13:12

http://gappstips.com/docs-tips/view/98/protect-your-google-drive-folders-by-setting-permissions

according to that link it seems like you need to make sure the files are set to the default permissions then they should inherit from the folder.

edit: ctrl+a selects all files in the folder then you can change who they are shared with all at once.

share|improve this answer
1  
I think the OP wants to know how you can reset permissions to default for all documents at once. –  Vidar S. Ramdal Aug 9 at 12:40
    
We have many folders. How to do this recursively for ALL files in them? –  Krom Stern Aug 11 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.