l'admin non riesce a cambiare il fido degli utenti...
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user