Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
Revert "Prevent new instances from being created"
Browse files Browse the repository at this point in the history
This reverts commit 28b7cff.
  • Loading branch information
chrismytton committed Aug 27, 2015
1 parent 20cb352 commit 0182bfb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
34 changes: 28 additions & 6 deletions hosting-app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,38 @@ exports.route = function (app) {
res.render('index.html');
});

app.get('/instance_creation_disabled', function(req, res, next) {
res.render('instance_creation_disabled.html');
});

app.get('/instances/new', requireUser, function(req, res, next) {
return res.redirect('/instance_creation_disabled');
res.locals.errors = {};
res.locals.slug = '';
res.render('instance_new.html');
});

app.post('/instances/new', requireUser, function(req, res, next) {
return res.redirect('/instance_creation_disabled');
var slug = res.locals.slug = req.param('slug', '').trim();
var Instance = req.popit.model('Instance');
var Permission = req.popit.permissions();
var instance = new Instance();
instance.slug = slug;
instance.email = req.user.email;
instance.status = 'active';
instance.save(function(err, newInstance) {
if (err) {
res.locals.errors = err.errors;
res.locals.existing_instance_url = instance.base_url;
return res.render('instance_new.html');
}
// Make the user owner of the instance
Permission.create({
account: req.user._id,
instance: newInstance._id,
role: 'owner',
}, function(err) {
if (err) {
return next(err);
}
res.redirect('/instances/' + slug);
});
});
});

app.get('/instances/:slug', function(req, res) {
Expand Down
21 changes: 0 additions & 21 deletions hosting-app/views/instance_creation_disabled.html

This file was deleted.

4 changes: 4 additions & 0 deletions test/ui/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe("homepage", function() {
browser.assert.success();
});

it("contains link to create new instance", function() {
browser.assert.link('a', 'Start your own PopIt', '/instances/new');
});

it("contains link to all instances", function() {
browser.assert.link('a', 'Browse existing PopIts', '/instances');
});
Expand Down

0 comments on commit 0182bfb

Please sign in to comment.