restric newsOnly groups from posting
This commit is contained in:
@@ -352,6 +352,12 @@ userDB = (DB) => {
|
|||||||
return g ? g.isPrivate : false;
|
return g ? g.isPrivate : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB.isGroupNewsOnly = async (groupid) => {
|
||||||
|
if(userProfileCache[groupid]) return userProfileCache[groupid].newsOnly;
|
||||||
|
let g = await DB.getGroup(groupid);
|
||||||
|
return g ? g.newsOnly : false;
|
||||||
|
}
|
||||||
|
|
||||||
DB.isOwnerOfGroup = async (profileid, groupid) => {
|
DB.isOwnerOfGroup = async (profileid, groupid) => {
|
||||||
let profile = await DB.getProfileCache(profileid);
|
let profile = await DB.getProfileCache(profileid);
|
||||||
let group = userProfileCache[groupid] ? userProfileCache[groupid] : await DB.getGroup(groupid);
|
let group = userProfileCache[groupid] ? userProfileCache[groupid] : await DB.getGroup(groupid);
|
||||||
|
|||||||
@@ -141,7 +141,9 @@ DB.getDB.then((DB) => {
|
|||||||
profileid: getProfileId(req),
|
profileid: getProfileId(req),
|
||||||
...req.body
|
...req.body
|
||||||
}
|
}
|
||||||
if (post.toProfile && await DB.isGroupPrivate(post.toProfile)) {
|
const isGroupPrivate = await DB.isGroupPrivate(post.toProfile);
|
||||||
|
const isGroupNewsOnly = await DB.isGroupNewsOnly(post.toProfile);
|
||||||
|
if (post.toProfile && isGroupPrivate) {
|
||||||
let requestProfile = getProfileId(req) + "";
|
let requestProfile = getProfileId(req) + "";
|
||||||
let group = await DB.getProfileCache(post.toProfile);
|
let group = await DB.getProfileCache(post.toProfile);
|
||||||
if (!group.subscribed[requestProfile] && group._id != requestProfile) {
|
if (!group.subscribed[requestProfile] && group._id != requestProfile) {
|
||||||
@@ -150,6 +152,11 @@ DB.getDB.then((DB) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (post.toProfile && isGroupNewsOnly) {
|
||||||
|
return res.json({
|
||||||
|
status: "This is a news only group, only the admin can post",
|
||||||
|
});
|
||||||
|
}
|
||||||
post.toProfile = post.toProfile ? DB.ObjectID(post.toProfile) : undefined;
|
post.toProfile = post.toProfile ? DB.ObjectID(post.toProfile) : undefined;
|
||||||
let postObj = new Post(post);
|
let postObj = new Post(post);
|
||||||
let dbr = await DB.newPost(postObj);
|
let dbr = await DB.newPost(postObj);
|
||||||
|
|||||||
Reference in New Issue
Block a user