Compare commits

..

4 Commits

Author SHA1 Message Date
Barış Soner Uşaklı
a6a02fb773 feat: merge 2021-04-15 12:52:58 -04:00
Barış Soner Uşaklı
49583fe48b feat: allow slugs 2021-04-12 17:28:04 -04:00
Barış Soner Uşaklı
14e211fb68 fix: #9473 (#9476) 2021-04-08 14:16:59 -04:00
Tudor-Dan Ravoiu
7b98fab95c Translate categories (#9472)
* use appParseAndTranslate to translate category names

* translate parent categories on new category creation

Co-authored-by: Tudor-Dan Ravoiu <tudor-dan.ravoiu@ubisoft.com>
2021-04-08 09:10:01 -04:00
6 changed files with 21 additions and 12 deletions

View File

@@ -109,9 +109,9 @@ define('admin/manage/categories', [
name: '[[admin/manage/categories:parent-category-none]]',
icon: 'fa-none',
});
Benchpress.render('admin/partials/categories/create', {
app.parseAndTranslate('admin/partials/categories/create', {
categories: categories,
}).then(function (html) {
}, function (html) {
var modal = bootbox.dialog({
title: '[[admin/manage/categories:alert.create]]',
message: html,

View File

@@ -119,9 +119,9 @@ define('admin/manage/category', [
return app.alertError(err.message);
}
Benchpress.render('admin/partials/categories/copy-settings', {
app.parseAndTranslate('admin/partials/categories/copy-settings', {
categories: allCategories,
}).then(function (html) {
}, function (html) {
var selectedCid;
var modal = bootbox.dialog({
title: '[[modules:composer.select_category]]',

View File

@@ -49,8 +49,8 @@ categoryController.get = async function (req, res, next) {
return helpers.notAllowed(req, res);
}
if (!res.locals.isAPI && (!req.params.slug || categoryFields.slug !== cid + '/' + req.params.slug) && (categoryFields.slug && categoryFields.slug !== cid + '/')) {
return helpers.redirect(res, '/category/' + categoryFields.slug, true);
if (!res.locals.isAPI && !req.params.slug && (categoryFields.slug && categoryFields.slug !== `${cid}/`)) {
return helpers.redirect(res, `/category/${categoryFields.slug}`, true);
}
if (categoryFields.link) {

View File

@@ -118,7 +118,7 @@ function calculateStartStop(page, postIndex, settings) {
let startSkip = 0;
if (!settings.usePagination) {
if (postIndex !== 0) {
if (postIndex > 1) {
page = 1;
}
startSkip = Math.max(0, postIndex - Math.ceil(settings.postsPerPage / 2));

View File

@@ -185,9 +185,8 @@ module.exports = function (middleware) {
if (!userslug) {
return next();
}
const path = req.path.replace(/^\/api/, '')
.replace('uid', 'user')
.replace(uid, function () { return userslug; });
const path = req.url.replace(/^\/api/, '')
.replace(`/uid/${uid}`, () => `/user/${userslug}`);
controllers.helpers.redirect(res, path);
});

View File

@@ -1050,8 +1050,18 @@ describe('Controllers', function () {
});
});
it('should 404 if user does not exist', function (done) {
request(nconf.get('url') + '/api/uid/123123', { json: true }, function (err, res) {
it('should redirect to userslug and keep query params', (done) => {
request(`${nconf.get('url')}/api/uid/${fooUid}/topics?foo=bar`, { json: true }, (err, res, body) => {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(res.headers['x-redirect'], '/user/foo/topics?foo=bar');
assert.equal(body, '/user/foo/topics?foo=bar');
done();
});
});
it('should 404 if user does not exist', (done) => {
request(`${nconf.get('url')}/api/uid/123123`, { json: true }, (err, res) => {
assert.ifError(err);
assert.equal(res.statusCode, 404);
done();