adding concept of group slugs, #2588. ping @barisusakli for downstream plugin changes

v1.18.x
Julian Lam 10 years ago
parent 6f140384e0
commit c026a64e8e

@ -1,5 +1,5 @@
"use strict";
/* globals app, define, ajaxify, socket, bootbox */
/* globals app, define, ajaxify, socket, bootbox, utils */
define('forum/groups/list', function() {
var Groups = {};
@ -10,7 +10,7 @@ define('forum/groups/list', function() {
groupsEl.on('click', '.list-cover', function() {
var groupName = $(this).parents('[data-group]').attr('data-group');
ajaxify.go('groups/' + encodeURIComponent(groupName));
ajaxify.go('groups/' + utils.slugify(groupName));
});
// Group creation
@ -21,7 +21,7 @@ define('forum/groups/list', function() {
name: name
}, function(err) {
if (!err) {
ajaxify.go('groups/' + encodeURIComponent(name));
ajaxify.go('groups/' + utils.slugify(name));
} else {
app.alertError(err.message);
}

@ -26,7 +26,7 @@ groupsController.details = function(req, res, next) {
async.parallel({
group: function(next) {
groups.get(req.params.name, {
groups.getByGroupslug(req.params.slug, {
expand: true,
uid: uid
}, next);

@ -193,8 +193,10 @@ var async = require('async'),
});
}
}, function (err, results) {
if (err || !results.base) {
if (err) {
return callback(err);
} else if (!results.base) {
return callback(new Error('[[error:no-group]]'));
}
// Default image
@ -224,6 +226,18 @@ var async = require('async'),
});
};
Groups.getByGroupslug = function(slug, options, callback) {
db.getObjectField('groupslug:groupname', slug, function(err, groupName) {
if (err) {
return callback(err);
} else if (!groupName) {
return callback(new Error('[[error:no-group]]'));
}
Groups.get.call(Groups, groupName, options, callback);
});
};
Groups.getGroupFields = function(groupName, fields, callback) {
db.getObjectFields('group:' + groupName, fields, callback);
};
@ -413,8 +427,10 @@ var async = require('async'),
return callback(new Error('[[error:group-already-exists]]'));
}
var groupData = {
var slug = utils.slugify(data.name),
groupData = {
name: data.name,
slug: slug,
userTitle: data.name,
description: data.description || '',
deleted: '0',
@ -432,6 +448,10 @@ var async = require('async'),
tasks.push(async.apply(db.setAdd, 'group:' + data.name + ':members', data.ownerUid));
}
if (!data.hidden) {
tasks.push(async.apply(db.setObjectField, 'groupslug:groupname', slug, data.name));
}
async.parallel(tasks, function(err) {
if (!err) {
plugins.fireHook('action:group.create', groupData);
@ -567,6 +587,7 @@ var async = require('async'),
async.apply(db.delete, 'group:' + groupName + ':members'),
async.apply(db.delete, 'group:' + groupName + ':pending'),
async.apply(db.delete, 'group:' + groupName + ':owners'),
async.apply(db.deleteObjectField, 'groupslug:groupname', utils.slugify(groupName)),
function(next) {
db.getSetMembers('groups', function(err, groups) {
if (err) {
@ -578,7 +599,7 @@ var async = require('async'),
});
}
], callback);
})
});
};
Groups.join = function(groupName, uid, callback) {

@ -93,7 +93,7 @@ function groupRoutes(app, middleware, controllers) {
var middlewares = [middleware.checkGlobalPrivacySettings];
setupPageRoute(app, '/groups', middleware, middlewares, controllers.groups.list);
setupPageRoute(app, '/groups/:name', middleware, middlewares, controllers.groups.details);
setupPageRoute(app, '/groups/:slug', middleware, middlewares, controllers.groups.details);
}
function setupPageRoute(router, name, middleware, middlewares, controller) {

Loading…
Cancel
Save