mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
isInvited mechanic for #2758
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
} else {
|
||||
if (groupObj.isPending) {
|
||||
return '<button class="btn btn-warning disabled"><i class="fa fa-clock-o"></i> Invitation Pending</button>';
|
||||
} else if (groupObj.isInvited) {
|
||||
return '<button class="btn btn-link" data-action="rejectInvite" data-group="' + groupObj.name + '">Reject</button><button class="btn btn-success" data-action="acceptInvite" data-group="' + groupObj.name + '"><i class="fa fa-plus"></i> Accept Invitation</button>';
|
||||
} else {
|
||||
return '<button class="btn btn-success" data-action="join" data-group="' + groupObj.name + '"><i class="fa fa-plus"></i> Join Group</button>';
|
||||
}
|
||||
|
||||
@@ -42,7 +42,12 @@ groupsController.details = function(req, res, next) {
|
||||
next(null, true);
|
||||
} else {
|
||||
// If not, only members are granted access
|
||||
groups.isMember(uid, res.locals.groupName, next);
|
||||
async.parallel([
|
||||
async.apply(groups.isMember, uid, res.locals.groupName),
|
||||
async.apply(groups.isInvited, uid, res.locals.groupName)
|
||||
], function(err, checks) {
|
||||
next(err, checks[0] || checks[1]);
|
||||
});
|
||||
}
|
||||
}
|
||||
], function(err, ok) {
|
||||
|
||||
@@ -31,7 +31,7 @@ var async = require('async'),
|
||||
if (!group) {
|
||||
return false;
|
||||
}
|
||||
if (group.deleted || (group.hidden && !group.system && !group.isMember && !options.isAdmin) || (!options.showSystemGroups && group.system)) {
|
||||
if (group.deleted || (group.hidden && !(group.system || group.isMember || options.isAdmin || group.isInvited)) || (!options.showSystemGroups && group.system)) {
|
||||
return false;
|
||||
} else if (options.removeEphemeralGroups && ephemeralGroups.indexOf(group.name) !== -1) {
|
||||
return false;
|
||||
@@ -179,6 +179,7 @@ var async = require('async'),
|
||||
|
||||
db.isSetMember('group:' + groupName + ':pending', options.uid, next);
|
||||
},
|
||||
isInvited: async.apply(Groups.isInvited, options.uid, groupName),
|
||||
isOwner: function(next) {
|
||||
// Retrieve group ownership state, if uid is passed in
|
||||
if (!options.uid) {
|
||||
@@ -228,6 +229,7 @@ var async = require('async'),
|
||||
results.base.truncated = truncated;
|
||||
results.base.isMember = results.isMember;
|
||||
results.base.isPending = results.isPending;
|
||||
results.base.isInvited = results.isInvited;
|
||||
results.base.isOwner = results.isOwner;
|
||||
|
||||
|
||||
@@ -408,6 +410,11 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Groups.isInvited = function(uid, groupName, callback) {
|
||||
if (!uid) { return callback(null, false); }
|
||||
db.isSetMember('group:' + groupName + ':invited', uid, callback);
|
||||
};
|
||||
|
||||
Groups.exists = function(name, callback) {
|
||||
if (Array.isArray(name)) {
|
||||
var slugs = name.map(function(groupName) {
|
||||
@@ -607,6 +614,7 @@ var async = require('async'),
|
||||
async.apply(db.rename, 'group:' + oldName + ':members', 'group:' + newName + ':members'),
|
||||
async.apply(db.rename, 'group:' + oldName + ':owners', 'group:' + newName + ':owners'),
|
||||
async.apply(db.rename, 'group:' + oldName + ':pending', 'group:' + newName + ':pending'),
|
||||
async.apply(db.rename, 'group:' + oldName + ':invited', 'group:' + newName + ':invited'),
|
||||
async.apply(renameGroupMember, 'groups:createtime', oldName, newName),
|
||||
function(next) {
|
||||
plugins.fireHook('action:group.rename', {
|
||||
@@ -651,6 +659,7 @@ var async = require('async'),
|
||||
async.apply(db.sortedSetRemove, 'groups:createtime', groupName),
|
||||
async.apply(db.delete, 'group:' + groupName + ':members'),
|
||||
async.apply(db.delete, 'group:' + groupName + ':pending'),
|
||||
async.apply(db.delete, 'group:' + groupName + ':invited'),
|
||||
async.apply(db.delete, 'group:' + groupName + ':owners'),
|
||||
async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)),
|
||||
function(next) {
|
||||
@@ -747,18 +756,41 @@ var async = require('async'),
|
||||
Groups.acceptMembership = function(groupName, uid, callback) {
|
||||
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.setRemove('group:' + groupName + ':pending', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
Groups.join(groupName, uid, next);
|
||||
}
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':invited', uid),
|
||||
async.apply(Groups.join, groupName, uid)
|
||||
], callback);
|
||||
};
|
||||
|
||||
Groups.rejectMembership = function(groupName, uid, callback) {
|
||||
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
|
||||
db.setRemove('group:' + groupName + ':pending', uid, callback);
|
||||
async.parallel([
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
|
||||
async.apply(db.setRemove, 'group:' + groupName + ':invited', uid)
|
||||
], callback);
|
||||
};
|
||||
|
||||
Groups.invite = function(groupName, uid, callback) {
|
||||
async.parallel({
|
||||
exists: async.apply(Groups.exists, groupName),
|
||||
isMember: async.apply(Groups.isMember, uid, groupName)
|
||||
}, function(err, checks) {
|
||||
if (!checks.exists) {
|
||||
return callback(new Error('[[error:no-group]]'));
|
||||
} else if (checks.isMember) {
|
||||
return callback(new Error('[[error:group-already-member]]'));
|
||||
}
|
||||
|
||||
if (parseInt(uid, 10) > 0) {
|
||||
db.setAdd('group:' + groupName + ':invited', uid, callback);
|
||||
plugins.fireHook('action:group.inviteMember', {
|
||||
groupName: groupName,
|
||||
uid: uid
|
||||
});
|
||||
} else {
|
||||
callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Groups.leave = function(groupName, uid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user