- Refused User

- Report User
- Unblock User
- refresh tables when an action (setFriends and setGroups) occurred.
- fix duplicate call of loadsite
This commit is contained in:
paoloar77
2022-08-08 16:35:32 +02:00
parent e433d3db8c
commit fc8e8d8034
7 changed files with 182 additions and 59 deletions

View File

@@ -5,7 +5,6 @@ const tools = require('../tools/general');
const shared_consts = require('../tools/shared_nodejs');
mongoose.Promise = global.Promise;
mongoose.level = 'F';
@@ -99,6 +98,12 @@ const MyGroupSchema = new Schema({
username: {type: String},
date: {type: Date},
}], // username
refused_users: [
{
_id: false,
username: {type: String},
date: {type: Date},
}], // username
deleted: {
type: Boolean,
default: false,
@@ -112,7 +117,7 @@ MyGroupSchema.statics.getFieldsForSearch = function() {
MyGroupSchema.statics.executeQueryTable = function(idapp, params, user) {
params.fieldsearch = this.getFieldsForSearch();
const { User } = require('./user');
const {User} = require('./user');
if (params.options) {
if (tools.isBitActive(params.options, shared_consts.OPTIONS_SEARCH_USER_ONLY_FULL_WORDS)) {
@@ -144,8 +149,6 @@ MyGroupSchema.pre('save', async function(next) {
next();
});
MyGroupSchema.statics.findAllIdApp = async function(idapp) {
const myfind = {idapp};
@@ -171,7 +174,23 @@ MyGroupSchema.statics.removeReqGroup = async function(idapp, username, groupname
{$pull: {req_users: {username: {$in: [username]}}}});
};
MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
// Aggiungi agli utenti Rifiutati del Gruppo
MyGroupSchema.statics.refuseReqGroup = async function(idapp, username, groupnameDest) {
return MyGroup.updateOne({idapp, groupname: groupnameDest},
{
$push:
{
refused_users: {
username,
date: new Date(),
},
},
});
};
MyGroupSchema.statics.getWhatToShow = function(idapp, username) {
// FOR ME, PERMIT ALL
return {
groupname: 1,
@@ -189,11 +208,12 @@ MyGroupSchema.statics.getWhatToShow = function (idapp, username) {
admins: 1,
blocked: 1,
req_users: 1,
refused_users: 1,
};
}
};
MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
MyGroupSchema.statics.getWhatToShow_Unknown = function(idapp, username) {
return {
groupname: 1,
title: 1,
@@ -204,7 +224,7 @@ MyGroupSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
idCity: 1,
note: 1,
};
}
};
MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
idapp, groupname, field) {
@@ -227,13 +247,6 @@ MyGroupSchema.statics.getArrUsernameFromFieldByGroupname = async function(
};
MyGroupSchema.statics.getUsernameReqGroupsByGroupname = async function(
idapp, groupname) {
return this.getArrUsernameFromFieldByGroupname(idapp, groupname, 'req_users');
};
MyGroupSchema.statics.getInfoGroupByGroupname = async function(idapp, groupname) {
const whatToShow = this.getWhatToShow(idapp, groupname);
@@ -252,8 +265,6 @@ MyGroupSchema.statics.deleteGroup = async function(idapp, usernameOrig, groupnam
return MyGroup.findOneAndRemove({idapp, groupname});
};
MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req) {
try {
@@ -300,11 +311,21 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
{deleted: {$exists: true, $eq: false}}],
}, whatToShow_Unknown);
let listRefusedGroups = await MyGroup.find({
idapp,
'refused_users': {
$elemMatch: {username: {$eq: username}},
},
$or: [
{deleted: {$exists: false}},
{deleted: {$exists: true, $eq: false}}],
}, whatToShow_Unknown);
return {
listUsersGroup,
listgroups,
//listRequestUsersGroup,
listSentRequestGroups,
listRefusedGroups,
mygroups: req.user.profile.mygroups,
};
@@ -317,6 +338,7 @@ MyGroupSchema.statics.getGroupsByUsername = async function(idapp, username, req)
listRequestUsersGroup: [],
listTrusted: [],
listSentRequestGroups: [],
listRefusedGroups: [],
};
};