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);
|
||||
|
||||
@@ -332,6 +332,16 @@ module.exports = {
|
||||
} else {
|
||||
invia = false;
|
||||
}
|
||||
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_CIRCUIT) {
|
||||
if (params.circuitnameDest) {
|
||||
addquery = {
|
||||
'profile.mycircuits': {
|
||||
$elemMatch: {circuitname: {$eq: params.circuitnameDest}},
|
||||
},
|
||||
};
|
||||
} else {
|
||||
invia = false;
|
||||
}
|
||||
}
|
||||
|
||||
let numrec = 0;
|
||||
|
||||
@@ -71,7 +71,11 @@ module.exports = {
|
||||
REQ: 2000,
|
||||
SET: 2001,
|
||||
REMOVE_FROM_MYLIST: 2144,
|
||||
REFUSE_REQ: 2145,
|
||||
CANCEL_REQ: 1146,
|
||||
DELETE: 2170,
|
||||
ADDADMIN: 2180,
|
||||
REMOVEADMIN: 2185,
|
||||
},
|
||||
|
||||
REPORT_FILT_RESP: 1,
|
||||
@@ -87,6 +91,7 @@ module.exports = {
|
||||
TAB_SETTINGS: 'settings',
|
||||
TAB_SITES: 'sites',
|
||||
TAB_MYGROUPS: 'mygroups',
|
||||
TAB_MYCIRCUITS: 'circuits',
|
||||
TAB_BOTS: 'bots',
|
||||
TAB_USERS: 'users',
|
||||
|
||||
@@ -115,7 +120,7 @@ module.exports = {
|
||||
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups'],
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'],
|
||||
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps'],
|
||||
TABLES_REC_ID: ['skills', 'goods', 'subskills'],
|
||||
@@ -125,6 +130,7 @@ module.exports = {
|
||||
TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'],
|
||||
TABLES_EVENTS_NOTIFICATION: ['mybachecas'],
|
||||
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
||||
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
||||
|
||||
TABLES_ID_NUMBER: [
|
||||
'permissions',
|
||||
@@ -144,7 +150,6 @@ module.exports = {
|
||||
'myhosps',
|
||||
'mygoods',
|
||||
'mygroups',
|
||||
'circuits',
|
||||
'movements'],
|
||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_CREATEDBY: ['mygroups', 'circuits'],
|
||||
@@ -238,6 +243,7 @@ module.exports = {
|
||||
SEND_TO_PAOLO: 20,
|
||||
SEND_TO_USER: 25,
|
||||
SEND_TO_GROUP: 30,
|
||||
SEND_TO_CIRCUIT: 35,
|
||||
SEND_TO_MYSELF: 40,
|
||||
SEND_TO_TELEG_NO_USERNAME_TELEG: 50,
|
||||
SEND_TO_TELEG_NO_VERIF_BY_APORTADOR: 60,
|
||||
@@ -260,6 +266,7 @@ module.exports = {
|
||||
REGISTRATION: 6,
|
||||
RICHIESTA_GRUPPO: 10,
|
||||
RICHIESTA_AMICIZIA: 15,
|
||||
RICHIESTA_CIRCUIT: 20,
|
||||
},
|
||||
|
||||
OrderStatus: {
|
||||
@@ -325,6 +332,15 @@ module.exports = {
|
||||
STATUS_GROUPS_REMOVED: 7,
|
||||
},
|
||||
|
||||
CircuitsNotif: {
|
||||
STATUS_NEW: 51,
|
||||
STATUS_ACCEPTED: 53,
|
||||
STATUS_REFUSED: 54,
|
||||
STATUS_BLOCKED: 55,
|
||||
STATUS_DELETED: 56,
|
||||
STATUS_REMOVED: 57,
|
||||
},
|
||||
|
||||
TypeNotifs: {
|
||||
TYPEDIR_BACHECA: 1,
|
||||
ID_BACHECA_NEW_GOOD: 1,
|
||||
@@ -354,6 +370,15 @@ module.exports = {
|
||||
ID_GROUP_REMOVED_ADMIN_OFMYGROUP: 256,
|
||||
|
||||
TYPEDIR_CIRCUITS: 5,
|
||||
ID_CIRCUIT_NEW_REC: 1,
|
||||
ID_CIRCUIT_ACCEPTED: 2,
|
||||
ID_CIRCUIT_REFUSED: 4,
|
||||
ID_CIRCUIT_REQUEST_TO_ENTER: 8,
|
||||
ID_CIRCUIT_BLOCK_USER: 16,
|
||||
ID_CIRCUIT_DELETE_USER: 32,
|
||||
ID_CIRCUIT_REMOVED: 64,
|
||||
ID_CIRCUIT_ADDED_ADMIN: 128,
|
||||
ID_CIRCUIT_REMOVED_ADMIN: 256,
|
||||
|
||||
TYPEDIR_BOOKING: 6,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user