diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 53b7064f59..b960f1446c 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -115,19 +115,33 @@ groupsController.details = function (req, res, callback) { }); }; -groupsController.members = function (req, res, next) { +groupsController.members = function (req, res, callback) { var groupName; async.waterfall([ function (next) { groups.getGroupNameByGroupSlug(req.params.slug, next); }, function (_groupName, next) { + if (!_groupName) { + return callback(); + } groupName = _groupName; + async.parallel({ + isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid), + isMember: async.apply(groups.isMember, req.uid, groupName), + isHidden: async.apply(groups.isHidden, groupName) + }, next); + }, + function (results, next) { + if (results.isHidden && !results.isMember && !results.isAdminOrGlobalMod) { + return callback(); + } + user.getUsersFromSet('group:' + groupName + ':members', req.uid, 0, 49, next); }, ], function (err, users) { - if (err || !groupName) { - return next(err); + if (err) { + return callback(err); } var breadcrumbs = helpers.buildBreadcrumbs([ diff --git a/src/groups.js b/src/groups.js index 7d71a6e0fa..fbca035cba 100644 --- a/src/groups.js +++ b/src/groups.js @@ -296,7 +296,7 @@ var utils = require('../public/src/utils'); }; Groups.isHidden = function (groupName, callback) { - db.getObjectField(groupName, 'hidden', function (err, isHidden) { + db.getObjectField('group:' + groupName, 'hidden', function (err, isHidden) { if (err) { return callback(err); } diff --git a/test/controllers.js b/test/controllers.js index 3fe84c446e..91983e940a 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -16,6 +16,7 @@ describe('Controllers', function () { var tid; var cid; + var fooUid; before(function (done) { async.series({ @@ -33,6 +34,7 @@ describe('Controllers', function () { return done(err); } cid = results.category.cid; + fooUid = results.user; topics.post({uid: results.user, title: 'test topic title', content: 'test topic content', cid: results.category.cid}, function (err, result) { tid = result.topicData.tid; @@ -382,6 +384,84 @@ describe('Controllers', function () { }); }); + it('should load users page', function (done) { + request(nconf.get('url') + '/users', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should load users page', function (done) { + request(nconf.get('url') + '/users?section=online', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should load users search page', function (done) { + request(nconf.get('url') + '/users?term=bar§ion=sort-posts', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should load groups page', function (done) { + request(nconf.get('url') + '/groups', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should load group details page', function (done) { + var groups = require('../src/groups'); + groups.create({ + name: 'group-details', + description: 'Foobar!', + hidden: 0 + }, function (err) { + assert.ifError(err); + request(nconf.get('url') + '/groups/group-details', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + }); + + it('should load group members page', function (done) { + request(nconf.get('url') + '/groups/group-details/members', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); + + it('should 404 when trying to load group members of hidden group', function (done) { + var groups = require('../src/groups'); + groups.create({ + name: 'hidden-group', + description: 'Foobar!', + hidden: 1 + }, function (err) { + assert.ifError(err); + request(nconf.get('url') + '/groups/hidden-group/members', function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 404); + done(); + }); + }); + }); + after(function (done) { db.emptydb(done); });