diff --git a/controllers/flag.js b/controllers/flag.js index 7da9e6f4c..44a35ce73 100644 --- a/controllers/flag.js +++ b/controllers/flag.js @@ -84,7 +84,6 @@ exports.flag = function (aReq, aRes, aNext) { isLib = true; // fallthrough case 'scripts': - aReq.params.username = aReq.params[2]; aReq.params.scriptname = aReq.params[3] diff --git a/controllers/remove.js b/controllers/remove.js index 027800918..7f6ba6d69 100644 --- a/controllers/remove.js +++ b/controllers/remove.js @@ -15,6 +15,7 @@ var Script = require('../models/script').Script; var User = require('../models/user').User; //--- Controller inclusions +var scriptStorage = require('./scriptStorage'); //--- Library inclusions var removeLib = require('../libs/remove'); @@ -44,7 +45,10 @@ exports.rm = function (aReq, aRes, aNext) { var reason = aFields.reason; var type = aReq.params[0]; - var path = aReq.params[1]; + var isLib = null; + + var installNameBase = null; + var username = null; var authedUser = aReq.session.user; @@ -70,21 +74,32 @@ exports.rm = function (aReq, aRes, aNext) { } switch (type) { - case 'scripts': case 'libs': - path += type === 'libs' ? '.js' : '.user.js'; - Script.findOne({ installName: path }, function (aErr, aScript) { - removeLib.remove(Script, aScript, authedUser, reason, function (aRemoved) { - if (!aRemoved) { - aNext(); - return; - } - aRes.redirect('/'); + isLib = true; + // fallthrough + case 'scripts': + aReq.params.username = username = aReq.params[2]; + aReq.params.scriptname = aReq.params[3] + + installNameBase = scriptStorage.getInstallNameBase(aReq); + + Script.findOne({ + installName: scriptStorage.caseSensitive(installNameBase + + (isLib ? '.js' : '.user.js')) + }, function (aErr, aScript) { + removeLib.remove(Script, aScript, authedUser, reason, function (aRemoved) { + if (!aRemoved) { + aNext(); + return; + } + aRes.redirect('/users/' + encodeURIComponent(username) + '/scripts'); + }); }); - }); break; case 'users': - User.findOne({ name: { $regex: new RegExp('^' + path + '$', "i") } }, + username = aReq.params[1]; + + User.findOne({ name: { $regex: new RegExp('^' + username + '$', "i") } }, function (aErr, aUser) { removeLib.remove(User, aUser, authedUser, reason, function (aRemoved) { if (!aRemoved) { @@ -94,7 +109,7 @@ exports.rm = function (aReq, aRes, aNext) { // Destroy all the sessions belonging to the removed user destroySessions(aReq, aUser, function () { - aRes.redirect('/'); + aRes.redirect('/users'); }); }); }); diff --git a/routes.js b/routes.js index 0cff5e6c9..7b609c08e 100644 --- a/routes.js +++ b/routes.js @@ -110,7 +110,7 @@ module.exports = function (aApp) { aApp.route(/^\/flag\/(users|scripts|libs)\/((.+?)(?:\/(.+))?)$/).post(flag.flag); // Remove route - aApp.route(/^\/remove\/(.+?)\/(.+)$/).post(remove.rm); + aApp.route(/^\/remove\/(users|scripts|libs)\/((.+?)(?:\/(.+))?)$/).post(remove.rm); // Group routes aApp.route('/groups').get(group.list);