Automating Permissions and I keep getting an extra person in there
<p>So I hate permissions, they are awful. BUT I also hate it when people over write things they didn't realise were important... I was really excited to find out that I could automate the entire granting permissions ordeal using google scripting.</p>

<p>So I tested things out in a small dummy sheet, and got it working the way I wanted to. However! When I use it on my test template of the actual sheet I will need to be using it on, it will (for some reason) add the other person I shared the file with into <em>all</em> the levels of permissions.</p>

<p>This is not what I want. The other person is currently me (at SHOULDN'TBEINEVERYTHING@WHYYYYY.com in this script), but that account is supposed to have the lower level of permissions so I can make sure that everything is working the way I want it to. Here's a dummy version of the code I'm using:</p>

<pre><code>function plus10Protection() {

var ss = SpreadsheetApp.getActive();

    // Removes protections from Ranges
 var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
 for (var i = 0; i &lt; protections.length; i++) {
   var protection = protections[i];
   if (protection.canEdit()) {
     protection.remove();
   }
 }

      //removes sheet protections
 var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
 for (var i = 0; i &lt; protections.length; i++) {
   var protection = protections[i];
   if (protection.canEdit()) {
     protection.remove();
   }
 }

  //SHEET1
  var sh7 = ss.getSheetByName("Sheet1");
  var protection = sh7.protect().setDescription('Sheet1 - Wizards');  
//protects whole sheet
  protection.addEditors(['wizard1@test.com', 
                         'wizard2@test.com']); 
  //adds email addresses to WIZARD range - SHEET1

  var unprotected = sh7.getRange('A1:D');
  protection.setUnprotectedRanges([sh7.getRange("B1:B1"),
                                   sh7.getRange("B3:D")]); 
  //unprotects

  var range = sh7.getRange('B1:B1'); //selects the range
  var protection = range.protect().setDescription('Sheet1 - Part Number'); 
  //names the range
  var me = Session.getEffectiveUser();
  protection.addEditors(['wizard1@test.com',
                         'wizard2@test.com',
                         'supervisor1@test.com']); 
  //put emails here SHEET1 SUPERVISORS   

  var range = sh7.getRange('B3:D'); //selects the range
  var protection = range.protect().setDescription('Sheet1 - Workers');
  //names the range
  var me = Session.getEffectiveUser();
  protection.addEditors(['wizard1@test.com',
                         'wizard2@test.com',
                         'supervisor1@test.com'
                         'worker1@test.com'
                         'worker2@test.com'
                         'SHOULDN'TBEINEVERYTHING@WHYYYYY.com']);  
  //put emails here SHEET1 WORKERS 
</code></pre>

<p>Repeated for about fifteen other tabs. I was really wanting this to solve the problem with updating permissions when people leave or join, since this script removes old permissions and then puts new ones on. However, the sheet is already shared with everyone at the company, and if suddenly everyone has Wizard level access, it's pretty much the worst.</p>

<p>I tested it again by sharing with another person, and they were added in to everything as well. Is there some code snippet that specifies <em>only</em> sharing with the emails I've provided, and not everyone it could possibly share with? (stop getting over excited, google.)</p>

<p>I don't want to have to un-share it with everyone and then re-share, because that seems like a huge problem. I'm hoping there's something in the code that I stole from somewhere online (I should have bookmarked it!!!) is actually calling everyone with edit permissions.... Maybe the getEffectiveUser? Though I'm running it from my test1@test.com account, not from the other which is open in a different browser! (Firefox, and I'm scripting in Chrome.)</p>

<p>I also tested to see if maybe it was because I was signed in and looking at the sheet with my SHOULDN'TBEINEVERYTHING@WHYYYYY.com account, but nope, that's not it.</p>

<p>Is it possible to script sharing? So I could have it first unshare with everyone, clear the permissions, set the new permissions, then re-share? If that is the only solution? The less finicky I can make this the better. :S</p>

<p>I'm trying to get answers to this problem over on the google sheets forums, but no bites so far. I was hoping to cast a wider net.</p>