Created
June 6, 2017 21:58
-
-
Save mvogelgesang/38a5d93a7761faabf9a820a00f1f950e to your computer and use it in GitHub Desktop.
Review file permissions in Google Drive for a given folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This global array identifies which access scopes shall be excluded. L | |
var ACCESS_WHITELIST = ["PRIVATE"]; // "ANYONE", "ANYONE_WITH_LINK", "DOMAIN", "DOMAIN_WITH_LINK", "PRIVATE"]; | |
function fileActivityReport() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getSheetByName("OUTPUT").clear(); | |
var folderId = showPrompt(); | |
if (folderId != "") { | |
// Log the name of every folder in the user's Drive. | |
var folder = DriveApp.getFolderById(folderId); | |
sheet.appendRow(["Folder Name", "Folder URL", "File Name", "File Url"]); | |
traverseFolder(folder); | |
} | |
} | |
function traverseFolder(folderObj, parentFolder) { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getActiveSheet(); | |
var folderSharingAccess = folderObj.getSharingAccess(); | |
var folderName = folderObj.getName(); | |
var folderUrl = folderObj.getUrl(); | |
var files = folderObj.getFiles(); | |
while (files.hasNext()) { | |
var file = files.next(); | |
var fileSharingAccess = file.getSharingAccess(); | |
if (fileSharingAccess != DriveApp.Access.PRIVATE) { | |
sheet.appendRow([folderName, folderUrl, file.getName(), file.getUrl, fileSharingAccess]); | |
} | |
} | |
parentFolder = folderName; | |
var subs = folderObj.getFolders(); | |
while (subs.hasNext()) { | |
traverseFolder(subs.next()); | |
} | |
} | |
/** | |
* This function prompts the user for their folder ID or URL. | |
* If a URL is provided, the ID is extracted | |
* | |
* @return text {string} containing the ID of the folder | |
*/ | |
function showPrompt() { | |
var text = ""; | |
var ui = SpreadsheetApp.getUi(); // Same variations. | |
var result = ui.prompt( | |
'Welcome to the utility!', | |
'Please enter the ID or URL of the folder you would like to scan:', | |
ui.ButtonSet.OK_CANCEL); | |
// Process the user's response. | |
var button = result.getSelectedButton(); | |
text = result.getResponseText(); | |
if (text.indexOf("https://") != -1) { | |
var regex = new RegExp("[^/]+$"); | |
var text = regex.exec(text)[0]; | |
} | |
if (button == ui.Button.OK && text != "") { | |
// User clicked "OK". | |
ui.alert('Thanks, the ID for this folder is: "' + text + '". We will get started with the scan!'); | |
} else if (text == "") { | |
ui.alert('Looks like you forgot to add a URL or ID, please try again!'); | |
} else if (button == ui.Button.CANCEL) { | |
// User clicked "Cancel". | |
ui.alert('Not ready to scan, come again later.'); | |
} else if (button == ui.Button.CLOSE) { | |
// User clicked X in the title bar. | |
ui.alert('You closed the dialog.'); | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment