|
|
@ -12,48 +12,57 @@ module.exports = function (Groups) {
|
|
|
|
|
|
|
|
|
|
|
|
Groups.update = function (groupName, values, callback) {
|
|
|
|
Groups.update = function (groupName, values, callback) {
|
|
|
|
callback = callback || function () {};
|
|
|
|
callback = callback || function () {};
|
|
|
|
db.exists('group:' + groupName, function (err, exists) {
|
|
|
|
|
|
|
|
if (err || !exists) {
|
|
|
|
|
|
|
|
return callback(err || new Error('[[error:no-group]]'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:group.update', {
|
|
|
|
async.waterfall([
|
|
|
|
groupName: groupName,
|
|
|
|
function (next) {
|
|
|
|
values: values
|
|
|
|
db.exists('group:' + groupName, next);
|
|
|
|
}, function (err) {
|
|
|
|
},
|
|
|
|
if (err) {
|
|
|
|
function (exists, next) {
|
|
|
|
return callback(err);
|
|
|
|
if (!exists) {
|
|
|
|
|
|
|
|
return next(new Error('[[error:no-group]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins.fireHook('filter:group.update', {
|
|
|
|
|
|
|
|
groupName: groupName,
|
|
|
|
|
|
|
|
values: values
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (result, next) {
|
|
|
|
|
|
|
|
values = result.values;
|
|
|
|
|
|
|
|
|
|
|
|
var payload = {
|
|
|
|
var payload = {
|
|
|
|
description: values.description || '',
|
|
|
|
description: values.description || '',
|
|
|
|
icon: values.icon || '',
|
|
|
|
icon: values.icon || '',
|
|
|
|
labelColor: values.labelColor || '#000000'
|
|
|
|
labelColor: values.labelColor || '#000000'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('userTitle')) {
|
|
|
|
if (values.hasOwnProperty('userTitle')) {
|
|
|
|
payload.userTitle = values.userTitle || '';
|
|
|
|
payload.userTitle = values.userTitle || '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('userTitleEnabled')) {
|
|
|
|
if (values.hasOwnProperty('userTitleEnabled')) {
|
|
|
|
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
|
|
|
|
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('hidden')) {
|
|
|
|
if (values.hasOwnProperty('hidden')) {
|
|
|
|
payload.hidden = values.hidden ? '1' : '0';
|
|
|
|
payload.hidden = values.hidden ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('private')) {
|
|
|
|
if (values.hasOwnProperty('private')) {
|
|
|
|
payload.private = values.private ? '1' : '0';
|
|
|
|
payload.private = values.private ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('disableJoinRequests')) {
|
|
|
|
if (values.hasOwnProperty('disableJoinRequests')) {
|
|
|
|
payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
|
|
|
|
payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
async.series([
|
|
|
|
async.apply(checkNameChange, groupName, values.name),
|
|
|
|
async.apply(checkNameChange, groupName, values.name),
|
|
|
|
async.apply(updatePrivacy, groupName, values.private),
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
if (values.hasOwnProperty('private')) {
|
|
|
|
|
|
|
|
updatePrivacy(groupName, values.private, next);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
if (values.hasOwnProperty('hidden')) {
|
|
|
|
if (values.hasOwnProperty('hidden')) {
|
|
|
|
updateVisibility(groupName, values.hidden, next);
|
|
|
|
updateVisibility(groupName, values.hidden, next);
|
|
|
@ -63,19 +72,16 @@ module.exports = function (Groups) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async.apply(db.setObject, 'group:' + groupName, payload),
|
|
|
|
async.apply(db.setObject, 'group:' + groupName, payload),
|
|
|
|
async.apply(renameGroup, groupName, values.name)
|
|
|
|
async.apply(renameGroup, groupName, values.name)
|
|
|
|
], function (err) {
|
|
|
|
], next);
|
|
|
|
if (err) {
|
|
|
|
},
|
|
|
|
return callback(err);
|
|
|
|
function (result, next) {
|
|
|
|
}
|
|
|
|
plugins.fireHook('action:group.update', {
|
|
|
|
|
|
|
|
name: groupName,
|
|
|
|
plugins.fireHook('action:group.update', {
|
|
|
|
values: values
|
|
|
|
name: groupName,
|
|
|
|
|
|
|
|
values: values
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function updateVisibility(groupName, hidden, callback) {
|
|
|
|
function updateVisibility(groupName, hidden, callback) {
|
|
|
@ -118,35 +124,33 @@ module.exports = function (Groups) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updatePrivacy(groupName, newValue, callback) {
|
|
|
|
function updatePrivacy(groupName, isPrivate, callback) {
|
|
|
|
if (!newValue) {
|
|
|
|
async.waterfall([
|
|
|
|
return callback();
|
|
|
|
function (next) {
|
|
|
|
}
|
|
|
|
Groups.getGroupFields(groupName, ['private'], next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (currentValue, next) {
|
|
|
|
|
|
|
|
var currentlyPrivate = parseInt(currentValue.private, 10) === 1;
|
|
|
|
|
|
|
|
if (!currentlyPrivate || currentlyPrivate === isPrivate) {
|
|
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
db.getSetMembers('group:' + groupName + ':pending', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (uids, next) {
|
|
|
|
|
|
|
|
if (!uids.length) {
|
|
|
|
|
|
|
|
return callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var now = Date.now();
|
|
|
|
|
|
|
|
var scores = uids.map(function () { return now; });
|
|
|
|
|
|
|
|
|
|
|
|
Groups.getGroupFields(groupName, ['private'], function (err, currentValue) {
|
|
|
|
winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');
|
|
|
|
if (err) {
|
|
|
|
async.series([
|
|
|
|
return callback(err);
|
|
|
|
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', scores, uids),
|
|
|
|
}
|
|
|
|
async.apply(db.delete, 'group:' + groupName + ':pending')
|
|
|
|
currentValue = currentValue.private === '1';
|
|
|
|
], next);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentValue !== newValue && currentValue === true) {
|
|
|
|
|
|
|
|
// Group is now public, so all pending users are automatically considered members
|
|
|
|
|
|
|
|
db.getSetMembers('group:' + groupName + ':pending', function (err, uids) {
|
|
|
|
|
|
|
|
if (err) { return callback(err); }
|
|
|
|
|
|
|
|
else if (!uids) { return callback(); } // No pending users, we're good to go
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var now = Date.now(),
|
|
|
|
|
|
|
|
scores = uids.map(function () { return now; }); // There's probably a better way to initialise an Array of size x with the same value...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
winston.verbose('[groups.update] Group is now public, automatically adding ' + uids.length + ' new members, who were pending prior.');
|
|
|
|
|
|
|
|
async.series([
|
|
|
|
|
|
|
|
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', scores, uids),
|
|
|
|
|
|
|
|
async.apply(db.delete, 'group:' + groupName + ':pending')
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
], function (err) {
|
|
|
|
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|