google sheet file : duplicate protections via apps script but problem with sheet co-owner

197 views
Skip to first unread message

scosco LASTIQUO

unread,
Nov 28, 2021, 4:05:18 PM11/28/21
to Google Apps Script Community
Hi everyone,

I own the google sheet file and give restricted access to authorized editors. I have a protected template tab (model). I created a script for editors to duplicate the model tab. Of course the protections are not duplicated (it is a known fact) So I scripted the protections to copy each other. However, by duplicating the model tab, via my script, the editor still becomes co-owner (with me) of the created tab. and as a result can modify the protected areas.

here below the script part using by editors :
var me = Session.getActiveUser().getEmail();
var p = model.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
var p2 = sheet.protect();
p2.setDescription(p.getDescription());

var ranges = p.getUnprotectedRanges();
var newRanges = [];
for (var i = 0; i < ranges.length; i++) {
newRanges.push(sheet.getRange(ranges.getA1Notation()));
}
p2.setUnprotectedRanges(newRanges);
p2.removeEditors(p2.getEditors());
p2.removeEditors([me]);

I even tried to delete removeEditors(e-mail) but it doesn't work, the editor remains co-owner with me.

Is my project possible ?
thanks




Tanaike

unread,
Nov 28, 2021, 7:23:50 PM11/28/21
to Google Apps Script Community
Can you provide the script of "I created a script for editors to duplicate the model tab."? And, in your situation, how does the user run your scripts?
Reply all
Reply to author
Forward
0 new messages