mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
closes #4070
This commit is contained in:
@@ -37,6 +37,7 @@ define('admin/manage/category', [
|
||||
});
|
||||
}
|
||||
|
||||
handleTags();
|
||||
|
||||
$('#category-settings input, #category-settings select').not($('.privilege-table-container input'))
|
||||
.on('change', function (ev) {
|
||||
@@ -169,8 +170,6 @@ define('admin/manage/category', [
|
||||
});
|
||||
|
||||
Category.setupPrivilegeTable();
|
||||
|
||||
handleTags();
|
||||
};
|
||||
|
||||
function modified(el) {
|
||||
@@ -202,6 +201,7 @@ define('admin/manage/category', [
|
||||
ajaxify.data.category.tagWhitelist.forEach(function (tag) {
|
||||
tagEl.tagsinput('add', tag);
|
||||
});
|
||||
|
||||
tagEl.on('itemAdded itemRemoved', function () {
|
||||
modified(tagEl);
|
||||
});
|
||||
|
||||
@@ -21,6 +21,10 @@ define('admin/manage/group', [
|
||||
|
||||
var groupName = ajaxify.data.group.name;
|
||||
|
||||
$('#group-selector').on('change', function () {
|
||||
ajaxify.go('admin/manage/groups/' + $(this).val() + window.location.hash);
|
||||
});
|
||||
|
||||
memberList.init('admin/manage/group');
|
||||
|
||||
changeGroupUserTitle.keyup(function () {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
|
||||
var db = require('../../database');
|
||||
var groups = require('../../groups');
|
||||
@@ -16,12 +17,9 @@ groupsController.list = function (req, res, next) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRange('groups:createtime', 0, -1, next);
|
||||
getGroupNames(next);
|
||||
},
|
||||
function (groupNames, next) {
|
||||
groupNames = groupNames.filter(function (name) {
|
||||
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
|
||||
});
|
||||
pageCount = Math.ceil(groupNames.length / groupsPerPage);
|
||||
|
||||
var start = (page - 1) * groupsPerPage;
|
||||
@@ -44,20 +42,48 @@ groupsController.get = function (req, res, callback) {
|
||||
var groupName = req.params.name;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
groups.exists(groupName, next);
|
||||
async.parallel({
|
||||
groupNames: function (next) {
|
||||
getGroupNames(next);
|
||||
},
|
||||
group: function (next) {
|
||||
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (exists, next) {
|
||||
if (!exists) {
|
||||
function (result) {
|
||||
if (!result.group) {
|
||||
return callback();
|
||||
}
|
||||
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next);
|
||||
},
|
||||
function (group) {
|
||||
group.isOwner = true;
|
||||
result.group.isOwner = true;
|
||||
|
||||
result.groupNames = result.groupNames.map(function (name) {
|
||||
return {
|
||||
encodedName: encodeURIComponent(name),
|
||||
displayName: validator.escape(String(name)),
|
||||
selected: name === groupName,
|
||||
};
|
||||
});
|
||||
|
||||
res.render('admin/manage/group', {
|
||||
group: group,
|
||||
group: result.group,
|
||||
groupNames: result.groupNames,
|
||||
allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
function getGroupNames(callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRange('groups:createtime', 0, -1, next);
|
||||
},
|
||||
function (groupNames, next) {
|
||||
groupNames = groupNames.filter(function (name) {
|
||||
return name !== 'registered-users' && !groups.isPrivilegeGroup(name);
|
||||
});
|
||||
next(null, groupNames);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -98,21 +98,18 @@ groupsController.details = function (req, res, callback) {
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
], function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
function (results) {
|
||||
if (!results.group) {
|
||||
return callback();
|
||||
}
|
||||
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
|
||||
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
||||
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
|
||||
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
|
||||
|
||||
if (!results.group) {
|
||||
return callback();
|
||||
}
|
||||
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
|
||||
results.title = '[[pages:group, ' + results.group.displayName + ']]';
|
||||
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
|
||||
results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
|
||||
|
||||
res.render('groups/details', results);
|
||||
});
|
||||
res.render('groups/details', results);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
groupsController.members = function (req, res, callback) {
|
||||
@@ -139,24 +136,21 @@ groupsController.members = function (req, res, callback) {
|
||||
|
||||
user.getUsersFromSet('group:' + groupName + ':members', req.uid, 0, 49, next);
|
||||
},
|
||||
], function (err, users) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
function (users) {
|
||||
var breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{ text: '[[pages:groups]]', url: '/groups' },
|
||||
{ text: validator.escape(String(groupName)), url: '/groups/' + req.params.slug },
|
||||
{ text: '[[groups:details.members]]' },
|
||||
]);
|
||||
|
||||
var breadcrumbs = helpers.buildBreadcrumbs([
|
||||
{ text: '[[pages:groups]]', url: '/groups' },
|
||||
{ text: validator.escape(String(groupName)), url: '/groups/' + req.params.slug },
|
||||
{ text: '[[groups:details.members]]' },
|
||||
]);
|
||||
|
||||
res.render('groups/members', {
|
||||
users: users,
|
||||
nextStart: 50,
|
||||
loadmore_display: users.length > 50 ? 'block' : 'hide',
|
||||
breadcrumbs: breadcrumbs,
|
||||
});
|
||||
});
|
||||
res.render('groups/members', {
|
||||
users: users,
|
||||
nextStart: 50,
|
||||
loadmore_display: users.length > 50 ? 'block' : 'hide',
|
||||
breadcrumbs: breadcrumbs,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
groupsController.uploadCover = function (req, res, next) {
|
||||
|
||||
@@ -135,7 +135,7 @@ Groups.get = function (groupName, options, callback) {
|
||||
function (_results, next) {
|
||||
results = _results;
|
||||
if (!results.base) {
|
||||
return callback(new Error('[[error:no-group]]'));
|
||||
return callback(null, null);
|
||||
}
|
||||
plugins.fireHook('filter:parse.raw', results.base.description, next);
|
||||
},
|
||||
|
||||
@@ -93,6 +93,13 @@
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select id="group-selector" class="form-control">
|
||||
<!-- BEGIN groupNames -->
|
||||
<option value="{groupNames.encodedName}" <!-- IF groupNames.selected -->selected<!-- ENDIF groupNames.selected -->>{groupNames.displayName}</option>
|
||||
<!-- END groupNames -->
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -97,6 +97,14 @@ describe('Groups', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return null if group does not exist', function (done) {
|
||||
Groups.get('doesnotexist', {}, function (err, groupObj) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(groupObj, null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('.search()', function () {
|
||||
@@ -375,8 +383,9 @@ describe('Groups', function () {
|
||||
Groups.destroy('foobar?', function (err) {
|
||||
assert.ifError(err);
|
||||
|
||||
Groups.get('foobar?', {}, function (err) {
|
||||
assert(err, 'Group still exists!');
|
||||
Groups.get('foobar?', {}, function (err, groupObj) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(groupObj, null);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user