Skip to content

Commit

Permalink
Make Dev node engine Dep Match Current Pro
Browse files Browse the repository at this point in the history
* Bump requested node to current pro node stable
* Rename route to be less cryptic and tiered based for npm functions with alteration of affected controller with handler
* Update view to reflect new urls
* Squash some deprecation warnings in here since we changed to *express* 4 at OpenUserJS#417
  • Loading branch information
Martii committed Nov 23, 2014
1 parent 6fdd7c4 commit 254cd79
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
37 changes: 31 additions & 6 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ exports.adminJsonView = function (aReq, aRes, aNext) {
options.isAdmin = authedUser && authedUser.isAdmin;

if (!options.isAdmin)
return aRes.send(403, { status: 403, message: 'Not an admin.' });
return aRes.status(403).send({ status: 403, message: 'Not an admin.' });

var model = jsonModelMap[modelname];
if (!model)
return aRes.send(400, { status: 400, message: 'Invalid model.' });
return aRes.status(400).send({ status: 400, message: 'Invalid model.' });

model.findOne({
_id: id
}, function (aErr, aObj) {
if (aErr || !aObj)
return aRes.send(404, { status: 404, message: 'Id doesn\'t exist.' });
return aRes.status(404).send({ status: 404, message: 'Id doesn\'t exist.' });

aRes.json(aObj);
});
Expand Down Expand Up @@ -298,7 +298,7 @@ exports.adminApiKeysPage = function (aReq, aRes, aNext) {

// View everything about current modules for the server
// This is mostly for debugging in production
exports.adminNpmLsView = function (aReq, aRes, aNext) {
exports.adminNpmListView = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

//
Expand All @@ -310,14 +310,39 @@ exports.adminNpmLsView = function (aReq, aRes, aNext) {
options.isAdmin = authedUser && authedUser.isAdmin;

if (!options.isAdmin)
return aRes.send(403, { status: 403, message: 'Not an admin.' });
return aRes.status(403).send({ status: 403, message: 'Not an admin.' });

exec('npm ls --json', function (aErr, aStdout, aStderr) {
if (aErr) return aRes.send(501, { status: 501, message: 'Not implemented.' });
if (aErr) return aRes.status(501).send({ status: 501, message: 'Not implemented.' });
aRes.json(JSON.parse(aStdout));
});
};

// View current version of npm
// This is mostly for debugging in production
exports.adminNpmVersionView = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;

//
var options = {};

// Session
authedUser = options.authedUser = modelParser.parseUser(authedUser);
options.isMod = authedUser && authedUser.isMod;
options.isAdmin = authedUser && authedUser.isAdmin;

if (!options.isAdmin)
return aRes.status(403).send({ status: 403, message: 'Not an admin.' });

exec('npm --version', function (aErr, aStdout, aStderr) {
if (aErr) return aRes.status(501).send({ status: 501, message: 'Not implemented.' });

aRes.set('Content-Type', 'text/plain; charset=UTF-8');
aRes.write(aStdout + '\n');
aRes.end();
});
};

// Manage oAuth strategies without having to restart the server
// When new keys are added, we load the new strategy
// When keys are removed, we remove the strategy
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@
"start": "node app.js"
},
"engines": {
"node": ">=0.10.7"
"node": ">=0.10.33"
}
}
3 changes: 2 additions & 1 deletion routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ module.exports = function (aApp) {
aApp.route('/admin/json').get(admin.adminJsonView);
aApp.route('/admin/user/:id').get(admin.adminUserView);
aApp.route('/admin/api').get(admin.adminApiKeysPage);
aApp.route('/admin/npmls').get(admin.adminNpmLsView);
aApp.route('/admin/npm/list').get(admin.adminNpmListView);
aApp.route('/admin/npm/version').get(admin.adminNpmVersionView);
aApp.route('/admin/api/update').post(admin.apiAdminUpdate);

// Moderation routes
Expand Down
7 changes: 5 additions & 2 deletions views/pages/adminPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
<a href="/admin/api" class="list-group-item">
<i class="octicon octicon-fw octicon-key"></i> API Keys
</a>
<a href="/admin/npmls" class="list-group-item">
<i class="fa fa-fw fa-database"></i> Raw <code>npm ls --json</code> Data
<a href="/admin/npm/list" class="list-group-item">
<i class="fa fa-fw fa-database"></i> Raw <code>npm ls --json</code> JSON Data
</a>
<a href="/admin/npm/version" class="list-group-item">
<i class="fa fa-fw fa-database"></i> Raw <code>npm --version</code> Shell Session Data
</a>
</div>
</div>
Expand Down

0 comments on commit 254cd79

Please sign in to comment.