0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Merge pull request #2670 from jaswilli/issue-2628

Redirect from admin editor to frontend post view
This commit is contained in:
Hannah Wolfe 2014-05-02 14:59:24 +01:00
commit 94ed8a5cea
3 changed files with 103 additions and 3 deletions

View file

@ -69,10 +69,23 @@ adminControllers = {
}); });
}, },
// Route: editor // Route: editor
// Path: /ghost/editor(/:id)?/ // Path: /ghost/editor(/:id)?(/:action)?/
// Method: GET // Method: GET
'editor': function (req, res) { 'editor': function (req, res) {
if (req.params.id !== undefined) { if (req.params.id && req.params.action) {
if (req.params.action !== 'view') {
return errors.error404(req, res);
}
api.posts.read({ id: req.params.id }).then(function (result) {
return config.urlForPost(api.settings, result.posts[0]).then(function (url) {
return res.redirect(url);
});
}, function () {
return errors.error404(req, res);
});
} else if (req.params.id !== undefined) {
res.render('editor', { res.render('editor', {
bodyClass: 'editor', bodyClass: 'editor',
adminNav: setSelected(adminNavbar, 'content') adminNav: setSelected(adminNavbar, 'content')

View file

@ -40,7 +40,8 @@ module.exports = function (server) {
server.post('/ghost/reset/:token', admin.doReset); server.post('/ghost/reset/:token', admin.doReset);
server.post('/ghost/changepw/', admin.doChangePassword); server.post('/ghost/changepw/', admin.doChangePassword);
server.get('/ghost/editor(/:id)/', admin.editor); server.get('/ghost/editor/:id/:action', admin.editor);
server.get('/ghost/editor/:id/', admin.editor);
server.get('/ghost/editor/', admin.editor); server.get('/ghost/editor/', admin.editor);
server.get('/ghost/content/', admin.content); server.get('/ghost/content/', admin.content);
server.get('/ghost/settings*', admin.settings); server.get('/ghost/settings*', admin.settings);

View file

@ -13,6 +13,7 @@ var request = require('supertest'),
testUtils = require('../../utils'), testUtils = require('../../utils'),
ghost = require('../../../../core'), ghost = require('../../../../core'),
httpServer, httpServer,
agent = request.agent,
ONE_HOUR_S = 60 * 60, ONE_HOUR_S = 60 * 60,
ONE_YEAR_S = 365 * 24 * ONE_HOUR_S, ONE_YEAR_S = 365 * 24 * ONE_HOUR_S,
@ -283,3 +284,88 @@ describe('Admin Routing', function () {
}); });
}); });
}); });
describe('Authenticated Admin Routing', function () {
var user = testUtils.DataGenerator.forModel.users[0],
csrfToken = '';
before(function (done) {
var app = express();
ghost({app: app}).then(function (_httpServer) {
httpServer = _httpServer;
request = agent(app);
testUtils.clearData()
.then(function () {
return testUtils.initData();
})
.then(function () {
return testUtils.insertDefaultFixtures();
})
.then(function () {
request.get('/ghost/signin/')
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
var pattern_meta = /<meta.*?name="csrf-param".*?content="(.*?)".*?>/i;
pattern_meta.should.exist;
csrfToken = res.text.match(pattern_meta)[1];
process.nextTick(function() {
request.post('/ghost/signin/')
.set('X-CSRF-Token', csrfToken)
.send({email: user.email, password: user.password})
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
request.saveCookies(res);
request.get('/ghost/')
.expect(200)
.end(function (err, res) {
if (err) {
return done(err);
}
csrfToken = res.text.match(pattern_meta)[1];
done();
});
});
});
});
}, done);
}).otherwise(function (e) {
console.log('Ghost Error: ', e);
console.log(e.stack);
});
});
after(function () {
httpServer.close();
});
describe('Ghost Admin magic /view/ route', function () {
it('should redirect to the single post page on the frontend', function (done) {
request.get('/ghost/editor/1/view/')
.expect(302)
.expect('Location', '/welcome-to-ghost/')
.end(function (err, res) {
if (err) {
return done(err);
}
done();
});
});
});
});