[英]Data protection issue with other editors except owner in Google App Scripts having onEdit() trigger
I have a google spreadsheets with 6 editors including me as a owner.我有一个谷歌电子表格,有 6 位编辑,包括我作为所有者。 When any editor except the owner of the sheets selects certain value in the dropdown menu, the onEdit trigger attached with classAttendance() starts working.
当除工作表所有者之外的任何编辑器在下拉菜单中选择某个值时,附加到 classAttendance() 的 onEdit 触发器开始工作。 That's fine.
没关系。 But the issue is, every time the data is protected on the owner name (has edit access) though the user is different editor.
但问题是,每次数据都受到所有者名称的保护(具有编辑权限),尽管用户是不同的编辑者。 It should be on that specific editor name and should have edit access to it.
它应该在该特定的编辑名称上,并且应该具有对其的编辑权限。 How to solve it?
如何解决?
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);
}
The installable version runs with the authorization of the user who created the trigger, even if another user with edit access opens the spreadsheet.
可安装版本在创建触发器的用户的授权下运行,即使另一个具有编辑权限的用户打开电子表格也是如此。
Now, the documentaiton for removeEditor() says:现在, removeEditor()的文档说:
Neither the owner of the spreadsheet nor the current user can be removed.
电子表格的所有者和当前用户都不能被删除。
In other words:换句话说:
protectionm.addEditor(me);
protectionm.addEditor(me);
will only add you as an editor (but you are already an editor anyway).addEditor
before removeEditos()
- the latter will remove all editors that have been added before.removeEditos()
之前使用addEditor
是没有意义的——后者将删除之前添加的所有编辑器。user
to retrieve the active useruser
检索活动用户 Sample for implementation:实施示例:
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.