delete your own data (to enable testing)

This commit is contained in:
Adam Lofting 2014-04-04 15:36:08 +01:00
Родитель 14186dbd21
Коммит 2d7c6d2fbb
4 изменённых файлов: 53 добавлений и 2 удалений

Просмотреть файл

@ -161,3 +161,36 @@ exports.saveItem = function saveItem(entry, callback) {
}
});
};
/**
* Delete an activity from the DB
* @param {field object} toDelete
* @param {Function} callback
* @return {null}
*/
exports.deleteItem = function saveItem(toDelete, callback) {
pool.getConnection(function (err, connection) {
if (err) {
console.error(err);
callback(err);
} else {
var target = "logged_by=" + connection.escape(toDelete.logged_by) + " AND ";
target = target + "contributor_id=" + connection.escape(toDelete.contributor_id) + " AND ";
target = target + "contribution_date=" + connection.escape(toDelete.contribution_date) + " AND ";
target = target + "mofo_team=" + connection.escape(toDelete.mofo_team) + " AND ";
target = target + "data_bucket=" + connection.escape(toDelete.data_bucket);
connection.query('DELETE FROM contributions WHERE ' + target, function (err, result) {
if (err) {
console.error(err);
callback(err);
}
connection.release();
callback(null);
});
}
});
};

Просмотреть файл

@ -1,9 +1,10 @@
MVP:
☐ sample .env
Nice to have:
___________________
Archive:
✔ Delete recent entry option (only applies to self) @done (14-04-04 15:35)
✔ sample .env @done (14-04-04 14:52)
✔ enforce SSL on heroku @done (14-04-04 14:34)
✔ Remember users team etc. @done (14-04-04 14:06) @project(Nice to have)
✔ Date picker @done (14-04-04 13:49) @project(Nice to have)

Просмотреть файл

@ -52,12 +52,15 @@
<th>Team</th>
<th>Type</th>
<th>Description</th>
<th>&nbsp;</th>
</tr>
{{#each recentlyLogged}}
<tr>
{{#each this}}
<td>{{this}}</td>
{{/each}}
<td><a href="/delete?contributor_id={{contributor_id}}&contribution_date={{contribution_date}}&mofo_team={{mofo_team}}&data_bucket={{data_bucket}}" onclick="return confirm('Are you sure?')" class="btn btn-xm"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
{{/each}}
</table>

16
web.js
Просмотреть файл

@ -55,7 +55,7 @@ require("express-persona")(app, {
});
return;
}
console.log("Login attempt by: ", req.session.email);
res.json({
status: "failure",
reason: "Only users with a mozillafoundation.org email address may use this tool"
@ -109,6 +109,20 @@ app.post('/log-em', restrict, function (req, res) {
});
});
app.get('/delete', restrict, function (req, res) {
var toDelete = {
logged_by: req.session.email,
contributor_id: req.query.contributor_id,
contribution_date: req.query.contribution_date,
mofo_team: req.query.mofo_team,
data_bucket: req.query.data_bucket
};
data.deleteItem(toDelete, function deletedItem(err, response) {
console.log("deleted", req.session.email);
res.redirect('/log-em#logged');
});
});
app.get('/api', function (req, res) {
var date = null;
var team = null;