Merge branch 'master' into develop

This commit is contained in:
Julian Lam
2017-02-24 12:46:40 -05:00
449 changed files with 9202 additions and 6984 deletions

View File

@@ -1,10 +1,7 @@
'use strict';
var async = require('async');
var nconf = require('nconf');
var path = require('path');
var fs = require('fs');
var crypto = require('crypto');
var Jimp = require('jimp');
var mime = require('mime');
var winston = require('winston');
@@ -14,7 +11,6 @@ var image = require('../image');
var uploadsController = require('../controllers/uploads');
module.exports = function (Groups) {
Groups.updateCoverPosition = function (groupName, position, callback) {
if (!groupName) {
return callback(new Error('[[error:invalid-data]]'));
@@ -23,7 +19,6 @@ module.exports = function (Groups) {
};
Groups.updateCover = function (uid, data, callback) {
// Position only? That's fine
if (!data.imageData && !data.file && data.position) {
return Groups.updateCoverPosition(data.groupName, data.position, callback);
@@ -45,7 +40,7 @@ module.exports = function (Groups) {
uploadsController.uploadGroupCover(uid, {
name: 'groupCover',
path: tempPath,
type: type
type: type,
}, next);
},
function (uploadData, next) {
@@ -59,7 +54,7 @@ module.exports = function (Groups) {
uploadsController.uploadGroupCover(uid, {
name: 'groupCoverThumb',
path: tempPath,
type: type
type: type,
}, next);
},
function (uploadData, next) {
@@ -71,13 +66,13 @@ module.exports = function (Groups) {
} else {
next(null);
}
}
},
], function (err) {
fs.unlink(tempPath, function (unlinkErr) {
if (unlinkErr) {
winston.error(unlinkErr);
}
callback(err, {url: url});
callback(err, { url: url });
});
});
};
@@ -92,7 +87,7 @@ module.exports = function (Groups) {
},
function (image, next) {
image.write(path, next);
}
},
], function (err) {
callback(err);
});
@@ -101,5 +96,4 @@ module.exports = function (Groups) {
Groups.removeCover = function (data, callback) {
db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url', 'cover:position'], callback);
};
};
};

View File

@@ -7,7 +7,6 @@ var utils = require('../../public/src/utils');
var db = require('../database');
module.exports = function (Groups) {
Groups.create = function (data, callback) {
var system = isSystemGroup(data);
var groupData;
@@ -42,14 +41,14 @@ module.exports = function (Groups) {
hidden: parseInt(data.hidden, 10) === 1 ? 1 : 0,
system: system ? 1 : 0,
private: isPrivate,
disableJoinRequests: disableJoinRequests
disableJoinRequests: disableJoinRequests,
};
plugins.fireHook('filter:group.create', {group: groupData, data: data}, next);
plugins.fireHook('filter:group.create', { group: groupData, data: data }, next);
},
function (results, next) {
var tasks = [
async.apply(db.sortedSetAdd, 'groups:createtime', groupData.createtime, groupData.name),
async.apply(db.setObject, 'group:' + groupData.name, groupData)
async.apply(db.setObject, 'group:' + groupData.name, groupData),
];
if (data.hasOwnProperty('ownerUid')) {
@@ -72,9 +71,8 @@ module.exports = function (Groups) {
function (results, next) {
plugins.fireHook('action:group.create', {group: groupData});
next(null, groupData);
}
},
], callback);
};
function isSystemGroup(data) {

View File

@@ -6,7 +6,6 @@ var utils = require('../../public/src/utils');
var db = require('./../database');
module.exports = function (Groups) {
Groups.destroy = function (groupName, callback) {
Groups.getGroupsData([groupName], function (err, groupsData) {
if (err) {
@@ -37,7 +36,7 @@ module.exports = function (Groups) {
db.sortedSetRemove('group:' + group + ':members', groupName, next);
}, next);
});
}
},
], function (err) {
if (err) {
return callback(err);

View File

@@ -1,6 +1,6 @@
'use strict';
var async = require('async');
var async = require('async');
var winston = require('winston');
var _ = require('underscore');
@@ -15,11 +15,10 @@ var LRU = require('lru-cache');
var cache = LRU({
max: 40000,
maxAge: 1000 * 60 * 60
maxAge: 1000 * 60 * 60,
});
module.exports = function (Groups) {
Groups.cache = cache;
Groups.join = function (groupName, uid, callback) {
@@ -46,7 +45,7 @@ module.exports = function (Groups) {
Groups.create({
name: groupName,
description: '',
hidden: 1
hidden: 1,
}, function (err) {
if (err && err.message !== '[[error:group-already-exists]]') {
winston.error('[groups.join] Could not create new hidden group: ' + err.message);
@@ -62,13 +61,13 @@ module.exports = function (Groups) {
},
isHidden: function (next) {
Groups.isHidden(groupName, next);
}
},
}, next);
},
function (results, next) {
var tasks = [
async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid),
async.apply(db.incrObjectField, 'group:' + groupName, 'memberCount')
async.apply(db.incrObjectField, 'group:' + groupName, 'memberCount'),
];
if (results.isAdmin) {
tasks.push(async.apply(db.setAdd, 'group:' + groupName + ':owners', uid));
@@ -85,10 +84,10 @@ module.exports = function (Groups) {
function (next) {
plugins.fireHook('action:group.join', {
groupName: groupName,
uid: uid
uid: uid,
});
next();
}
},
], callback);
};
@@ -120,12 +119,12 @@ module.exports = function (Groups) {
bodyLong: '[[groups:request.notification_text, ' + username + ', ' + groupName + ']]',
nid: 'group:' + groupName + ':uid:' + uid + ':request',
path: '/groups/' + utils.slugify(groupName),
from: uid
from: uid,
}, next);
},
owners: function (next) {
Groups.getOwners(groupName, next);
}
},
}, next);
},
function (results, next) {
@@ -133,24 +132,22 @@ module.exports = function (Groups) {
return next();
}
notifications.push(results.notification, results.owners, next);
}
},
], callback);
};
Groups.acceptMembership = function (groupName, uid, callback) {
// Note: For simplicity, this method intentially doesn't check the caller uid for ownership!
async.waterfall([
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
async.apply(db.setRemove, 'group:' + groupName + ':invited', uid),
async.apply(Groups.join, groupName, 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!
async.parallel([
async.apply(db.setRemove, 'group:' + groupName + ':pending', uid),
async.apply(db.setRemove, 'group:' + groupName + ':invited', uid)
async.apply(db.setRemove, 'group:' + groupName + ':invited', uid),
], callback);
};
@@ -161,11 +158,11 @@ module.exports = function (Groups) {
bodyShort: '[[groups:invited.notification_title, ' + groupName + ']]',
bodyLong: '',
nid: 'group:' + groupName + ':uid:' + uid + ':invite',
path: '/groups/' + utils.slugify(groupName)
path: '/groups/' + utils.slugify(groupName),
}),
function (notification, next) {
notifications.push(notification, [uid], next);
}
},
], callback);
};
@@ -182,7 +179,7 @@ module.exports = function (Groups) {
exists: async.apply(Groups.exists, groupName),
isMember: async.apply(Groups.isMember, uid, groupName),
isPending: async.apply(Groups.isPending, uid, groupName),
isInvited: async.apply(Groups.isInvited, uid, groupName)
isInvited: async.apply(Groups.isInvited, uid, groupName),
}, next);
},
function (checks, next) {
@@ -201,10 +198,10 @@ module.exports = function (Groups) {
function (next) {
plugins.fireHook(hookName, {
groupName: groupName,
uid: uid
uid: uid,
});
next();
}
},
], callback);
}
@@ -229,7 +226,7 @@ module.exports = function (Groups) {
async.parallel([
async.apply(db.sortedSetRemove, 'group:' + groupName + ':members', uid),
async.apply(db.setRemove, 'group:' + groupName + ':owners', uid),
async.apply(db.decrObjectField, 'group:' + groupName, 'memberCount')
async.apply(db.decrObjectField, 'group:' + groupName, 'memberCount'),
], next);
},
function (results, next) {
@@ -242,21 +239,19 @@ module.exports = function (Groups) {
}
if (Groups.isPrivilegeGroup(groupName) && parseInt(groupData.memberCount, 10) === 0) {
Groups.destroy(groupName, next);
} else if (parseInt(groupData.hidden, 10) !== 1) {
db.sortedSetAdd('groups:visible:memberCount', groupData.memberCount, groupName, next);
} else {
if (parseInt(groupData.hidden, 10) !== 1) {
db.sortedSetAdd('groups:visible:memberCount', groupData.memberCount, groupName, next);
} else {
next();
}
next();
}
},
function (next) {
plugins.fireHook('action:group.leave', {
groupName: groupName,
uid: uid
uid: uid,
});
next();
}
},
], callback);
};
@@ -279,10 +274,10 @@ module.exports = function (Groups) {
},
function (next) {
Groups.rejectMembership(groupName, uid, next);
}
},
], next);
}, next);
}
},
], callback);
};
@@ -318,7 +313,7 @@ module.exports = function (Groups) {
});
function clearCache(uid, groupName) {
pubsub.publish('group:cache:del', {uid: uid, groupName: groupName});
pubsub.publish('group:cache:del', { uid: uid, groupName: groupName });
cache.del(uid + ':' + groupName);
}
@@ -343,7 +338,7 @@ module.exports = function (Groups) {
function (isMember, next) {
cache.set(cacheKey, isMember);
next(null, isMember);
}
},
], callback);
};
@@ -355,7 +350,7 @@ module.exports = function (Groups) {
}
if (!groupName || !uids.length) {
return callback(null, uids.map(function () {return false;}));
return callback(null, uids.map(function () { return false; }));
}
var nonCachedUids = uids.filter(function (uid) {
@@ -376,7 +371,7 @@ module.exports = function (Groups) {
});
getFromCache(next);
}
},
], callback);
};
@@ -388,7 +383,7 @@ module.exports = function (Groups) {
}
if (!uid || parseInt(uid, 10) <= 0 || !groups.length) {
return callback(null, groups.map(function () {return false;}));
return callback(null, groups.map(function () { return false; }));
}
var nonCachedGroups = groups.filter(function (groupName) {
@@ -413,7 +408,7 @@ module.exports = function (Groups) {
});
getFromCache(next);
}
},
], callback);
};
@@ -471,7 +466,7 @@ module.exports = function (Groups) {
});
var result = members.map(function (groupNames) {
for (var i = 0; i < groupNames.length; ++i) {
for (var i = 0; i < groupNames.length; i += 1) {
if (map[groupNames[i]]) {
return true;
}
@@ -551,7 +546,7 @@ module.exports = function (Groups) {
return next(new Error('[[error:group-needs-owner]]'));
}
Groups.leave(groupName, uid, next);
}
},
], callback);
} else {
Groups.leave(groupName, uid, callback);

View File

@@ -1,11 +1,10 @@
'use strict';
var async = require('async'),
db = require('../database'),
plugins = require('../plugins');
var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
module.exports = function (Groups) {
Groups.ownership = {};
Groups.ownership.isOwner = function (uid, groupName, callback) {
@@ -30,9 +29,9 @@ module.exports = function (Groups) {
db.setAdd('group:' + groupName + ':owners', toUid, next);
},
function (next) {
plugins.fireHook('action:group.grantOwnership', {uid: toUid, groupName: groupName});
plugins.fireHook('action:group.grantOwnership', { uid: toUid, groupName: groupName });
next();
}
},
], callback);
};
@@ -51,9 +50,9 @@ module.exports = function (Groups) {
db.setRemove('group:' + groupName + ':owners', toUid, next);
},
function (next) {
plugins.fireHook('action:group.rescindOwnership', {uid: toUid, groupName: groupName});
plugins.fireHook('action:group.rescindOwnership', { uid: toUid, groupName: groupName });
next();
}
},
], callback);
};
};

View File

@@ -7,7 +7,6 @@ var db = require('./../database');
module.exports = function (Groups) {
Groups.search = function (query, options, callback) {
if (!query) {
return callback(null, []);
@@ -33,38 +32,37 @@ module.exports = function (Groups) {
}
Groups.sort(options.sort, groupsData, next);
}
},
], callback);
};
Groups.sort = function (strategy, groups, next) {
switch(strategy) {
case 'count':
groups = groups.sort(function (a, b) {
return a.slug > b.slug;
}).sort(function (a, b) {
return b.memberCount - a.memberCount;
});
break;
switch (strategy) {
case 'count':
groups = groups.sort(function (a, b) {
return a.slug > b.slug;
}).sort(function (a, b) {
return b.memberCount - a.memberCount;
});
break;
case 'date':
groups = groups.sort(function (a, b) {
return b.createtime - a.createtime;
});
break;
case 'date':
groups = groups.sort(function (a, b) {
return b.createtime - a.createtime;
});
break;
case 'alpha': // intentional fall-through
default:
groups = groups.sort(function (a, b) {
return a.slug > b.slug ? 1 : -1;
});
case 'alpha': // intentional fall-through
default:
groups = groups.sort(function (a, b) {
return a.slug > b.slug ? 1 : -1;
});
}
next(null, groups);
};
Groups.searchMembers = function (data, callback) {
function findUids(query, searchBy, callback) {
query = query.toLowerCase();
@@ -77,14 +75,14 @@ module.exports = function (Groups) {
},
function (users, next) {
var uids = [];
for(var i = 0; i < users.length; ++i) {
for (var i = 0; i < users.length; i += 1) {
var field = users[i][searchBy];
if (field.toLowerCase().startsWith(query)) {
uids.push(users[i].uid);
}
}
next(null, uids);
}
},
], callback);
}
@@ -93,7 +91,7 @@ module.exports = function (Groups) {
if (err) {
return callback(err);
}
callback(null, {users: users});
callback(null, { users: users });
});
return;
}
@@ -112,24 +110,22 @@ module.exports = function (Groups) {
Groups.ownership.isOwners(uids, data.groupName, next);
},
function (isOwners, next) {
results.users.forEach(function (user, index) {
if (user) {
user.isOwner = isOwners[index];
}
});
results.users.sort(function (a,b) {
results.users.sort(function (a, b) {
if (a.isOwner && !b.isOwner) {
return -1;
} else if (!a.isOwner && b.isOwner) {
return 1;
} else {
return 0;
}
return 0;
});
next(null, results);
}
},
], callback);
};
};

View File

@@ -9,7 +9,6 @@ var db = require('../database');
module.exports = function (Groups) {
Groups.update = function (groupName, values, callback) {
callback = callback || function () {};
@@ -23,7 +22,7 @@ module.exports = function (Groups) {
}
plugins.fireHook('filter:group.update', {
groupName: groupName,
values: values
values: values,
}, next);
},
function (result, next) {
@@ -32,7 +31,7 @@ module.exports = function (Groups) {
var payload = {
description: values.description || '',
icon: values.icon || '',
labelColor: values.labelColor || '#000000'
labelColor: values.labelColor || '#000000',
};
if (values.hasOwnProperty('userTitle')) {
@@ -71,16 +70,16 @@ module.exports = function (Groups) {
}
},
async.apply(db.setObject, 'group:' + groupName, payload),
async.apply(renameGroup, groupName, values.name)
async.apply(renameGroup, groupName, values.name),
], next);
},
function (result, next) {
plugins.fireHook('action:group.update', {
name: groupName,
values: values
values: values,
});
next();
}
},
], callback);
};
@@ -118,7 +117,7 @@ module.exports = function (Groups) {
callback = callback || function () {};
async.parallel([
async.apply(db.setObjectField, 'group:' + groupName, 'hidden', hidden ? 1 : 0),
async.apply(updateVisibility, groupName, hidden)
async.apply(updateVisibility, groupName, hidden),
], function (err) {
callback(err);
});
@@ -131,7 +130,7 @@ module.exports = function (Groups) {
},
function (currentValue, next) {
var currentlyPrivate = parseInt(currentValue.private, 10) === 1;
if (!currentlyPrivate || currentlyPrivate === isPrivate) {
if (!currentlyPrivate || currentlyPrivate === isPrivate) {
return callback();
}
db.getSetMembers('group:' + groupName + ':pending', next);
@@ -146,9 +145,9 @@ module.exports = function (Groups) {
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')
async.apply(db.delete, 'group:' + groupName + ':pending'),
], next);
}
},
], function (err) {
callback(err);
});
@@ -218,11 +217,11 @@ module.exports = function (Groups) {
function (next) {
plugins.fireHook('action:group.rename', {
old: oldName,
new: newName
new: newName,
});
next();
}
},
], callback);
});
});
@@ -244,7 +243,7 @@ module.exports = function (Groups) {
},
function (next) {
db.sortedSetAdd(group, score, newName, next);
}
},
], callback);
});
}