- "La Mia Lavagna" ora è visibile il numero di Invitati che hanno i requisiti, dei propri invitati.

- Sistemato la funzione di poter Donare un invitato a qualcun'altro.
 - Aggiornati testi sul BOT.

 Per Staff Admin:
 - Notifica sul BOT per ogni modifica dell'invitante o eliminazione di un invitato.
This commit is contained in:
Paolo Arena
2020-02-05 00:39:25 +01:00
parent e386d2550b
commit a8bec7686a
4 changed files with 153 additions and 54 deletions

View File

@@ -134,7 +134,7 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
User.findByLinkTokenforgot(idapp, email, tokenforgot).then((user) => {
if (!user) {
return res.send({code: server_constants.RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND});
return res.send({ code: server_constants.RIS_CODE_TOKEN_RESETPASSWORD_NOT_FOUND });
} else {
// aggiorna la nuova password
user.password = password;
@@ -146,7 +146,7 @@ router.post(process.env.LINK_UPDATE_PWD, (req, res) => {
// Salva lo User
user.save().then(() => {
res.header('x-auth', token).send({code: server_constants.RIS_CODE_OK}); // Ritorna il token di ritorno
res.header('x-auth', token).send({ code: server_constants.RIS_CODE_OK }); // Ritorna il token di ritorno
});
})
}
@@ -255,6 +255,7 @@ router.post('/gettable', authenticate, (req, res) => {
});
router.patch('/chval', authenticate, (req, res) => {
// const idapp = req.body.idapp;
const id = req.body.data.id;
@@ -267,20 +268,39 @@ router.patch('/chval', authenticate, (req, res) => {
tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
// If I change my record...
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && !(req.user._id.toString() === id)) {
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && !(req.user._id.toString() === id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).then((rec) => {
mytable.findByIdAndUpdate(id, { $set: fieldsvalue }).then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
if (!rec) {
return res.status(404).send();
} else {
if (mydata.notifBot) {
// Send Notification to the BOT
telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, mydata.notifBot.txt)
telegrambot.sendMsgTelegram(idapp, mydata.notifBot.un, mydata.notifBot.txt);
addtext = '[Msg Inviato a ' + mydata.notifBot.un + ']:' + '\n' + mydata.notifBot.txt;
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext);
}
if (tools.ModificheConsentite(mydata.table, fieldsvalue)) {
let msg = '';
if (mydata.table === 'users') {
if ('aportador_solidario' in fieldsvalue) {
const nomecognomenuovo = await User.getNameSurnameByUsername(idapp, fieldsvalue.aportador_solidario);
const nomecognomeas = await User.getNameSurnameByUsername(idapp, rec.aportador_solidario);
msg = `Variato l'invitante di ` + rec.name + ' ' + rec.surname + '\nmodificato da ' + req.user.name + ' ' + req.user.surname + ' \n' +
'Prima: ' + nomecognomeas + ' (' + rec.aportador_solidario + ')\n' +
'Dopo: ' + nomecognomenuovo + ' (' + fieldsvalue.aportador_solidario + ') ]';
}
}
if (msg !== '')
telegrambot.sendMsgTelegramToTheManagers(idapp, msg);
}
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
}
@@ -292,48 +312,52 @@ router.patch('/chval', authenticate, (req, res) => {
});
router.get('/copyfromapptoapp/:idapporig/:idappdest', async (req, res) => {
const idapporig = req.params.idapporig;
const idappdest = req.params.idappdest;
if (!idapporig || !idappdest)
res.status(400).send();
const mytablesstr = ['settings', 'users', 'templemail', 'contribtype'];
try {
let numrectot = 0;
for (const table of mytablesstr) {
const mytable = getTableByTableName(table);
tools.mylogshow('copyfromapptoapp: ', table, mytable);
await mytable.DuplicateAllRecords(idapporig, idappdest).then((numrec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);
numrectot += numrec
});
}
res.send({ code: server_constants.RIS_CODE_OK, msg: '', numrectot });
} catch (e) {
tools.mylogserr('Error copyfromapptoapp: ', e);
res.status(400).send();
}
// const idapporig = req.params.idapporig;
// const idappdest = req.params.idappdest;
// if (!idapporig || !idappdest)
// res.status(400).send();
//
// const mytablesstr = ['settings', 'users', 'templemail', 'contribtype'];
//
// try {
// let numrectot = 0;
// for (const table of mytablesstr) {
// const mytable = getTableByTableName(table);
//
// tools.mylogshow('copyfromapptoapp: ', table, mytable);
//
// await mytable.DuplicateAllRecords(idapporig, idappdest).then((numrec) => {
// // tools.mylogshow(' REC TO MODIFY: ', rec);
// numrectot += numrec
// });
// }
//
// res.send({ code: server_constants.RIS_CODE_OK, msg: '', numrectot });
//
// } catch (e) {
// tools.mylogserr('Error copyfromapptoapp: ', e);
// res.status(400).send();
// }
});
router.delete('/delrec/:table/:id', authenticate, (req, res) => {
const id = req.params.id;
const idapp = req.user.idapp;
const tablename = req.params.table;
let notifBot = false;
// const idapp = req.body.idapp;
console.log('id', id, 'table', tablename);
const mytable = getTableByTableName(tablename);
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) && (tablename !== 'extralist')) {
// If without permissions, exit
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
}
notifBot = tools.NotifyIfDelRecord(tablename);
return mytable.findByIdAndRemove(id).then((rec) => {
if (!rec) {
return res.status(404).send();
@@ -344,6 +368,19 @@ router.delete('/delrec/:table/:id', authenticate, (req, res) => {
// Do extra things after deleted
return actions.doOtherThingsAfterDeleted(tablename, rec).then((ris) => {
if (ris) {
if (notifBot) {
// Send Notification to the BOT
let nomerecord = '';
if ((tablename === 'users') || (tablename === 'extralist')) {
nomerecord = rec.name + ' ' + rec.surname + ' (' + rec.username + ')';
}
addtext = 'Eliminato il Record "' + nomerecord + '" dalla tabella ' + tablename + '\n' +
'Eseguito da ' + req.user.name + ' ' + req.user.surname + ' \n';
telegrambot.sendMsgTelegramToTheManagers(idapp, addtext);
}
tools.mylog('DELETED Others things ...');
return res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
}
@@ -562,7 +599,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
if (!!dir)
await client.createDir(dir);
const miofile = (dir) ? dir + `/` + file.name : file.name;
const miofile = (dir) ? dir + ` / ` + file.name : file.name;
console.log('Upload...');
const ret = await client.upload(file.path, miofile, 755);
console.log('Uploaded ' + file.name, 'status:', ret);