Skip to content

Commit

Permalink
Merge pull request OpenUserJS#825 from Martii/Issue-819
Browse files Browse the repository at this point in the history
More encoding and controller symmetry

Auto-merge
  • Loading branch information
Martii committed Nov 17, 2015
2 parents 542227b + 1f82419 commit 4d23b72
Show file tree
Hide file tree
Showing 6 changed files with 598 additions and 554 deletions.
27 changes: 16 additions & 11 deletions controllers/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ exports.flag = function (aReq, aRes, aNext) {

var type = aReq.params[0];
var isLib = null;

var installName = null;
var path = aReq.params[1];
var username = null;

var authedUser = aReq.session.user;

Expand Down Expand Up @@ -83,15 +84,16 @@ exports.flag = function (aReq, aRes, aNext) {
isLib = true;
// fallthrough
case 'scripts':
installName = scriptStorage.getInstallName({
params: {
username: aReq.params[2],
scriptname: aReq.params[3]
}});

path += type === 'libs' ? '.js' : '.user.js';
aReq.params.username = aReq.params[2];
aReq.params.scriptname = aReq.params[3]

installName = scriptStorage.getScriptBaseName(aReq);

Script.findOne({ installName: path },
Script.findOne({
installName: scriptStorage.caseSensitive(installName +
(isLib ? '.js' : '.user.js'))
},
function (aErr, aScript) {
var fn = flagLib[flag ? 'flag' : 'unflag'];

Expand All @@ -101,13 +103,16 @@ exports.flag = function (aReq, aRes, aNext) {
}

fn(Script, aScript, authedUser, reason, function (aFlagged) {
aRes.redirect((isLib ? '/libs/' : '/scripts/') + encodeURI(installName));
aRes.redirect((isLib ? '/libs/' : '/scripts/') + scriptStorage.getScriptBaseName(
aReq, { encoding: 'uri' }));
});

});
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) {
var fn = flagLib[flag ? 'flag' : 'unflag'];

Expand All @@ -117,7 +122,7 @@ exports.flag = function (aReq, aRes, aNext) {
}

fn(User, aUser, authedUser, reason, function (aFlagged) {
aRes.redirect('/users/' + encodeURI(path));
aRes.redirect('/users/' + encodeURIComponent(username));
});

});
Expand Down
Loading

0 comments on commit 4d23b72

Please sign in to comment.