Next: File Permissions and Sharing Settings in Google Drive

File Permissions and Sharing Settings in Google Drive

If you want to know who has access to your files in Google Drive there is the following script by Amit Agarwal.:


 /*   
    
    
  ======================================  
  Who Can See Your Files in Google Drive   
  ======================================  
    
  Written by Amit Agarwal on 09/11/2013   
    
  Tutorial :: http://labnol.org/?p=28237  
    
    
 */  
    
    
    
 function ScanGoogleDrive() {  
    
  // Get all files in your Google Drive  
  var files = DriveApp.getFiles();  
    
  var msg = "";  
  var report = "";  
    
  while (files.hasNext()) {  
     
   try {  
      
    var file = files.next();  
      
    // Get the Sharing Permissions of a file  
    var access = file.getSharingAccess();  
      
    // Is a file privately shared with specific users     
    if (access == DriveApp.Access.PRIVATE) {  
     var viewers = file.getViewers();     
     var editors = file.getEditors();  
     if (editors.length || viewers.length) {  
      var view="", edit="";  
        
      // Find who has "view" permissions for that file  
      for (var i=0; i<viewers.length; i++) {          
       if (view.length) {  
        view += ", ";  
       }  
       view += viewers[i].getName() + " " + viewers[i].getEmail();  
      }  
        
      // Find who has "edit" permissions for that file  
      for (var i=0; i<editors.length; i++) {          
       if (edit.length) {  
        edit += ", ";  
       }  
       edit += editors[i].getName() + " " + editors[i].getEmail();  
      }  
      report += "<tr><td style='padding:5px;'><a href='" + file.getUrl() + "'>" + file.getName()  
       + "</a></td><td style='padding:5px'>" + view + "</td><td style='padding:5px'>" + edit + "</td></tr>";                   
     }  
     // Or is the file public, shared with anyone on the Internet  
    } else if ((access == DriveApp.Access.ANYONE_WITH_LINK) || (access == DriveApp.Access.PRIVATE)) {  
     var permission = file.getSharingPermission();  
       
     // Is the file shared with "Edit" permissions?  
     if (permission == DriveApp.Permission.EDIT) {  
      permission = "Public";  
     } else {  
      permission = "";  
     }        
     report += "<tr><td style='padding:5px'><a href='" + file.getUrl() + "'>" + file.getName()   
      + "</a></td><td style='padding:5px'>Public</td><td style='padding:5px'>" + permission + "</td></tr>";            
    }  
   }  
   catch (e) {  
    Logger.log(e.toString());  
   }  
  }   
    
  // Send the report as HTML Email  
  report ="<table><tr><th'>File Name</th><th>Who can view</th><th>Who can edit</th></tr>" + report + "</table>";  
  MailApp.sendEmail(Session.getActiveUser().getEmail(),  
           "Google Drive - File Sharing Report", report, {htmlBody: report});  
 }