- fix QSelect

- permessi none/friends/all
This commit is contained in:
paoloar77
2022-01-28 18:15:56 +01:00
parent fd79893ddc
commit c391ca85c3
2 changed files with 90 additions and 6 deletions

View File

@@ -426,6 +426,22 @@ UserSchema.statics.setZoomPresenza = async function(idapp, id, presenza) {
};
UserSchema.statics.canHavePower = function(perm) {
const User = this;
try {
let consentito = false;
if (User.isAdmin(perm) || User.isManager(perm) ||
User.isEditor(perm) || User.isTutor(perm)) {
consentito = true;
}
return consentito;
} catch (e) {
return false;
}
};
UserSchema.statics.isAdmin = function(perm) {
try {
return ((perm & shared_consts.Permissions.Admin) ===
@@ -1185,13 +1201,82 @@ UserSchema.statics.getUserById = function(idapp, id) {
});
};
UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
UserSchema.statics.isMyFriend = async function(idapp, username, myusername) {
let perm = tools.Perm.PERM_ALL; //++Todo: sistemare
const myfriends = await User.getUsernameFriendsByUsername(idapp, myusername);
if (myfriends) {
return myfriends.includes(username);
} else {
return false;
}
};
UserSchema.statics.getUserProfileByUsername = async function(idapp, username, myusername, usaSuperPower, myperm = '') {
const User = this;
// If is my Friend, then can show all
const ismyfriend = await User.isMyFriend(idapp, username, myusername);
let perm = tools.Perm.PERM_NONE;
if (ismyfriend) {
perm = tools.Perm.PERM_FRIEND;
}
if (username === myusername) {
perm = tools.Perm.PERM_ALL;
} else {
if (await User.canHavePower(myperm) && usaSuperPower) {
perm = tools.Perm.PERM_ALL;
}
}
let whatToShow = {};
if (perm === tools.Perm.PERM_ALL) {
if (perm === tools.Perm.PERM_NONE) {
whatToShow = {
lang: 1,
index: 1,
username: 1,
deleted: 1,
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
date_reg: 1,
'profile.img': 1,
};
} else if (perm === tools.Perm.PERM_FRIEND) {
whatToShow = {
lang: 1,
index: 1,
username: 1,
aportador_solidario: 1,
name: 1,
surname: 1,
deleted: 1,
sospeso: 1,
verified_email: 1,
verified_by_aportador: 1,
'profile.nationality': 1,
'profile.qualifica': 1,
'profile.biografia': 1,
'profile.teleg_id': 1,
'profile.username_telegram': 1,
'profile.website': 1,
'profile.img': 1,
'profile.sex': 1,
'profile.dateofbirth': 1,
'profile.born_city': 1,
'profile.born_province': 1,
'profile.born_country': 1,
email: 1,
date_reg: 1,
};
} else if (perm === tools.Perm.PERM_ALL) {
whatToShow = {
lang: 1,
index: 1,
@@ -1217,7 +1302,6 @@ UserSchema.statics.getUserProfileByUsername = async function(idapp, username) {
'profile.born_country': 1,
email: 1,
date_reg: 1,
img: 1,
};
}
@@ -1345,7 +1429,7 @@ UserSchema.statics.setFriendsCmd = async function(
ris = await User.getInfoFriendByUsername(idapp, usernameDest);
}
} else if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
// Aggiungo l'Amicizia a me
// Aggiungo la richiesta di Amicizia a me
const foundIfAlreadyAskFriend = await User.findOne({
idapp,
username: usernameDest,