[英]Data protection issue with other editors except owner in Google App Scripts having onEdit() trigger
我有一个谷歌电子表格,有 6 位编辑,包括我作为所有者。 当除工作表所有者之外的任何编辑器在下拉菜单中选择某个值时,附加到 classAttendance() 的 onEdit 触发器开始工作。 没关系。 但问题是,每次数据都受到所有者名称的保护(具有编辑权限),尽管用户是不同的编辑者。 它应该在该特定的编辑名称上,并且应该具有对其的编辑权限。 如何解决?
function classAttendance(e){
var spreadsheet = SpreadsheetApp.getActive();
var dashboard = spreadsheet.getSheetByName("Dashboard");
var sheetName = dashboard.getRange("A4").getValue();
if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 1-Period") {
refreshSheet();
onePeriod();
}
if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 2-Period") {
refreshSheet();
twoPeriod();
}
}
function refreshSheet() {
//For protecting dashboard while scripts running
var spreadsheet = SpreadsheetApp.getActive();
var dashboard = spreadsheet.getSheetByName("Dashboard");
var rangem = dashboard.getRange("A1:K71");
var timeZone = Session.getScriptTimeZone();
var stringDate = Utilities.formatDate(new Date(), timeZone, 'dd/MM/yy HH:mm');
var me = Session.getEffectiveUser();
var description = 'Scripts running on ' + stringDate + ' by ' + me;
var protectionm = rangem.protect().setDescription(description);
protectionm.addEditor(me);
protectionm.removeEditors(protectionm.getEditors());
if (protectionm.canDomainEdit()) {
protectionm.setDomainEdit(false);
}
Utilities.sleep(300000);
}
可安装版本在创建触发器的用户的授权下运行,即使另一个具有编辑权限的用户打开电子表格也是如此。
现在, removeEditor()的文档说:
电子表格的所有者和当前用户都不能被删除。
换句话说:
protectionm.addEditor(me);
只会将您添加为编辑器(但无论如何您已经是编辑器)。removeEditos()
之前使用addEditor
是没有意义的——后者将删除之前添加的所有编辑器。user
检索活动用户实施示例:
function classAttendance(e){
//////////MODIFICATION HERE
var user = e.user;
var spreadsheet = SpreadsheetApp.getActive();
var dashboard = spreadsheet.getSheetByName("Dashboard");
var sheetName = dashboard.getRange("A4").getValue();
if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 1-Period") {
//////////MODIFICATION HERE
refreshSheet(user);
onePeriod();
}
if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 2-Period") {
//////////MODIFICATION HERE
refreshSheet(user);
twoPeriod();
}
}
//////////MODIFICATION HERE
function refreshSheet(user) {
//For protecting dashboard while scripts running
var spreadsheet = SpreadsheetApp.getActive();
var dashboard = spreadsheet.getSheetByName("Dashboard");
var rangem = dashboard.getRange("A1:K71");
var timeZone = Session.getScriptTimeZone();
var stringDate = Utilities.formatDate(new Date(), timeZone, 'dd/MM/yy HH:mm');
var me = Session.getEffectiveUser();
var description = 'Scripts running on ' + stringDate + ' by ' + me;
var protectionm = rangem.protect().setDescription(description);
protectionm.removeEditors(protectionm.getEditors());
//////////MODIFICATION HERE
protectionm.addEditor(user);
if (protectionm.canDomainEdit()) {
protectionm.setDomainEdit(false);
}
Utilities.sleep(300000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.