Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #173

Merged
merged 17 commits into from
Jun 22, 2014
16 changes: 6 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var group = require('./controllers/group');
var discussion = require('./controllers/discussion');
var issue = require('./controllers/issue');
var scriptStorage = require('./controllers/scriptStorage');
var statusCodePage = require('./libs/templateHelpers').statusCodePage;

var modelParser = require('./libs/modelParser');

var statusCodePage = require('./libs/templateHelpers').statusCodePage;
var modifySessions = require('./libs/modifySessions');

var settings = require('./models/settings.json');

var connectStr = process.env.CONNECT_STRING || settings.connect;
var sessionSecret = process.env.SESSION_SECRET || settings.secret;
var db = mongoose.connection;
Expand Down Expand Up @@ -61,8 +61,7 @@ app.configure(function(){
'max-age=8640000; includeSubDomains');

if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(301, 'https://' + req.headers.host
+ encodeURI(req.url));
return res.redirect(301, 'https://' + req.headers.host + encodeURI(req.url));
}

next();
Expand Down Expand Up @@ -153,7 +152,6 @@ app_route('/user/add/lib/new').get(script.lib(user.editScript)).post(script.lib(
app_route('/user/add/scripts/upload').post(user.uploadScript);
app_route('/user/add/lib/upload').post(script.lib(user.uploadScript));


// Script routes
app_route('/scripts/:username/:namespace?/:scriptname').get(script.view);
app_route('/script/:username/:namespace?/:scriptname/edit').get(script.edit).post(script.edit);
Expand Down Expand Up @@ -201,9 +199,8 @@ 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/libs/:username/:scriptname/:unflag?', script.lib(script.flag)); //
app.get(listRegex('\/flagged(?:\/([^\/]+?))?', 'user|script'),
moderation.flagged); //
app.get('/flag/libs/:username/:scriptname/:unflag?', script.lib(script.flag));
app.get(listRegex('\/flagged(?:\/([^\/]+?))?', 'user|script'), moderation.flagged);
app.get(listRegex('\/graveyard(?:\/([^\/]+?))?', ''), moderation.graveyard);
app.get(/^\/remove\/(.+?)\/(.+)$/, remove.rm);

Expand Down Expand Up @@ -243,4 +240,3 @@ app.use(function (req, res, next) {
statusMessage: 'This is not the page you\'re are looking for.',
});
});

3 changes: 0 additions & 3 deletions controllers/_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var modelQuery = require('../libs/modelQuery');
// Generate a bootstrap3 pagination widget.
var getDefaultPagination = require('../libs/templateHelpers').getDefaultPagination;


//--- Views
exports.example = function(req, res, next) {
var authedUser = req.session.user;
Expand All @@ -38,7 +37,6 @@ exports.example = function (req, res, next) {
options.pageMetaKeywords = pageMetaKeywords.join(', ');

//--- Tasks
// ...

//---
function preRender() { };
Expand Down Expand Up @@ -81,7 +79,6 @@ exports.example = function (req, res, next) {
scriptListQuery.sort('-rating -installs -updated');
});


// Pagination
var pagination = getDefaultPagination(req);
pagination.applyToQuery(scriptListQuery);
Expand Down
32 changes: 21 additions & 11 deletions controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ function getOAuthStrategies(stored) {
strategy = strategies[type];
if (strategy.oauth) {
oAuthStrats.push(stored[type] ||
nil({ 'strat' : type, 'id' : '', 'key' : ''}));
nil({
'strat': type,
'id': '',
'key': ''
}));
}
}

Expand All @@ -56,14 +60,20 @@ exports.userAdmin = function (req, res, next) {
users.forEach(function(user) {
var roles = [];
userRoles.forEach(function(role, index) {
roles.push({ 'val' : index, 'display' : role,
'selected' : index === user.role });
roles.push({
'val': index,
'display': role,
'selected': index === user.role
});
});
roles = roles.splice(thisUser.role + 1);
roles.reverse();

options.users.push({ 'id' : user._id, 'name' : user.name,
'roles' : roles });
options.users.push({
'id': user._id,
'name': user.name,
'roles': roles
});
});

res.render('userAdmin', options);
Expand All @@ -83,20 +93,22 @@ exports.adminUserView = function (req, res, next) {
function(err, user) {
if (err || !user) { return next(); }

res.render('userAdmin', { user: {
info: JSON.stringify(user.toObject(), null, ' ') } });
res.render('userAdmin', {
user: {
info: JSON.stringify(user.toObject(), null, ' ')
}
});
});
};


var jsonModelMap = {
'User': User,
'Script': Script,
'Group': Group,
'Discussion': Discussion,
'Comment': Comment,
'Vote': Vote,
'Flag': Flag,
'Flag': Flag
};
// View everything about a particular user
// This is mostly for debugging in production
Expand All @@ -117,7 +129,6 @@ exports.adminJsonView = function (req, res, next) {
if (!options.isAdmin)
return res.send(403, { status: 403, message: 'Not an admin.' });


var model = jsonModelMap[modelname];
if (!model)
return res.send(400, { status: 400, message: 'Invalid model.' });
Expand Down Expand Up @@ -324,7 +335,6 @@ exports.apiAdminUpdate = function (req, res, next) {
});
}


return strategy.save(function(err, strategy) {
loadPassport(strategy);
cb();
Expand Down
4 changes: 1 addition & 3 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ exports.callback = function (req, res, next) {
// Get the passport strategy instance so we can alter the _verfiy method
strategyInstance = strategyInstances[strategy];


// Hijak the private verify method so we can fuck shit up freely
// We use this library for things it was never intended to do
if (openIdStrategies[strategy]) {
Expand All @@ -125,8 +124,7 @@ exports.callback = function (req, res, next) {
}

// This callback will happen after the verify routine
var authenticate = passport.authenticate(strategy,
function (err, user, info) {
var authenticate = passport.authenticate(strategy, function(err, user, info) {
if (err) { return next(err); }
if (!user) {
return res.redirect(doneUrl + (doneUrl === '/' ? 'register' : '')
Expand Down
2 changes: 1 addition & 1 deletion controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var categories = [
slug: 'announcements',
name: 'Announcements',
description: 'UserScripts News (OpenUserJS, GreaseMonkey, etc)',
roleReqToPostTopic: 3, // Moderator
roleReqToPostTopic: 3 // Moderator
},
{
slug: 'garage',
Expand Down
3 changes: 2 additions & 1 deletion controllers/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ exports.addScriptToGroups = function (script, groupNames, callback) {
group.rating = getRating(scripts);
group.updated = new Date();
group.save(function() { });
});
}
);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var modelQuery = require('../libs/modelQuery');
var execQueryTask = require('../libs/tasks').execQueryTask;
var removeSession = require('../libs/modifySessions').remove;


// The home page has scripts and groups in a sidebar
exports.home = function(req, res) {
var authedUser = req.session.user;
Expand Down Expand Up @@ -175,7 +174,8 @@ function getSearchResults (req, res, prefixSearch, fullSearch, opts, callback) {
'search': search,
'scriptsList': scriptsList
});
});
}
);
};

// Script search results
Expand Down
3 changes: 1 addition & 2 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var discussionLib = require('./discussion');
var execQueryTask = require('../libs/tasks').execQueryTask;
var countTask = require('../libs/tasks').countTask;


// List script issues
exports.list = function(req, res, next) {
var authedUser = req.session.user;
Expand Down Expand Up @@ -261,7 +260,6 @@ exports.open = function (req, res, next) {
} else {
// New Issue Page


//--- Tasks
// ...

Expand Down Expand Up @@ -323,6 +321,7 @@ exports.changeStatus = function (req, res, next) {
+ (type === 'libs' ? '.js' : '.user.js')) }, function (err, script) {

if (err || !script) { return next(); }
if (err || !script) { return next(); }

discussionLib.findDiscussion(category, topic, function(issue) {
if (!issue) { return next(); }
Expand Down
8 changes: 5 additions & 3 deletions controllers/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ exports.flagged = function (req, res, next) {
var user = req.session.user;
var type = req.route.params.shift() || 'users';
var baseUrl = '/flagged' + (type ? '/' + type : '');
var options = { title: 'Flagged Content', moderation: true,
username: user ? user.name : '' };
var options = {
title: 'Flagged Content', moderation: true,
username: user ? user.name : ''
};

options[type + 'Type'] = true;

Expand Down Expand Up @@ -126,7 +128,7 @@ exports.removedItemPage = function (req, res, next) {
if (err || !removedItemData) { return next(); }

res.json(removedItemData);
})
});
};

exports.removedItemListPage = function(req, res, next) {
Expand Down
Empty file modified controllers/remove.js
Whitespace-only changes.
12 changes: 6 additions & 6 deletions controllers/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ var getScriptPageTasks = function(options) {
var script = options.script;
var authedUser = options.authedUser;


//--- Tasks

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


// Show collaborators of the script
if (script.meta.author && script.meta.collaborator) {
options.hasCollab = true;
Expand Down Expand Up @@ -308,7 +306,6 @@ exports.view = function (req, res, next) {
//--- Tasks
tasks = tasks.concat(getScriptPageTasks(options));


//---
function preRender() {
var pageMetaKeywords = ['userscript', 'greasemonkey'];
Expand Down Expand Up @@ -504,8 +501,10 @@ exports.vote = function (req, res, next) {
}

voteModel.save(saveScript);
});
});
}
);
}
);
};

// Script flagging
Expand All @@ -523,5 +522,6 @@ exports.flag = function (req, res, next) {
fn(Script, script, req.session.user, function(flagged) {
res.redirect((isLib ? '/libs/' : '/scripts/') + encodeURI(installName));
});
});
}
);
};
13 changes: 8 additions & 5 deletions controllers/scriptStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ if (process.env.NODE_ENV === 'production') {
// You need to install (and ruby too): https://github.com/jubos/fake-s3
// Then run the fakes3.sh script or: fakes3 -r fakeS3 -p 10001
var DEV_AWS_URL = process.env.DEV_AWS_URL || 'localhost:10001';
AWS.config.update({ accessKeyId: 'fakeId', secretAccessKey: 'fakeKey',
AWS.config.update({
accessKeyId: 'fakeId',
secretAccessKey: 'fakeKey',
httpOptions: {
proxy: DEV_AWS_URL, agent: require('http').globalAgent
}});
proxy: DEV_AWS_URL,
agent: require('http').globalAgent
}
});
}

/*Script.find({ installName: /^[^\/]+\/[^\/]+\/[^\/]+$/ },function (err, scripts){
Expand Down Expand Up @@ -275,7 +279,6 @@ exports.storeScript = function (user, meta, buf, callback, update) {
// Prevent a removed script from being reuploaded
findDeadorAlive(Script, { installName: caseInsensitive(installName) }, true,
function(alive, script, removed) {

if (removed || (!script && (update || collaborators))) {
return callback(null);
} else if (!script) {
Expand Down Expand Up @@ -352,7 +355,7 @@ exports.webhook = function (req, res) {
var repos = {};
var repo = null;

res.end(); // close connection
res.end(); // Close connection

// Test for know GH webhook ips: https://api.github.com/meta
if (!req.body.payload ||
Expand Down
Loading