Il creatore del Gruppo deve già appartenere al Gruppo stesso

Non permettere di aggiungere un Gruppo con lo stesso nome o codice
quando cancelli un Gruppo, cancella anche tutti i riferimenti sugli utenti di quel gruppo.
Errore caricamento Immagini !
This commit is contained in:
paoloar77
2022-02-28 17:20:47 +01:00
parent 1d7397bafe
commit adf4918224
9 changed files with 188 additions and 117 deletions

View File

@@ -23,6 +23,8 @@ const { Newstosent } = require('./models/newstosent');
const server_constants = require('./tools/server_constants');
const shared_consts = require('./tools/shared_nodejs');
const { User } = require('./models/user');
const transport_preview = nodemailer.createTransport({
@@ -190,14 +192,13 @@ module.exports = {
nomeapp: tools.getNomeAppByIdApp(idapp),
strlinksito: tools.getHostByIdApp(idapp),
strlinkreg: this.getlinkReg(idapp, idreg),
username: user.username,
name: user.name,
surname: user.surname,
forgetpwd: tools.getHostByIdApp(idapp) + '/requestresetpwd',
emailto: emailto,
user,
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
this.sendEmail_base(tools.getpathregByIdApp(idapp, lang), emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
// Send to the Admin an Email
@@ -208,8 +209,10 @@ module.exports = {
if (tools.getConfSiteOptionEnabledByIdApp(mylocalsconf.idapp, shared_consts.ConfSite.Notif_Reg_Push_Admin)) {
const nometot = tools.getNomeCognomeEUserNameByUser(mylocalsconf);
let aportador = mylocalsconf.aportador_solidario ? ' (da ' + mylocalsconf.aportador_solidario + ')': '';
const numutenti = await User.getNumUsers(mylocalsconf.idapp);
tools.sendNotifToAdmin('++ [' + numutenti + '] ' + nometot);
tools.sendNotifToAdmin('++ [' + numutenti + '] ' + nometot + aportador);
}
// if (tools.isManagAndAdminDifferent(idapp)) {
@@ -226,15 +229,14 @@ module.exports = {
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
strlinksito: tools.getHostByIdApp(idapp),
username: iscritto.username,
name: iscritto.name,
surname: iscritto.surname,
emailto: emailto,
iscritto,
metodo_pagamento: tools.getPaymentTypesById(iscritto.metodo_pagamento),
data_nascita: tools.getstrDate_DD_MM_YYYY(iscritto.dateofbirth)
};
mylocalsconf = this.setParamsForTemplate(iscritto, mylocalsconf);
this.sendEmail_base('iscrizione_conacreis/' + lang, emailto, mylocalsconf, tools.getreplyToEmailByIdApp(idapp));
// Send to the Admin an Email
@@ -256,14 +258,12 @@ module.exports = {
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
user: user,
name: user.name,
username: user.username,
surname: user.surname,
strlinksetpassword: this.getlinkRequestNewPassword(idapp, emailto, tokenforgot),
emailto: emailto,
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
this.sendEmail_base('resetpwd/' + lang, emailto, mylocalsconf, '');
},
@@ -278,8 +278,6 @@ module.exports = {
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
emailto: emailto,
participants: '',
participantsLunch: '',
@@ -290,6 +288,8 @@ module.exports = {
event: recbooking.infoevent,
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
return Settings.getValDbSettings(idapp, 'MSG_REPLY_AFTER_BOOKING')
.then(async (ris) => {
mylocalsconf.msgreply_after_booking = ris;
@@ -362,9 +362,6 @@ module.exports = {
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
emailto: emailto,
event: recbooking.infoevent,
participants: '',
participantsLunch: '',
@@ -373,6 +370,10 @@ module.exports = {
eventtextplain: tools.removeSpecialCharForEmail(recbooking.infoevent),
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
mylocalsconf.emailto = emailto;
mylocalsconf = await this.preparaConfPerBooking(res, idapp, mylocalsconf, recbooking, 'Cancellazione');
let msgtelegram = 'Cancellazione Evento [' + mylocalsconf.name + ' (' + mylocalsconf.name + ' ' + mylocalsconf.surname + ')] ' + mylocalsconf.eventtextplain;
@@ -399,15 +400,15 @@ module.exports = {
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
usernameorig: user.name + ' ' + user.surname,
emailto: emailto,
message: tools.convertTexttoHtml(recmsg.message),
infoevent: recmsg.source.infoevent,
strlinkreply: tools.getHostByIdApp(idapp) + '/messages/' + recmsg._id
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
mylocalsconf.emailto = emailto;
let replyto = '';
if (mylocalsconf.infoevent !== '')
replyto = user.email;
@@ -424,17 +425,17 @@ module.exports = {
tools.mylog('sendEmail_ByText');
mylocalsconf = {
let mylocalsconf = {
idapp,
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
usernameorig: user.name + ' ' + user.surname,
emailto: emailto,
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
mylocalsconf.emailto = emailto;
mylocalsconf.dataemail.emailbody = rec.emailbody;
mylocalsconf.dataemail.emailtitle = rec.emailtitle;
@@ -453,16 +454,15 @@ module.exports = {
// console.log('idapp', idapp, tools.getNomeAppByIdApp(idapp));
mylocalsconf = {
let mylocalsconf = {
idapp,
dataemail: await this.getdataemail(idapp),
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
name: user.name,
surname: user.surname,
emailto: user.email,
};
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
const hash = tools.getHash(mylocalsconf.emailto);
// Check if exist to the Mailing List
@@ -553,6 +553,7 @@ module.exports = {
out = out.replace('{username}', mylocalsconf.username);
out = out.replace('{name}', mylocalsconf.name ? mylocalsconf.name : mylocalsconf.username);
out = out.replace('{surname}', mylocalsconf.surname ? mylocalsconf.surname : '');
out = out.replace('{aportador_solidario}', mylocalsconf.aportador_solidario ? mylocalsconf.aportador_solidario : '');
return out
},
@@ -645,6 +646,25 @@ module.exports = {
return smtpTransport;
},
setParamsForTemplate: function (user, mylocalsconf){
try {
mylocalsconf.username = user.username;
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.aportador_solidario = user.aportador_solidario ? user.aportador_solidario : '';
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
mylocalsconf.user = user;
mylocalsconf = this.replacefields(mylocalsconf);
}catch (e) {
console.error('setParamsForTemplate', e);
}
return mylocalsconf;
},
sendEmail_OrderProduct: async function (lang, idapp, orders, user) {
const msginizio = 'Ordine n: ' + orders.numorder + ' ' + user.name + ' ' + user.surname;
@@ -652,7 +672,7 @@ module.exports = {
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
mylocalsconf = {
let mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
@@ -663,12 +683,7 @@ module.exports = {
user
};
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
mylocalsconf = this.replacefields(mylocalsconf);
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
this.sendEmail_base_e_manager(idapp, 'ecommerce/makeorder/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply);
@@ -680,7 +695,7 @@ module.exports = {
await telegrambot.sendMsgTelegramToTheManagers(idapp, msginizio);
mylocalsconf = {
let mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
@@ -691,12 +706,7 @@ module.exports = {
user
};
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
mylocalsconf = this.replacefields(mylocalsconf);
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
if ((status !== shared_consts.OrderStatus.CANCELED) && (status !== shared_consts.OrderStatus.RECEIVED)) {
const esito = this.sendEmail_base('ecommerce/' + ordertype + '/' + lang, mylocalsconf.emailto, mylocalsconf, mylocalsconf.dataemail.email_reply);
@@ -722,7 +732,7 @@ module.exports = {
const myarrevents = await MyEvent.getLastEvents(idapp);
mylocalsconf = {
let mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),
@@ -765,13 +775,7 @@ module.exports = {
return false
}
mylocalsconf.name = user.name;
mylocalsconf.surname = user.surname;
mylocalsconf.emailto = user.email;
mylocalsconf.hashemail = tools.getHash(user.email);
mylocalsconf = this.replacefields(mylocalsconf);
mylocalsconf = this.setParamsForTemplate(user, mylocalsconf);
// If has already sent, don't send it again!
if (user.lastid_newstosent !== id_newstosent.toString()) {
@@ -886,7 +890,7 @@ module.exports = {
const myarrevents = await MyEvent.getLastEvents(idapp);
const myemail = await Settings.getValDbSettings(idapp, 'EMAIL_TEST');
if (myemail) {
mylocalsconf = {
let mylocalsconf = {
idapp,
locale: lang,
nomeapp: tools.getNomeAppByIdApp(idapp),