Skip to content

Commit

Permalink
Finished code changes for migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
sizzlemctwizzle committed Jun 22, 2014
1 parent 3c4bc18 commit 5b65abd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
22 changes: 8 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,9 @@ app_route('/script/:namespace?/:scriptname/edit').get(script.edit).post(script.e
app_route('/scripts/:username/:namespace?/:scriptname/source').get(user.editScript); // Legacy TODO Remove

// Script routes: Legacy
app.get('/install/:username/:scriptname', scriptStorage.sendScript);
app.get('/install/:username/:namespace/:scriptname', scriptStorage.sendScript);
app.get('/meta/:username/:scriptname', scriptStorage.sendMeta);
app.get('/meta/:username/:namespace/:scriptname', scriptStorage.sendMeta);
app.get('/vote/scripts/:username/:scriptname/:vote', script.vote);
app.get('/vote/scripts/:username/:namespace/:scriptname/:vote', script.vote);
app.get('/install/:username/:namespace?/:scriptname', scriptStorage.sendScript);
app.get('/meta/:username/:namespace?/:scriptname', scriptStorage.sendMeta);
app.get('/vote/scripts/:username/:namespace?/:scriptname/:vote', script.vote);
app.post('/github/hook', scriptStorage.webhook);
app.post('/github/service', function (req, res, next) { next(); });

Expand All @@ -179,7 +176,7 @@ app.post('/lib/:scriptname/edit', script.lib(script.edit));
app.get('/libs/:username/:scriptname/source', script.lib(user.editScript));
app.get('/libs/src/:username/:scriptname', scriptStorage.sendScript);
app.get('/vote/libs/:username/:scriptname/:vote', script.lib(script.vote));
app.get(listRegex('\/use\/lib\/([^\/]+?)\/([^\/]+?)', 'script'), script.useLib);
//app.get(listRegex('\/use\/lib\/([^\/]+?)\/([^\/]+?)', 'script'), script.useLib);

// Issues routes
app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:open(closed)?').get(issue.list);
Expand All @@ -188,10 +185,8 @@ app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issue/new').ge
app_route('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic').get(issue.view);

// Issues routes: Legacy
app.post('/:type(scripts|libs)/:username/:scriptname/issues/:topic', issue.comment);
app.post('/:type(scripts|libs)/:username/:namespace/:scriptname/issues/:topic', issue.comment);
app.get('/:type(scripts|libs)/:username/:scriptname/issues/:topic/:action(close|reopen)', issue.changeStatus);
app.get('/:type(scripts|libs)/:username/:namespace/:scriptname/issues/:topic/:action(close|reopen)', issue.changeStatus);
app.post('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic', issue.comment);
app.get('/:type(scripts|libs)/:username/:namespace?/:scriptname/issues/:topic/:action(close|reopen)', issue.changeStatus);

// Admin routes
app.get('/admin', admin.adminPage);
Expand All @@ -205,8 +200,7 @@ app_route('/mod').get(moderation.modPage);
app_route('/mod/removed').get(moderation.removedItemListPage);
app_route('/mod/removed/:id').get(moderation.removedItemPage);
app.get('/flag/users/:username/:unflag?', user.flag);
app.get('/flag/scripts/:username/:namespace/:scriptname/:unflag?', script.flag);
app.get('/flag/scripts/:username/:scriptname/:unflag?', script.flag);
app.get('/flag/scripts/:username/:namespace?/:scriptname/:unflag?', script.flag);
app.get('/flag/libs/:username/:scriptname/:unflag?', script.lib(script.flag)); //
app.get(listRegex('\/flagged(?:\/([^\/]+?))?', 'user|script'),
moderation.flagged); //
Expand All @@ -233,7 +227,7 @@ app.get('/post/:category(announcements|corner|garage|discuss)', discussion.newTo
app.post('/post/:category(announcements|corner|garage|discuss)', discussion.createTopic);
app.post('/:category(announcements|corner|garage|discuss)/:topic', discussion.createComment);

// Search routes
// Search routes: Legacy
app.post('/search', function(req, res) {
var search = encodeURIComponent(req.body.search.replace(/^\s+|\s+$/g, ''));
res.redirect('/search/' + search + '/' + req.body.type + 'list');
Expand Down
7 changes: 4 additions & 3 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.lib = function (controller) {
};

// Display which scripts use a library hosted on the site
exports.useLib = function (req, res, next) {
/*exports.useLib = function (req, res, next) {
var installName = req.route.params.shift() + '/'
+ req.route.params.shift();
var user = req.session.user;
Expand All @@ -44,7 +44,7 @@ exports.useLib = function (req, res, next) {
res.render('group', options);
});
});
};
};*/

var getScriptPageTasks = function(options) {
var tasks = [];
Expand All @@ -57,7 +57,8 @@ var getScriptPageTasks = function(options) {
//--- Tasks

// Show the number of open issues
var scriptOpenIssueCountQuery = Discussion.find({ category: script.issuesCategorySlug, open: {$ne: false} });
var scriptOpenIssueCountQuery = Discussion.find({ category: scriptStorage
.caseInsensitive(script.issuesCategorySlug), open: {$ne: false} });
tasks.push(countTask(scriptOpenIssueCountQuery, options, 'issueCount'));


Expand Down
24 changes: 15 additions & 9 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ if (process.env.NODE_ENV === 'production') {
proxy: DEV_AWS_URL, agent: require('http').globalAgent
}});
}
require('../models/discussion').Discussion.find({ category: /\/issues$/ }, function (err, discussions) {
/*require('../models/discussion').Discussion.find({ category: /issues$/ }, function (err, discussions) {
discussions.forEach(function (discussion) {
console.log(discussion.category);
//var urlTopic = cleanFilename(discussion.topic, '').replace(/_\d+$/, '');
//var path = '/' + discussion.category + '/' + urlTopic;
console.log(discussion.path);
});
});
Script.find({}, function (err, scripts) {
});*/

/*Script.find({}, function (err, scripts) {
//var s3 = new AWS.S3();
var Discussion = require('../models/discussion').Discussion;
scripts.forEach(function (script) {
/*var newPath = script.installName.replace(/(\.user)?\.js$/, '');
var newPath = script.installName.replace(/(\.user)?\.js$/, '');
var oldPath = cleanFilename(script.author).toLowerCase() + '/'
+ (script.meta.namespace ? cleanFilename(script.meta.namespace) + '/' : '')
+ cleanFilename(script.name);
var newCat = (script.isLib ? 'libs' : 'scripts') + '/' + newPath + '/issues';
var oldCat = (script.isLib ? 'libs' : 'scripts') + '/' + oldPath + '/issues';
Discussion.find({ category: oldCat }, function (err, discussions) {
discussions.forEach(function (discussion) {
discussion.category = newCat;
discussion.save(function (){ console.log(newCat, oldCat); });
var urlTopic = cleanFilename(discussion.topic, '').replace(/_\d+$/, '');
var path = '/' + discussion.category + '/' + urlTopic;
discussion.path = path;
//discussion.category = newCat;
discussion.save(function (){ console.log(path); });
});
});*/
/*var oldPath = script.installName;
Expand All @@ -64,8 +70,8 @@ Discussion.find({ category: oldCat }, function (err, discussions) {
}
});
});*/
});
});
//});
//});


function getInstallName (req) {
Expand Down
13 changes: 9 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var countTask = require('../libs/tasks').countTask;
var settings = require('../models/settings.json');
var github = require('./../libs/githubClient');

function caseInsensitive (str) {
return new RegExp('^' + (str || '').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1")
+ '$', 'i');
}

var setupUserModerationUITask = function(options) {
var user = options.user;
var authedUser = options.authedUser;
Expand Down Expand Up @@ -204,7 +209,7 @@ exports.view = function (req, res, next) {
var username = req.route.params.username;

User.findOne({
name: username
name: caseInsensitive(username)
}, function (err, userData) {
if (err || !userData) { return next(); }

Expand Down Expand Up @@ -267,7 +272,7 @@ exports.userCommentListPage = function(req, res, next) {
var username = req.route.params.username;

User.findOne({
name: username
name: caseInsensitive(username)
}, function (err, userData) {
if (err || !userData) { return next(); }

Expand Down Expand Up @@ -353,7 +358,7 @@ exports.userScriptListPage = function(req, res, next) {
var username = req.route.params.username;

User.findOne({
name: username
name: caseInsensitive(username)
}, function (err, userData) {
if (err || !userData) { return next(); }

Expand Down Expand Up @@ -443,7 +448,7 @@ exports.userEditProfilePage = function (req, res, next) {
var username = req.route.params.username;

User.findOne({
name: username
_id: authedUser._id
}, function (err, userData) {
if (err || !userData) { return next(); }

Expand Down
6 changes: 2 additions & 4 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ var parseScript = function(scriptData) {

// Urls: Slugs
script.authorSlug = script.author.name;
script.namespaceSlug = (script.meta && script.meta.namespace) ? cleanFilename(script.meta.namespace) : '';
script.nameSlug = cleanFilename(script.name);
script.installNameSlug = script.author.slug + '/' + (script.namespaceSlug ? script.namespaceSlug + '/' : '') + script.nameSlug;
script.installNameSlug = script.author.slug + '/' + script.nameSlug;

// Urls: Public
script.scriptPageUrl = getScriptPageUrl(script);
Expand All @@ -127,8 +126,7 @@ var parseScript = function(scriptData) {

// Urls: Issues
var slug = (script.isLib ? 'libs' : 'scripts');
slug += '/' + script.author.slug.toLowerCase();
slug += script.meta.namespace ? '/' + script.namespaceSlug : '';
slug += '/' + script.author.slug;
slug += '/' + script.nameSlug;
script.issuesCategorySlug = slug + '/issues';
script.scriptIssuesPageUrl = '/' + script.issuesCategorySlug;
Expand Down

1 comment on commit 5b65abd

@Martii
Copy link
Member

@Martii Martii commented on 5b65abd Jul 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.