mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
refactor: async/await for src/socket.io/groups.js
This commit is contained in:
@@ -189,3 +189,5 @@ groupsController.uploadCover = function (req, res, next) {
|
|||||||
res.json([{ url: image.url }]);
|
res.json([{ url: image.url }]);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
require('../promisify')(groupsController);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
var groups = require('../groups');
|
var groups = require('../groups');
|
||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
@@ -12,119 +10,101 @@ var privileges = require('../privileges');
|
|||||||
|
|
||||||
var SocketGroups = module.exports;
|
var SocketGroups = module.exports;
|
||||||
|
|
||||||
SocketGroups.before = function (socket, method, data, next) {
|
SocketGroups.before = async (socket, method, data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return next(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
next();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.join = function (socket, data, callback) {
|
SocketGroups.join = async (socket, data) => {
|
||||||
if (socket.uid <= 0) {
|
if (socket.uid <= 0) {
|
||||||
return callback(new Error('[[error:invalid-uid]]'));
|
throw new Error('[[error:invalid-uid]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
||||||
return callback(new Error('[[error:not-allowed]]'));
|
throw new Error('[[error:not-allowed]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
const exists = await groups.exists(data.groupName);
|
||||||
function (next) {
|
|
||||||
groups.exists(data.groupName, next);
|
|
||||||
},
|
|
||||||
function (exists, next) {
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
return next(new Error('[[error:no-group]]'));
|
throw new Error('[[error:no-group]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!meta.config.allowPrivateGroups) {
|
if (!meta.config.allowPrivateGroups) {
|
||||||
groups.join(data.groupName, socket.uid, callback);
|
await groups.join(data.groupName, socket.uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async.parallel({
|
const results = await utils.promiseParallel({
|
||||||
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
isAdmin: await user.isAdministrator(socket.uid),
|
||||||
groupData: async.apply(groups.getGroupData, data.groupName),
|
groupData: await groups.getGroupData(data.groupName),
|
||||||
}, next);
|
});
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
if (results.groupData.private && results.groupData.disableJoinRequests) {
|
if (results.groupData.private && results.groupData.disableJoinRequests) {
|
||||||
return next(new Error('[[error:join-requests-disabled]]'));
|
throw new Error('[[error:join-requests-disabled]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.groupData.private || results.isAdmin) {
|
if (!results.groupData.private || results.isAdmin) {
|
||||||
groups.join(data.groupName, socket.uid, next);
|
await groups.join(data.groupName, socket.uid);
|
||||||
} else {
|
} else {
|
||||||
groups.requestMembership(data.groupName, socket.uid, next);
|
await groups.requestMembership(data.groupName, socket.uid);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.leave = function (socket, data, callback) {
|
SocketGroups.leave = async (socket, data) => {
|
||||||
if (socket.uid <= 0) {
|
if (socket.uid <= 0) {
|
||||||
return callback(new Error('[[error:invalid-uid]]'));
|
throw new Error('[[error:invalid-uid]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.groupName === 'administrators') {
|
if (data.groupName === 'administrators') {
|
||||||
return callback(new Error('[[error:cant-remove-self-as-admin]]'));
|
throw new Error('[[error:cant-remove-self-as-admin]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.leave(data.groupName, socket.uid, callback);
|
await groups.leave(data.groupName, socket.uid);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.addMember = isOwner(function (socket, data, callback) {
|
SocketGroups.addMember = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
if (data.groupName === 'administrators' || groups.isPrivilegeGroup(data.groupName)) {
|
||||||
return callback(new Error('[[error:not-allowed]]'));
|
throw new Error('[[error:not-allowed]]');
|
||||||
}
|
}
|
||||||
groups.join(data.groupName, data.uid, callback);
|
await groups.join(data.groupName, data.uid);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function isOwner(socket, data) {
|
||||||
|
const results = await utils.promiseParallel({
|
||||||
|
isAdmin: await user.isAdministrator(socket.uid),
|
||||||
|
isGlobalModerator: await user.isGlobalModerator(socket.uid),
|
||||||
|
isOwner: await groups.ownership.isOwner(socket.uid, data.groupName),
|
||||||
|
group: await groups.getGroupData(data.groupName),
|
||||||
});
|
});
|
||||||
|
|
||||||
function isOwner(next) {
|
|
||||||
return function (socket, data, callback) {
|
|
||||||
async.parallel({
|
|
||||||
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
|
||||||
isGlobalModerator: async.apply(user.isGlobalModerator, socket.uid),
|
|
||||||
isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName),
|
|
||||||
group: async.apply(groups.getGroupData, data.groupName),
|
|
||||||
}, function (err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
var isOwner = results.isOwner || results.isAdmin || (results.isGlobalModerator && !results.group.system);
|
var isOwner = results.isOwner || results.isAdmin || (results.isGlobalModerator && !results.group.system);
|
||||||
if (!isOwner) {
|
if (!isOwner) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
next(socket, data, callback);
|
}
|
||||||
});
|
|
||||||
|
async function isInvited(socket, data) {
|
||||||
|
const invited = await groups.isInvited(socket.uid, data.groupName);
|
||||||
|
if (!invited) {
|
||||||
|
throw new Error('[[error:not-invited]]');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketGroups.grant = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
|
await groups.ownership.grant(data.toUid, data.groupName);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function isInvited(next) {
|
SocketGroups.rescind = async (socket, data) => {
|
||||||
return function (socket, data, callback) {
|
await isOwner(socket, data);
|
||||||
groups.isInvited(socket.uid, data.groupName, function (err, invited) {
|
await groups.ownership.rescind(data.toUid, data.groupName);
|
||||||
if (err || !invited) {
|
|
||||||
return callback(err || new Error('[[error:not-invited]]'));
|
|
||||||
}
|
|
||||||
next(socket, data, callback);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
SocketGroups.grant = isOwner(function (socket, data, callback) {
|
SocketGroups.accept = async (socket, data) => {
|
||||||
groups.ownership.grant(data.toUid, data.groupName, callback);
|
await isOwner(socket, data);
|
||||||
});
|
await groups.acceptMembership(data.groupName, data.toUid);
|
||||||
|
|
||||||
SocketGroups.rescind = isOwner(function (socket, data, callback) {
|
|
||||||
groups.ownership.rescind(data.toUid, data.groupName, callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.accept = isOwner(function (socket, data, callback) {
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
groups.acceptMembership(data.groupName, data.toUid, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
events.log({
|
events.log({
|
||||||
type: 'accept-membership',
|
type: 'accept-membership',
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
@@ -132,17 +112,11 @@ SocketGroups.accept = isOwner(function (socket, data, callback) {
|
|||||||
groupName: data.groupName,
|
groupName: data.groupName,
|
||||||
targetUid: data.toUid,
|
targetUid: data.toUid,
|
||||||
});
|
});
|
||||||
setImmediate(next);
|
};
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.reject = isOwner(function (socket, data, callback) {
|
SocketGroups.reject = async (socket, data) => {
|
||||||
async.waterfall([
|
await isOwner(socket, data);
|
||||||
function (next) {
|
await groups.rejectMembership(data.groupName, data.toUid);
|
||||||
groups.rejectMembership(data.groupName, data.toUid, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
events.log({
|
events.log({
|
||||||
type: 'reject-membership',
|
type: 'reject-membership',
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
@@ -150,218 +124,179 @@ SocketGroups.reject = isOwner(function (socket, data, callback) {
|
|||||||
groupName: data.groupName,
|
groupName: data.groupName,
|
||||||
targetUid: data.toUid,
|
targetUid: data.toUid,
|
||||||
});
|
});
|
||||||
setImmediate(next);
|
};
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.acceptAll = isOwner(function (socket, data, callback) {
|
SocketGroups.acceptAll = async (socket, data) => {
|
||||||
acceptRejectAll(SocketGroups.accept, socket, data, callback);
|
await isOwner(socket, data);
|
||||||
});
|
await acceptRejectAll(SocketGroups.accept, socket, data);
|
||||||
|
};
|
||||||
|
|
||||||
SocketGroups.rejectAll = isOwner(function (socket, data, callback) {
|
SocketGroups.rejectAll = async (socket, data) => {
|
||||||
acceptRejectAll(SocketGroups.reject, socket, data, callback);
|
await isOwner(socket, data);
|
||||||
});
|
await acceptRejectAll(SocketGroups.reject, socket, data);
|
||||||
|
};
|
||||||
|
|
||||||
function acceptRejectAll(method, socket, data, callback) {
|
async function acceptRejectAll(method, socket, data) {
|
||||||
async.waterfall([
|
const uids = groups.getPending(data.groupName);
|
||||||
function (next) {
|
await new Promise(uids.forEach(async (uid) => {
|
||||||
groups.getPending(data.groupName, next);
|
await method(socket, { groupName: data.groupName, toUid: uid });
|
||||||
},
|
}));
|
||||||
function (uids, next) {
|
|
||||||
async.each(uids, function (uid, next) {
|
|
||||||
method(socket, { groupName: data.groupName, toUid: uid }, next);
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketGroups.issueInvite = isOwner(function (socket, data, callback) {
|
SocketGroups.issueInvite = async (socket, data) => {
|
||||||
groups.invite(data.groupName, data.toUid, callback);
|
await isOwner(socket, data);
|
||||||
});
|
await groups.invite(data.groupName, data.toUid);
|
||||||
|
};
|
||||||
|
|
||||||
SocketGroups.issueMassInvite = isOwner(function (socket, data, callback) {
|
SocketGroups.issueMassInvite = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
if (!data || !data.usernames || !data.groupName) {
|
if (!data || !data.usernames || !data.groupName) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
var usernames = String(data.usernames).split(',');
|
var usernames = String(data.usernames).split(',');
|
||||||
usernames = usernames.map(function (username) {
|
usernames = usernames.map(function (username) {
|
||||||
return username && username.trim();
|
return username && username.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
async.waterfall([
|
let uids = await user.getUidsByUsernames(usernames);
|
||||||
function (next) {
|
|
||||||
user.getUidsByUsernames(usernames, next);
|
|
||||||
},
|
|
||||||
function (uids, next) {
|
|
||||||
uids = uids.filter(function (uid) {
|
uids = uids.filter(function (uid) {
|
||||||
return !!uid && parseInt(uid, 10);
|
return !!uid && parseInt(uid, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
async.eachSeries(uids, function (uid, next) {
|
// eslint-disable-next-line guard-for-in
|
||||||
groups.invite(data.groupName, uid, next);
|
for (const i in uids) {
|
||||||
}, next);
|
// eslint-disable-next-line no-await-in-loop
|
||||||
},
|
await groups.invite(data.groupName, uids[i]);
|
||||||
], callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.rescindInvite = isOwner(function (socket, data, callback) {
|
|
||||||
groups.rejectMembership(data.groupName, data.toUid, callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.acceptInvite = isInvited(function (socket, data, callback) {
|
|
||||||
groups.acceptMembership(data.groupName, socket.uid, callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.rejectInvite = isInvited(function (socket, data, callback) {
|
|
||||||
groups.rejectMembership(data.groupName, socket.uid, callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.update = isOwner(function (socket, data, callback) {
|
|
||||||
groups.update(data.groupName, data.values, callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
SocketGroups.kick = isOwner(function (socket, data, callback) {
|
|
||||||
if (socket.uid === parseInt(data.uid, 10)) {
|
|
||||||
return callback(new Error('[[error:cant-kick-self]]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
groups.ownership.isOwner(data.uid, data.groupName, next);
|
|
||||||
},
|
|
||||||
function (isOwner, next) {
|
|
||||||
groups.kick(data.uid, data.groupName, isOwner, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
});
|
|
||||||
|
|
||||||
SocketGroups.create = function (socket, data, callback) {
|
|
||||||
if (!socket.uid) {
|
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
|
||||||
} else if (groups.isPrivilegeGroup(data.name)) {
|
|
||||||
return callback(new Error('[[error:invalid-group-name]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
privileges.global.can('group:create', socket.uid, next);
|
|
||||||
},
|
|
||||||
function (canCreate, next) {
|
|
||||||
if (!canCreate) {
|
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
|
||||||
data.ownerUid = socket.uid;
|
|
||||||
groups.create(data, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.delete = isOwner(function (socket, data, callback) {
|
SocketGroups.rescindInvite = async (socket, data) => {
|
||||||
if (data.groupName === 'administrators' ||
|
await isOwner(socket, data);
|
||||||
data.groupName === 'registered-users' ||
|
await groups.rejectMembership(data.groupName, data.toUid);
|
||||||
data.groupName === 'guests' ||
|
};
|
||||||
data.groupName === 'Global Moderators') {
|
|
||||||
return callback(new Error('[[error:not-allowed]]'));
|
SocketGroups.acceptInvite = async (socket, data) => {
|
||||||
|
await isInvited(socket, data);
|
||||||
|
await groups.acceptMembership(data.groupName, socket.uid);
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketGroups.rejectInvite = async (socket, data) => {
|
||||||
|
await isInvited(socket, data);
|
||||||
|
await groups.rejectMembership(data.groupName, socket.uid);
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketGroups.update = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
|
await groups.update(data.groupName, data.values);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SocketGroups.kick = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
|
if (socket.uid === parseInt(data.uid, 10)) {
|
||||||
|
throw new Error('[[error:cant-kick-self]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.destroy(data.groupName, callback);
|
const isOwnerBit = await groups.ownership.isOwner(data.uid, data.groupName);
|
||||||
});
|
await groups.kick(data.uid, data.groupName, isOwnerBit);
|
||||||
|
};
|
||||||
|
|
||||||
SocketGroups.search = function (socket, data, callback) {
|
SocketGroups.create = async (socket, data) => {
|
||||||
|
if (!socket.uid) {
|
||||||
|
throw new Error('[[error:no-privileges]]');
|
||||||
|
} else if (groups.isPrivilegeGroup(data.name)) {
|
||||||
|
throw new Error('[[error:invalid-group-name]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
const canCreate = await privileges.global.can('group:create', socket.uid);
|
||||||
|
if (!canCreate) {
|
||||||
|
throw new Error('[[error:no-privileges]]');
|
||||||
|
}
|
||||||
|
data.ownerUid = socket.uid;
|
||||||
|
await groups.create(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketGroups.delete = async (socket, data) => {
|
||||||
|
await isOwner(socket, data);
|
||||||
|
if (
|
||||||
|
data.groupName === 'administrators' || data.groupName === 'registered-users' ||
|
||||||
|
data.groupName === 'guests' || data.groupName === 'Global Moderators'
|
||||||
|
) {
|
||||||
|
throw new Error('[[error:not-allowed]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
await groups.destroy(data.groupName);
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketGroups.search = async (socket, data) => {
|
||||||
data.options = data.options || {};
|
data.options = data.options || {};
|
||||||
|
|
||||||
if (!data.query) {
|
if (!data.query) {
|
||||||
var groupsPerPage = 15;
|
var groupsPerPage = 15;
|
||||||
groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1, function (err, data) {
|
const groups = await groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1);
|
||||||
callback(err, !err ? data.groups : null);
|
return groups.groups;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
groups.search(data.query, data.options, callback);
|
await groups.search(data.query, data.options);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.loadMore = function (socket, data, callback) {
|
SocketGroups.loadMore = async (socket, data) => {
|
||||||
if (!data.sort || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
|
if (!data.sort || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupsPerPage = 9;
|
var groupsPerPage = 9;
|
||||||
var start = parseInt(data.after, 10);
|
var start = parseInt(data.after, 10);
|
||||||
var stop = start + groupsPerPage - 1;
|
var stop = start + groupsPerPage - 1;
|
||||||
groupsController.getGroupsFromSet(socket.uid, data.sort, start, stop, callback);
|
await groupsController.getGroupsFromSet(socket.uid, data.sort, start, stop);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.searchMembers = function (socket, data, callback) {
|
SocketGroups.searchMembers = async (socket, data) => {
|
||||||
data.uid = socket.uid;
|
data.uid = socket.uid;
|
||||||
groups.searchMembers(data, callback);
|
await groups.searchMembers(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.loadMoreMembers = function (socket, data, callback) {
|
SocketGroups.loadMoreMembers = async (socket, data) => {
|
||||||
if (!data.groupName || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
|
if (!data.groupName || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
data.after = parseInt(data.after, 10);
|
data.after = parseInt(data.after, 10);
|
||||||
async.waterfall([
|
const users = user.getUsersFromSet('group:' + data.groupName + ':members', socket.uid, data.after, data.after + 9);
|
||||||
function (next) {
|
return {
|
||||||
user.getUsersFromSet('group:' + data.groupName + ':members', socket.uid, data.after, data.after + 9, next);
|
|
||||||
},
|
|
||||||
function (users, next) {
|
|
||||||
next(null, {
|
|
||||||
users: users,
|
users: users,
|
||||||
nextStart: data.after + 10,
|
nextStart: data.after + 10,
|
||||||
});
|
};
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.cover = {};
|
SocketGroups.cover = {};
|
||||||
|
|
||||||
SocketGroups.cover.update = function (socket, data, callback) {
|
SocketGroups.cover.update = async (socket, data) => {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
await canModifyGroup(socket.uid, data.groupName);
|
||||||
function (next) {
|
await groups.updateCover(socket.uid, data);
|
||||||
canModifyGroup(socket.uid, data.groupName, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
groups.updateCover(socket.uid, data, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketGroups.cover.remove = function (socket, data, callback) {
|
SocketGroups.cover.remove = async (socket, data) => {
|
||||||
if (!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
await canModifyGroup(socket.uid, data.groupName);
|
||||||
function (next) {
|
await groups.removeCover(socket.uid, data);
|
||||||
canModifyGroup(socket.uid, data.groupName, next);
|
|
||||||
},
|
|
||||||
function (next) {
|
|
||||||
groups.removeCover(data, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function canModifyGroup(uid, groupName, callback) {
|
async function canModifyGroup(uid, groupName) {
|
||||||
async.waterfall([
|
const results = await utils.promiseParallel({
|
||||||
function (next) {
|
isOwner: groups.ownership.isOwner(uid, groupName),
|
||||||
async.parallel({
|
isAdminOrGlobalMod: user.isAdminOrGlobalMod(uid),
|
||||||
isOwner: async.apply(groups.ownership.isOwner, uid, groupName),
|
});
|
||||||
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, uid),
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results, next) {
|
|
||||||
if (!results.isOwner && !results.isAdminOrGlobalMod) {
|
if (!results.isOwner && !results.isAdminOrGlobalMod) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
throw new Error('[[error:no-privileges]]');
|
||||||
}
|
}
|
||||||
next();
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require('../promisify')(SocketGroups);
|
||||||
|
|||||||
Reference in New Issue
Block a user