title: Google Sheet Protect range and unprotect
body: <p>I use the following code to protect a range from a Google Sheet</p>
  <pre><code>// Protect range A1:B10, then remove all other users from the list of editors.
  var ss = SpreadsheetApp.getActive();
  var range = ss.getRange('A1:B10');
  var protection = range.protect().setDescription('Sample protected range');
  
  // Ensure the current user is an editor before removing others. Otherwise, if the user's edit
  // permission comes from a group, the script throws an exception upon removing the group.
  var me = Session.getEffectiveUser();
  protection.addEditor(&quot;*my email account*&quot;);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }
  </code></pre>
  <p>where my email account is the  Google account.</p>
  <p>I then share the sheet with some other people who I want to be able to remove protection, if they need, by running  a script triggered by clicking an icon.  The code include</p>
  <pre><code>// Remove all range protections in the spreadsheet that the user has permission to edit.
  var ss = SpreadsheetApp.getActive();
  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();
    }
  }
  </code></pre>
  <p>According to documentation, this code above should remove the protection.  But it does not work.  What is wrong?</p>
  <p>Thanks!</p>