The task is: several users edit GoogleSheets table. All of them have Editor's role. Some of the users are masterusers - they can edit everything. Some are clients - they can edit only empty time-slots and time-slots, reserved for their company.
I create Config with an object
var CONFIG = {
SPREADSHEET_URL:*** '*/edit',
OWNER_EMAIL: ['xxxxx@gmail.com', 'yyyy@pirs.ooo'],
EDITORS_TO_REMOVE: {"Агама":['zzzz@gmail.com'],"Юнифрост":['uuuu@gmail.com']}
};
EDITORS_TO_REMOVE: - array of users and their company
OWNER_EMAIL: - array of masterusers that can edit everything
Then I try to handle edit event - when client tries to edit something code should sheck, if the edited time-slot is empty or not reserved by other client.
So, I catch the edit event by function onEdit(e) and Log the result. When I operate from my own account - it operates good and
userEmail
is my email, all OK
but if I do it from any other account, userEmail is empty. AI didn't help.
function onEdit(e) {
const sheet = e.source.getActiveSheet();
const row = e.range.rowStart;
const col = e.range.columnStart;
const userEmail = Session.getActiveUser().getEmail();
// Определяем диапазоны ворот (Клиент, Ворота, Вид окна)
const gateRanges = [
{ clientCol: 3, gateCol: 4, windowCol: 5, name: 'Ворота 1' }, // C-E
{ clientCol: 6, gateCol: 7, windowCol: 8, name: 'Ворота 2' }, // F-H
{ clientCol: 9, gateCol: 10, windowCol: 11, name: 'Ворота 3' } // I-K
];
let processed = false;
for (const range of gateRanges) {
if ([range.clientCol, range.gateCol, range.windowCol].includes(col)) {
handleGateEdit(sheet, row, range, userEmail);
processed = true;
break;
}
}
if (!processed) return; // Если изменение не в нужных колонках — выходим
}