这就是我要做的:首先,如果用户在google工作表中的状态从Active变为Inactive,而用户仍处于登录状态,那么当他试图点击页面中的任何按钮时,他将被注销。在这种情况下,例如删除(xBtn)按钮。
单位为J
//check user status
function logout_inactive_user(status){
if (status == "Inactive"){
logout();
return;
}
if (status == "Active"){
return false;
}
}
function retrieve_record(){
google.script.run.withSuccessHandler(display_row).testing_row_data();
}
//show user time log - home page
function display_row(tbl_arr){
//there are some code here to create table
var xBtn = document.createElement('button')
xBtn.onclick = function(){
google.script.run.withSuccessHandler(logout_inactive_user).check_user_status();
var task_id = number[4];
const response = confirm("This will delete task " + task_id + ". Proceed?");
if (response) {
google.script.run.deleteRows(task_id);
tbody.innerHTML = "";
retrieve_record();
}
}
}
代码gs
var the_url = 'the spreadsheet url'; //sheet for code and list of usernames etc
var ss = SpreadsheetApp.openByUrl(url);
var ts = ss.getSheetByName("Sheet1");
var tHs = ss.getSheetByName("User_ID");
function doGet(e) {
const htmlOutput = HtmlService.createTemplateFromFile('Index');
return htmlOutput.evaluate();
}
function testing_row_data(){
//some code here
return variable
}
function check_user_status(){
//return user status
var status_data = tHs.getDataRange().getValues();
for(var i = 0; i<status_data.length;i++){
if(status_data[i][1] == userEmail){ //[1] because column B
var u_status = tHs.getRange(i+1,1).getValue() //user status column 1
}
}
return u_status;
}
function deleteRows(task_id) {
var rows = ts.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[4] == task_id) {
ts.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};
但它不起作用。它不会注销用户,而是仍然允许用户删除行,即使他的状态现在是非活动的。没有错误消息。
1条答案
按热度按时间ktca8awb1#
反正我已经想通了