fixed #2732 -- group creation now using language keys, and no longer succeeds if a group by the name of 'guest' is created.

v1.18.x
Julian Lam 10 years ago
parent dca143fd87
commit 502e806f88

@ -1,5 +1,5 @@
"use strict";
/*global define, templates, socket, ajaxify, app, admin, bootbox*/
/*global define, templates, socket, ajaxify, app, admin, bootbox, utils, config, translator */
define('admin/manage/groups', [
'iconSelect',
@ -50,19 +50,13 @@ define('admin/manage/groups', [
socket.emit('admin.groups.create', submitObj, function(err) {
if (err) {
switch (err) {
case 'group-exists':
errorText = '<strong>Please choose another name</strong><p>There seems to be a group with this name already.</p>';
break;
case 'name-too-short':
errorText = '<strong>Please specify a group name</strong><p>A group name is required for administrative purposes.</p>';
break;
default:
errorText = '<strong>Uh-Oh</strong><p>There was a problem creating your group. Please try again later!</p>';
break;
if (err.hasOwnProperty('message') && utils.hasLanguageKey(err.message)) {
translator.translate(err.message, config.defaultLang, function(translated) {
createModalError.html(translated).removeClass('hide');
});
} else {
createModalError.html('<strong>Uh-Oh</strong><p>There was a problem creating your group. Please try again later!</p>').removeClass('hide');
}
createModalError.html(errorText).removeClass('hide');
} else {
createModalError.addClass('hide');
createGroupName.val('');

@ -71,6 +71,7 @@
trimTrailingDash: /-$/g,
trimLeadingDash: /^-/g,
isLatin: /^[\w]+$/,
languageKeyRegex: /\[\[[\w]+:.+\]\]/,
//http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/
slugify: function(str) {
@ -108,6 +109,10 @@
return !isNaN(parseFloat(n)) && isFinite(n);
},
hasLanguageKey: function(input) {
return utils.languageKeyRegex.test(input);
},
// shallow objects merge
merge: function() {
var result = {}, obj, keys;

@ -43,20 +43,14 @@ var async = require('async'),
return groups;
}
},
getEphemeralGroup: function(groupName, options, callback) {
Groups.exists(groupName, function(err, exists) {
if (!err && exists) {
Groups.get.apply(null, arguments);
} else {
callback(null, {
name: groupName,
description: '',
deleted: '0',
hidden: '0',
system: '1'
});
}
});
getEphemeralGroup: function(groupName) {
return {
name: groupName,
description: '',
deleted: '0',
hidden: '0',
system: '1'
};
},
removeEphemeralGroups: function(groups) {
var x = groups.length;
@ -95,6 +89,9 @@ var async = require('async'),
};
Groups.get = function(groupName, options, callback) {
if (!arguments[0]) {
console.log(new Error.stack);
}
var truncated = false,
numUsers;
@ -103,7 +100,7 @@ var async = require('async'),
if (ephemeralGroups.indexOf(groupName) === -1) {
db.getObject('group:' + groupName, next);
} else {
internals.getEphemeralGroup(groupName, options, next);
next(null, internals.getEphemeralGroup(groupName));
}
},
users: function (next) {
@ -400,6 +397,11 @@ var async = require('async'),
return utils.slugify(groupName);
});
async.parallel([
function(next) {
callback(null, slugs.map(function(slug) {
return ephemeralGroups.indexOf(slug) !== -1;
}));
},
async.apply(db.isObjectFields, 'groupslug:groupname', slugs),
async.apply(db.isSortedSetMembers, 'groups:createtime', name)
], function(err, results) {
@ -407,17 +409,20 @@ var async = require('async'),
return callback(err);
}
callback(null, results.map(function(pair) {
return pair[0] || pair[1];
callback(null, results.map(function(result) {
return result[0] || result[1] || result[2];
}));
});
} else {
var slug = utils.slugify(name);
async.parallel([
function(next) {
next(null, ephemeralGroups.indexOf(slug) !== -1);
},
async.apply(db.isObjectField, 'groupslug:groupname', slug),
async.apply(db.isSortedSetMember, 'groups:createtime', name)
], function(err, results) {
callback(err, !err ? (results[0] || results[1]) : null);
callback(err, !err ? (results[0] || results[1] || results[2]) : null);
});
}
};

Loading…
Cancel
Save