Merge remote-tracking branch 'origin/master' into category-whitelisting

Conflicts:
	src/groups.js
v1.18.x
Julian Lam 11 years ago
commit 72ef8c839f

@ -76,6 +76,9 @@
<div class="btn-group pull-right post-tools"> <div class="btn-group pull-right post-tools">
<button class="btn btn-sm btn-default link" type="button" title="[[topic:link]]"><i class="fa fa-link"></i></button> <button class="btn btn-sm btn-default link" type="button" title="[[topic:link]]"><i class="fa fa-link"></i></button>
<button class="btn btn-sm btn-default main-post facebook-share" type="button" title=""><i class="fa fa-facebook"></i></button>
<button class="btn btn-sm btn-default main-post twitter-share" type="button" title=""><i class="fa fa-twitter"></i></button>
<button class="btn btn-sm btn-default main-post google-share" type="button" title=""><i class="fa fa-google-plus"></i></button>
<button class="btn btn-sm btn-default edit {posts.display_moderator_tools}" type="button" title="[[topic:edit]]"><i class="fa fa-pencil"></i></button> <button class="btn btn-sm btn-default edit {posts.display_moderator_tools}" type="button" title="[[topic:edit]]"><i class="fa fa-pencil"></i></button>
<button class="btn btn-sm btn-default delete {posts.display_moderator_tools}" type="button" title="[[topic:delete]]"><i class="fa fa-trash-o"></i></button> <button class="btn btn-sm btn-default delete {posts.display_moderator_tools}" type="button" title="[[topic:delete]]"><i class="fa fa-trash-o"></i></button>
</div> </div>

@ -1,130 +1,138 @@
(function () { (function(Groups) {
"use strict"; "use strict";
var async = require('async'), var async = require('async'),
User = require('./user'), User = require('./user'),
RDB = RDB || require('./redis'), RDB = RDB || require('./redis');
Groups = {
list: function (options, callback) { Groups.list = function(options, callback) {
RDB.hvals('group:gid', function (err, gids) { RDB.hvals('group:gid', function (err, gids) {
if (gids.length > 0) { if (gids.length > 0) {
async.map(gids, function (gid, next) { async.map(gids, function (gid, next) {
Groups.get(gid, { Groups.get(gid, {
expand: options.expand expand: options.expand
}, next); }, next);
}, function (err, groups) { }, function (err, groups) {
callback(err, groups.filter(function (group) { callback(err, groups.filter(function (group) {
if (group.deleted === '1') { if (group.deleted === '1') {
return false; return false;
} else { } else {
return true; return true;
} }
})); }));
});
} else {
callback(null, []);
}
}); });
} else {
callback(null, []);
}
});
};
Groups.get = function(gid, options, callback) {
async.parallel({
base: function (next) {
RDB.hgetall('gid:' + gid, next);
}, },
get: function (gid, options, callback) { users: function (next) {
async.parallel({ RDB.smembers('gid:' + gid + ':members', function (err, uids) {
base: function (next) { if (options.expand) {
RDB.hgetall('gid:' + gid, next); if (err) {
}, return next(err);
users: function (next) { }
RDB.smembers('gid:' + gid + ':members', function (err, uids) {
if (options.expand) { async.map(uids, function (uid, next) {
if (err) { User.getUserData(uid, next);
return next(err); }, function (err, users) {
} next(err, users);
async.map(uids, function (uid, next) {
User.getUserData(uid, next);
}, function (err, users) {
next(err, users);
});
} else {
next(err, uids);
}
}); });
} else {
next(err, uids);
} }
}, function (err, results) { });
if (err) { }
return callback(err); }, function (err, results) {
} if (err) {
return callback(err);
}
results.base.count = results.users.length; results.base.count = results.users.length;
results.base.members = results.users; results.base.members = results.users;
results.base.deletable = (results.base.gid !== '1'); results.base.deletable = (results.base.gid !== '1');
callback(err, results.base); callback(err, results.base);
}); });
}, };
getGidFromName: function (name, callback) {
RDB.hget('group:gid', name, callback); Groups.getGidFromName = function(name, callback) {
}, RDB.hget('group:gid', name, callback);
isMember: function (uid, gid, callback) { };
RDB.sismember('gid:' + gid + ':members', uid, callback);
}, Groups.isMember = function(uid, gid, callback) {
isMemberByGroupName: function(uid, groupName, callback) { RDB.sismember('gid:' + gid + ':members', uid, callback);
this.getGidFromName(groupName, function(err, gid) { };
if (err || !gid) {
callback(null, false); Groups.isMemberByGroupName = function(uid, groupName, callback)
} else { this.getGidFromName(groupName, function(err, gid
Groups.isMember(uid, gid, callback); if (err || !gid) {
} callback(null, false);
}); } else {
}, Groups.isMember(uid, gid, callba
exists: function (name, callback) { }
RDB.hexists('group:gid', name, callback); });
}, };
create: function (name, description, callback) {
if (name.length === 0) { Groups.exists = function(name, callback) {
return callback(new Error('name-too-short')); RDB.hexists('group:gid', name, callback);
} };
Groups.exists(name, function (err, exists) { Groups.create = function(name, description, callback) {
if (!exists) { if (name.length === 0) {
RDB.incr('next_gid', function (err, gid) { return callback(new Error('name-too-short'));
RDB.multi() }
.hset('group:gid', name, gid)
.hmset('gid:' + gid, { Groups.exists(name, function (err, exists) {
gid: gid, if (!exists) {
name: name, RDB.incr('next_gid', function (err, gid) {
description: description, RDB.multi()
deleted: '0' .hset('group:gid', name, gid)
}) .hmset('gid:' + gid, {
.exec(function (err) { gid: gid,
Groups.get(gid, {}, callback); name: name,
}); description: description,
deleted: '0'
})
.exec(function (err) {
Groups.get(gid, {}, callback);
}); });
} else {
callback(new Error('group-exists'));
}
}); });
}, } else {
update: function (gid, values, callback) { callback(new Error('group-exists'));
RDB.exists('gid:' + gid, function (err, exists) {
if (!err && exists) {
RDB.hmset('gid:' + gid, values, callback);
} else {
callback(new Error('gid-not-found'));
}
});
},
destroy: function (gid, callback) {
if (gid !== 1) {
RDB.hset('gid:' + gid, 'deleted', '1', callback);
}
},
join: function (gid, uid, callback) {
RDB.sadd('gid:' + gid + ':members', uid, callback);
},
leave: function (gid, uid, callback) {
RDB.srem('gid:' + gid + ':members', uid, callback);
} }
}; });
};
Groups.update = function(gid, values, callback) {
RDB.exists('gid:' + gid, function (err, exists) {
if (!err && exists) {
RDB.hmset('gid:' + gid, values, callback);
} else {
callback(new Error('gid-not-found'));
}
});
};
Groups.destroy = function(gid, callback) {
if (gid !== 1) {
RDB.hset('gid:' + gid, 'deleted', '1', callback);
}
};
Groups.join = function(gid, uid, callback) {
RDB.sadd('gid:' + gid + ':members', uid, callback);
};
Groups.leave = function(gid, uid, callback) {
RDB.srem('gid:' + gid + ':members', uid, callback);
};
module.exports = Groups; }(module.exports));
}());

Loading…
Cancel
Save