Skip to content

Commit d2c8195

Browse files
committed
ownerIsHelloRunnable check in findBuild middlware flow
1 parent 7a73c0d commit d2c8195

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

lib/middlewares/me.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,6 @@ module.exports = createMongooseMiddleware(User, 'sessionUser', {
5252
}
5353
};
5454
},
55-
isHelloRunnable: function (modelKey) {
56-
return function (req, res, next) {
57-
var model = keypather.get(req, modelKey);
58-
var modelGithubId = model.owner.github;
59-
var userGithubId = req.sessionUser.accounts.github.id;
60-
if (modelGithubId === process.env.HELLO_RUNNABLE_GITHUB_ID) {
61-
next();
62-
}
63-
else if (userGithubId === process.env.HELLO_RUNNABLE_GITHUB_ID) {
64-
next();
65-
}
66-
else {
67-
next(Boom.forbidden('Access denied (!owner)', { githubId: modelGithubId }));
68-
}
69-
};
70-
},
7155
isRegistered: function (req, res, next) {
7256
this.permission('registered')(req, res, next);
7357
},

lib/routes/instances/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var findBuild = flow.series(
4848
checkFound('build'),
4949
flow.or(
5050
me.isOwnerOf('build'),
51+
ownerIsHelloRunnable('build'),
5152
me.isModerator),
5253
mw.req('build.started').require()
5354
.else(mw.next(Boom.badRequest('Instances cannot use builds that haven\'t been started'))));
@@ -601,7 +602,10 @@ app.post('/instances/:id/actions/copy',
601602
me.isModerator),
602603
mw.body('owner.github').require().then(
603604
mw.body('owner.github').number(),
604-
me.isOwnerOf('body')),
605+
flow.or(
606+
me.isOwnerOf('body'),
607+
ownerIsHelloRunnable('body')
608+
)),
605609
// The best way to clone an instance is to just use the post route
606610
// If we deep copy the build, we can attach its id to the body, and just use the post route
607611
findBuild,

0 commit comments

Comments
 (0)