v1.18.x
Baris Usakli 8 years ago
parent 5fc6fe1c80
commit de55c8e431

@ -37,6 +37,7 @@ define('admin/manage/category', [
}); });
} }
handleTags();
$('#category-settings input, #category-settings select').not($('.privilege-table-container input')) $('#category-settings input, #category-settings select').not($('.privilege-table-container input'))
.on('change', function (ev) { .on('change', function (ev) {
@ -169,8 +170,6 @@ define('admin/manage/category', [
}); });
Category.setupPrivilegeTable(); Category.setupPrivilegeTable();
handleTags();
}; };
function modified(el) { function modified(el) {
@ -202,6 +201,7 @@ define('admin/manage/category', [
ajaxify.data.category.tagWhitelist.forEach(function (tag) { ajaxify.data.category.tagWhitelist.forEach(function (tag) {
tagEl.tagsinput('add', tag); tagEl.tagsinput('add', tag);
}); });
tagEl.on('itemAdded itemRemoved', function () { tagEl.on('itemAdded itemRemoved', function () {
modified(tagEl); modified(tagEl);
}); });

@ -21,6 +21,10 @@ define('admin/manage/group', [
var groupName = ajaxify.data.group.name; 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'); memberList.init('admin/manage/group');
changeGroupUserTitle.keyup(function () { changeGroupUserTitle.keyup(function () {

@ -1,6 +1,7 @@
'use strict'; 'use strict';
var async = require('async'); var async = require('async');
var validator = require('validator');
var db = require('../../database'); var db = require('../../database');
var groups = require('../../groups'); var groups = require('../../groups');
@ -16,12 +17,9 @@ groupsController.list = function (req, res, next) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRange('groups:createtime', 0, -1, next); getGroupNames(next);
}, },
function (groupNames, next) { function (groupNames, next) {
groupNames = groupNames.filter(function (name) {
return name.indexOf(':privileges:') === -1 && name !== 'registered-users';
});
pageCount = Math.ceil(groupNames.length / groupsPerPage); pageCount = Math.ceil(groupNames.length / groupsPerPage);
var start = (page - 1) * groupsPerPage; var start = (page - 1) * groupsPerPage;
@ -44,20 +42,48 @@ groupsController.get = function (req, res, callback) {
var groupName = req.params.name; var groupName = req.params.name;
async.waterfall([ async.waterfall([
function (next) { 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) { function (result) {
if (!exists) { if (!result.group) {
return callback(); return callback();
} }
groups.get(groupName, { uid: req.uid, truncateUserList: true, userListCount: 20 }, next); result.group.isOwner = true;
},
function (group) { result.groupNames = result.groupNames.map(function (name) {
group.isOwner = true; return {
encodedName: encodeURIComponent(name),
displayName: validator.escape(String(name)),
selected: name === groupName,
};
});
res.render('admin/manage/group', { res.render('admin/manage/group', {
group: group, group: result.group,
groupNames: result.groupNames,
allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1, allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
}); });
}, },
], callback); ], 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); }, next);
}, },
], function (err, results) { function (results) {
if (err) { if (!results.group) {
return callback(err); return callback();
} }
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
if (!results.group) { results.title = '[[pages:group, ' + results.group.displayName + ']]';
return callback(); results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
} results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
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) { 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); user.getUsersFromSet('group:' + groupName + ':members', req.uid, 0, 49, next);
}, },
], function (err, users) { function (users) {
if (err) { var breadcrumbs = helpers.buildBreadcrumbs([
return callback(err); { 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 }, res.render('groups/members', {
{ text: '[[groups:details.members]]' }, users: users,
]); nextStart: 50,
loadmore_display: users.length > 50 ? 'block' : 'hide',
res.render('groups/members', { breadcrumbs: breadcrumbs,
users: users, });
nextStart: 50, },
loadmore_display: users.length > 50 ? 'block' : 'hide', ], callback);
breadcrumbs: breadcrumbs,
});
});
}; };
groupsController.uploadCover = function (req, res, next) { groupsController.uploadCover = function (req, res, next) {

@ -135,7 +135,7 @@ Groups.get = function (groupName, options, callback) {
function (_results, next) { function (_results, next) {
results = _results; results = _results;
if (!results.base) { if (!results.base) {
return callback(new Error('[[error:no-group]]')); return callback(null, null);
} }
plugins.fireHook('filter:parse.raw', results.base.description, next); plugins.fireHook('filter:parse.raw', results.base.description, next);
}, },

@ -93,6 +93,13 @@
</fieldset> </fieldset>
</div> </div>
</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> </form>
</div> </div>

@ -97,6 +97,14 @@ describe('Groups', function () {
done(); 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 () { describe('.search()', function () {
@ -375,8 +383,9 @@ describe('Groups', function () {
Groups.destroy('foobar?', function (err) { Groups.destroy('foobar?', function (err) {
assert.ifError(err); assert.ifError(err);
Groups.get('foobar?', {}, function (err) { Groups.get('foobar?', {}, function (err, groupObj) {
assert(err, 'Group still exists!'); assert.ifError(err);
assert.strictEqual(groupObj, null);
done(); done();
}); });

Loading…
Cancel
Save