Skip to content

Commit

Permalink
Knock out a TODO in the script controller
Browse files Browse the repository at this point in the history
* Merge lib edit get and post routes into one... applies to OpenUserJS#135
* Standardize modelParser to return a url with the username intact just like Edit Script has in Author Tools

Applies to OpenUserJS#135 and post "unrepair" of OpenUserJS#813 and parent OpenUserJS#812
  • Loading branch information
Martii committed Nov 7, 2015
1 parent f4db626 commit 34a9e34
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
6 changes: 1 addition & 5 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,6 @@ exports.view = function (aReq, aRes, aNext) {
// route to edit a script
exports.edit = function (aReq, aRes, aNext) {
//
var authedUser = aReq.session.user;

// Support routes lacking the :username. TODO: Remove this functionality.
aReq.params.username = authedUser.name.toLowerCase();

var installNameSlug = scriptStorage.getInstallName(aReq);
var isLib = aReq.params.isLib;

Expand All @@ -434,6 +429,7 @@ exports.edit = function (aReq, aRes, aNext) {

//
var options = {};
var authedUser = aReq.session.user;
var script = null;
var scriptGroups = null;
var tasks = [];
Expand Down
7 changes: 1 addition & 6 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ var getScriptViewSourcePageUrl = function (aScript) {
};

var getScriptEditAboutPageUrl = function (aScript) {
var isLib = aScript.isLib || false;
var scriptPath = aScript.installName
.replace(isLib ? /\.js$/ : /\.user\.js$/, '');
var editUrl = scriptPath.split('/');
editUrl.shift();
return (isLib ? '/lib/' : '/script/') + editUrl.join('/') + '/edit';
return getScriptPageUrl(aScript) + '/edit';
};

var getScriptEditSourcePageUrl = function (aScript) {
Expand Down
6 changes: 2 additions & 4 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ module.exports = function (aApp) {

// Script routes
aApp.route('/scripts/:username/:namespace?/:scriptname').get(script.view);
aApp.route('/script/:username/:namespace?/:scriptname/edit').get(authentication.validateUser, script.edit).post(authentication.validateUser, script.edit);
aApp.route('/script/:namespace?/:scriptname/edit').get(authentication.validateUser, script.edit).post(authentication.validateUser, script.edit);
aApp.route('/scripts/:username/:namespace?/:scriptname/edit').get(authentication.validateUser, script.edit).post(authentication.validateUser, script.edit);
aApp.route('/scripts/:username/:namespace?/:scriptname/source').get(user.editScript);
aApp.route('/scripts/:username').get(function (aReq, aRes) {
aRes.redirect('/users/' + aReq.params.username + '/scripts');
Expand All @@ -74,8 +73,7 @@ module.exports = function (aApp) {

// Library routes
aApp.route('/libs/:username/:scriptname').get(script.lib(script.view));
aApp.route('/lib/:scriptname/edit').get(authentication.validateUser, script.lib(script.edit));
aApp.route('/lib/:scriptname/edit').post(authentication.validateUser, script.lib(script.edit));
aApp.route('/libs/:username/:scriptname/edit').get(authentication.validateUser, script.lib(script.edit)).post(authentication.validateUser, script.lib(script.edit));
aApp.route('/libs/:username/:scriptname/source').get(script.lib(user.editScript));
aApp.route('/libs/src/:username/:scriptname').get(scriptStorage.sendScript);

Expand Down

0 comments on commit 34a9e34

Please sign in to comment.