l'admin non riesce a cambiare il fido degli utenti...
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Abilita fido a %s nel '%s':",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Abilita fido nel Circuito al gruppo %s:",
|
||||
"CIRCUIT_REQUEST_TO_ENTER": "%s è entrato nel %s ed è in attesa di essere abilitato al Fido (è stato invitato da %s)",
|
||||
"CIRCUIT_ADMINS": "\nGli amministratori del circuito sono %s:\n%s",
|
||||
"CIRCUIT_WHERE_IS_PRESENT": "\nAttualmente è presente in: %s",
|
||||
"CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel %s",
|
||||
"CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s",
|
||||
@@ -51,12 +52,12 @@
|
||||
"CIRCUIT_REMOVED_ADMIN_YOU": "%s ti è stato rimosso l'incarico di Amministratore del %s da parte di %s",
|
||||
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il %s da parte di %s",
|
||||
"CIRCUIT_ELIMINATO": "Il %s è stato eliminato da parte di %s",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT": "✅ l'utente %s è stato abilitato al Fido sul '%s' (da parte di %s)",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato abilitato al Fido sul '%s' (da parte di %s)",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT": "✅ l'utente %s è stato abilitato al Fido (%s RIS) sul '%s' (da parte di %s)",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato abilitato al Fido fino a -%s sul '%s' (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del '%s' (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato accettato a far parte del '%s' (da parte di %s)",
|
||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
||||
"FIDO_IMPOSTATO": "✅ Sei stato abilitato al fido da %s sul '%s'.",
|
||||
"FIDO_IMPOSTATO": "✅ Ti è stata attivata la possibilità di utilizzare il fido (Fiducia Concessa) fino a %s RIS da %s sul '%s'.",
|
||||
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del '%s'",
|
||||
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del '%s'. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
||||
"CIRCUIT_REMOVED": "❌ l'utente %s è stato rimosso del %s (da parte di %s)",
|
||||
|
||||
@@ -552,6 +552,20 @@ AccountSchema.statics.updateFido = async function (idapp, username, circuitId, f
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
|
||||
const account = await Account.findOne({_id: id}).lean();
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (account) {
|
||||
const circuit = await Circuit.findOne({_id: account.circuitId}).lean();
|
||||
if (circuit) {
|
||||
return circuit.admins.findIndex((admin) => admin.username === username) >= 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
|
||||
return await Account.updateOne({ idapp, username, circuitId },
|
||||
|
||||
@@ -920,7 +920,6 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
path: 'ris' + tools.convertSpaces_ToUScore(nomeprovincia.toLowerCase()),
|
||||
strProv: province,
|
||||
photos: [],
|
||||
admins: [],
|
||||
color: '#ff5500',
|
||||
deperimento: false,
|
||||
transactionsEnabled: true, // Abilita cmq il circuito dall'inizio
|
||||
@@ -966,6 +965,49 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getListAdmins = async function (idapp, circuitname) {
|
||||
|
||||
let arr = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { admins: 1 }).lean();
|
||||
|
||||
let mystr = '';
|
||||
|
||||
if (arr) {
|
||||
for (const admin of arr.admins) {
|
||||
mystr += await tools.getAhref(admin.username, await tools.getLinkUserTelegram(idapp, admin.username)) + ', ';
|
||||
}
|
||||
}
|
||||
|
||||
return {str: mystr, num: arr ? arr.admins.length : 0};
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.isAdminCircuit = async function (idapp, circuitname, username) {
|
||||
|
||||
let arr = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { admins: 1 }).lean();
|
||||
|
||||
if (arr) {
|
||||
for (const admin of arr.admins) {
|
||||
if (admin.username === username)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getListCircuitsByUsername = async function (idapp, username, groupname) {
|
||||
|
||||
let mystr = '';
|
||||
|
||||
@@ -353,16 +353,16 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', -recnotif.paramsObj.extrarec.fido_scoperto_default_grp, recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT', sender, recnotif.paramsObj.circuitnameDest,
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT', sender, -recnotif.paramsObj.extrarec.fido_scoperto_default, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
}
|
||||
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO', username_action, recnotif.paramsObj.circuitnameDest);
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO', -recnotif.paramsObj.extrarec.fido_scoperto_default, username_action, recnotif.paramsObj.circuitnameDest);
|
||||
}
|
||||
tag = 'setfido';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
@@ -415,6 +415,9 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, '<strong>' + recnotif.paramsObj.circuitnameDest + '</strong>', aportador_solidario);
|
||||
|
||||
const myadmins = await Circuit.getListAdmins(recnotif.idapp, recnotif.paramsObj.circuitnameDest);
|
||||
|
||||
newdescr += '\n' + i18n.__('CIRCUIT_ADMINS', myadmins.num, myadmins.str);
|
||||
newdescr += '\n' + i18n.__('CIRCUIT_WHERE_IS_PRESENT', await Circuit.getListCircuitsByUsername(recnotif.idapp, sender, recnotif.extrarec.groupname));
|
||||
}
|
||||
tag = 'reqcircuits';
|
||||
|
||||
@@ -416,11 +416,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
// Controlla se esiste già questo record:
|
||||
if (shared_consts.TABLES_FIELDS_DESCR_AND_CITY_AND_USER.includes(params.table)) {
|
||||
if (mytablerec.isNew) {
|
||||
const trovatoDuplicato = await mytable.findOne({idapp: mytablerec.idapp, descr: mytablerec.descr, idCity: mytablerec.idCity, userId: mytablerec.userId }).lean();
|
||||
const trovatoDuplicato = await mytable.findOne({ idapp: mytablerec.idapp, descr: mytablerec.descr, idCity: mytablerec.idCity, userId: mytablerec.userId }).lean();
|
||||
if (trovatoDuplicato) {
|
||||
// trovatoDuplicato
|
||||
return res.status(200).send({ code: server_constants.RIS_CODE_REC_DUPLICATED_DESCR_CITY_USER, msg: '' });
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -491,8 +491,8 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
const myreq = {...req};
|
||||
const myres = {...res};
|
||||
const myreq = { ...req };
|
||||
const myres = { ...res };
|
||||
SendNotif.createNewNotification(myreq, myres, { groupnameDest, circuitnameDest }, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
|
||||
@@ -798,13 +798,17 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
const fieldsvalue = mydata.fieldsvalue;
|
||||
const unset = mydata.unset;
|
||||
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
if (((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
||||
(req.user._id.toString() !== id) &&
|
||||
!tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
||||
(!tools.ModificheConsentite(mydata.table, fieldsvalue)))
|
||||
&& !((mydata.table === 'accounts') && await Account.canEditAccountAdmins(req.user.username, mydata.id))
|
||||
) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
|
||||
@@ -1082,6 +1082,11 @@ module.exports = {
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||
const mycircuit = await Circuit.findOne({name: circuitname}).lean();
|
||||
if (mycircuit) {
|
||||
extrarec.fido_scoperto_default = mycircuit.fido_scoperto_default;
|
||||
extrarec.fido_scoperto_default_grp = mycircuit.fido_scoperto_default_grp;
|
||||
}
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
@@ -3952,8 +3957,7 @@ module.exports = {
|
||||
try {
|
||||
const name = myuser.username +
|
||||
(myuser.name ? ` (${myuser.name} ${myuser.surname})` : '');
|
||||
const linkuserprof = this.getHostByIdApp(idapp) + '/my/' +
|
||||
myuser.username;
|
||||
const linkuserprof = this.getLinkUserProfile(idapp, myuser.username);
|
||||
|
||||
let u_tg = myuser.profile && myuser.profile.hasOwnProperty('username_telegram') ? myuser.profile.username_telegram : usernametelegram;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user