Add to the Circuit
Remove to the Circuit Revoke request Users Admins
This commit is contained in:
@@ -965,7 +965,7 @@ module.exports = {
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_GROUPS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuseringroup = await User.countUsersInGroup(idapp, groupname);
|
||||
let name = await User.countUsersInGroup(idapp, groupname);
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.GROUPSCMD.SETGROUP) {
|
||||
@@ -1005,6 +1005,72 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
sendNotifCircuitByUsername: async function(
|
||||
cmd, idapp, usernameOrig, usernameDest, username_action, circuitname, path, myreccircuit, isAdmin, username_worked) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const {User} = require('../models/user');
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const req = this.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
const user = await User.findOne({idapp, username: usernameDest},
|
||||
{_id: 1, lang: 1});
|
||||
if (user) {
|
||||
|
||||
let lang = user.lang;
|
||||
let paramsObj = {
|
||||
usernameDest,
|
||||
circuitnameDest: circuitname,
|
||||
path,
|
||||
username_action: username_action,
|
||||
singleadmin_username: usernameDest,
|
||||
options: 0,
|
||||
lang,
|
||||
isAdmin,
|
||||
username_worked,
|
||||
};
|
||||
|
||||
let sendnotif = true;
|
||||
let typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
if (myreccircuit && myreccircuit.createdBy === usernameDest && numuserincircuit <= 1) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
} else {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED;
|
||||
}
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REFUSE_REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REFUSED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||
myreccircuit._id);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN_OFMYGROUP;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN_OFMYGROUP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (sendnotif && typeid > 0) {
|
||||
// CREATE NOTIFICATION IN TABLE SENDNOTIF
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, paramsObj, onlysave, typedir, typeid);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
sendNotificationByGroupname: async function(idapp, usernameOrig, groupname, cmd, value, telegram, username_action) {
|
||||
|
||||
const {MyGroup} = require('../models/mygroup');
|
||||
@@ -1033,7 +1099,7 @@ module.exports = {
|
||||
|
||||
if (!giainviato && (cmd !== shared_consts.GROUPSCMD.REQGROUP)) {
|
||||
// SEND TO THE USER THE NOTIFICATION
|
||||
await this.sendNotifGroupByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, groupname, false);
|
||||
await this.sendNotifGroupByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, groupname, null, false);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
@@ -1042,6 +1108,45 @@ module.exports = {
|
||||
|
||||
},
|
||||
|
||||
sendNotificationByCircuit: async function(idapp, usernameOrig, circuitname, cmd, value, telegram, username_action) {
|
||||
|
||||
const {Circuit} = require('../models/circuit');
|
||||
const {User} = require('../models/user');
|
||||
|
||||
const circuit = await Circuit.findOne({idapp, name: circuitname}, {_id: 1, admins: 1, createdBy: 1, path: 1}).lean();
|
||||
if (!circuit)
|
||||
return;
|
||||
|
||||
let giainviato = false;
|
||||
|
||||
try {
|
||||
// SEND TO THE ADMINS THE NOTIFICATIONS
|
||||
for (const singleadmin of circuit.admins) {
|
||||
try {
|
||||
if (singleadmin.username) {
|
||||
if (usernameOrig === singleadmin.username)
|
||||
giainviato = true;
|
||||
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, singleadmin.username, username_action, circuitname,
|
||||
circuit.path, circuit, true);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByCircuit', e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!giainviato && (cmd !== shared_consts.CIRCUITCMD.REQ)) {
|
||||
// SEND TO THE USER THE NOTIFICATION
|
||||
await this.sendNotifCircuitByUsername(cmd, idapp, usernameOrig, usernameOrig, username_action, circuitname, circuit.path, null,
|
||||
false);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('sendNotificationByCircuit: ', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// **********************
|
||||
// SORT WITH PREV_ID
|
||||
// **********************
|
||||
@@ -1433,6 +1538,32 @@ module.exports = {
|
||||
return query;
|
||||
},
|
||||
|
||||
addQueryIdMatch: function(params) {
|
||||
|
||||
myquery = {};
|
||||
|
||||
if (shared_consts.TABLES_ID_NUMBER.includes(params.table)) {
|
||||
myquery = {
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ['$_id', params.myid],
|
||||
},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
myquery = {
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ['$_id', mongoose.Types.ObjectId(params.myid)],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return myquery;
|
||||
},
|
||||
|
||||
getQueryTable: function(idapp, params, user) {
|
||||
|
||||
if (typeof params.startRow !== 'number') {
|
||||
@@ -1653,13 +1784,11 @@ module.exports = {
|
||||
numrowend = 1;
|
||||
|
||||
if (params.querytype === shared_consts.QUERYTYPE_MYGROUP || params.querytype === shared_consts.QUERYTYPE_CIRCUIT) {
|
||||
query.push({
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ['$_id', params.myid],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const myq = this.addQueryIdMatch(params);
|
||||
if (myq)
|
||||
query.push(myq);
|
||||
|
||||
query.push({$project: {req_users: 1}});
|
||||
const qa1 = this.getLookup(
|
||||
{
|
||||
@@ -1690,14 +1819,13 @@ module.exports = {
|
||||
},
|
||||
);
|
||||
|
||||
} else if (params.querytype === shared_consts.QUERYTYPE_REFUSED_USER_GRP || params.querytype === shared_consts.QUERYTYPE_REFUSED_USER_CIRCUIT) {
|
||||
query.push({
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ['$_id', params.myid],
|
||||
},
|
||||
},
|
||||
});
|
||||
} else if (params.querytype === shared_consts.QUERYTYPE_REFUSED_USER_GRP || params.querytype ===
|
||||
shared_consts.QUERYTYPE_REFUSED_USER_CIRCUIT) {
|
||||
|
||||
const myq = this.addQueryIdMatch(params);
|
||||
if (myq)
|
||||
query.push(myq);
|
||||
|
||||
query.push({$project: {refused_users: 1}});
|
||||
const qa1 = this.getLookup(
|
||||
{
|
||||
@@ -1861,11 +1989,11 @@ module.exports = {
|
||||
// BINARY CHECK (?): const filter = [{ visibility: { $bitsAnyClear: [1] } }];
|
||||
// if (!User.isAdmin(req.user.perm)) {
|
||||
// not Visibility_Group.HIDDEN
|
||||
if (true && !filteradmin) {
|
||||
if (!filteradmin) {
|
||||
const filter = [
|
||||
{
|
||||
visibility: {
|
||||
$nin: [shared_consts.Visibility_Group.HIDDEN]
|
||||
$nin: [shared_consts.Visibility_Group.HIDDEN],
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -1880,7 +2008,7 @@ module.exports = {
|
||||
if (q1) query = [...query, ...q1];
|
||||
}
|
||||
|
||||
query.push (
|
||||
query.push(
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
@@ -2929,6 +3057,9 @@ module.exports = {
|
||||
|
||||
convertSpecialTags(user, msg) {
|
||||
try {
|
||||
if (!msg)
|
||||
return msg;
|
||||
|
||||
if (!!user) {
|
||||
msg = msg.replace('{appname}', this.getNomeAppByIdApp(user.idapp));
|
||||
msg = msg.replace('{username}', user.username);
|
||||
|
||||
Reference in New Issue
Block a user