Skip to content

Commit 2c07a9d

Browse files
committed
Merge pull request #513 from Martii/Issue-261RemoveReasons
Support existing incompleted "reason" value for remove user and script Auto-merge with private sizzle approval to temporarily bypass section block in #262
2 parents c137bc1 + 3a2ecd0 commit 2c07a9d

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

controllers/remove.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,40 @@ var Script = require('../models/script').Script;
1111
var User = require('../models/user').User;
1212
var destroySessions = require('../libs/modifySessions').destroy;
1313

14+
var formidable = require('formidable');
15+
var statusCodePage = require('../libs/templateHelpers').statusCodePage;
16+
1417
// Simple controller to remove content and save it in the graveyard
1518
exports.rm = function (aReq, aRes, aNext) {
1619
var type = aReq.params[0];
1720
var path = aReq.params[1];
1821
var authedUser = aReq.session.user;
1922

23+
var form = null;
24+
var reason = null;
25+
26+
if (!/multipart\/form-data/.test(aReq.headers['content-type'])) {
27+
return aNext();
28+
}
29+
30+
form = new formidable.IncomingForm();
31+
form.parse(aReq, function (aErr, aFields) {
32+
reason = aFields.reason.trim();
33+
});
34+
35+
if (!reason || reason === '' || /^User removed$/i.test(reason)) {
36+
return statusCodePage(aReq, aRes, aNext, {
37+
statusCode: 403,
38+
statusMessage: 'Invalid reason for removal.'
39+
});
40+
}
41+
2042
switch (type) {
2143
case 'scripts':
2244
case 'libs':
2345
path += type === 'libs' ? '.js' : '.user.js';
2446
Script.findOne({ installName: path }, function (aErr, aScript) {
25-
removeLib.remove(Script, aScript, authedUser, '', function (aRemoved) {
47+
removeLib.remove(Script, aScript, authedUser, reason, function (aRemoved) {
2648
if (!aRemoved) { return aNext(); }
2749
aRes.redirect('/');
2850
});
@@ -31,7 +53,7 @@ exports.rm = function (aReq, aRes, aNext) {
3153
case 'users':
3254
User.findOne({ name: { $regex: new RegExp('^' + path + '$', "i") } },
3355
function (aErr, aUser) {
34-
removeLib.remove(User, aUser, authedUser, '', function (aRemoved) {
56+
removeLib.remove(User, aUser, authedUser, reason, function (aRemoved) {
3557
if (!aRemoved) { return aNext(); }
3658

3759
// Destory all the sessions belonging to the removed user

libs/remove.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ exports.remove = function (aModel, aContent, aUser, aReason, aCallback) {
7878
model.find({ _authorId: aContent._id },
7979
function (aErr, aContentArr) {
8080
async.each(aContentArr, function (aContent, innerCb) {
81-
remove(model, aContent, aUser, null, innerCb);
81+
remove(model, aContent, aUser, 'User removed', innerCb);
8282
}, aCallback);
8383
});
8484
}, function () {

views/includes/scriptModals.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ <h4 class="modal-title">Remove {{script.fullName}}</h4>
3232
<p>Are you sure you want to remove this script? You cannot undo this.</p>
3333
</div>
3434
<div class="modal-footer">
35-
<form action="{{{script.scriptRemovePageUrl}}}" method="post">
35+
<form action="{{{script.scriptRemovePageUrl}}}" method="post" enctype="multipart/form-data">
36+
<input type="text" class="form-control" name="reason" placeholder="Reason for removal.">
37+
<br />
3638
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-fw fa-close"></i> Close</button>
3739
<input type="hidden" name="remove" value="true">
3840
<button type="submit" class="btn btn-danger"><i class="fa fa-fw fa-ban"></i> Remove</button>

views/includes/userModals.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ <h4 class="modal-title">Remove {{user.name}}</h4>
1010
<p>Are you sure you want to remove this user? You cannot undo this.</p>
1111
</div>
1212
<div class="modal-footer">
13-
<form action="{{{user.userRemovePageUrl}}}" method="post">
13+
<form action="{{{user.userRemovePageUrl}}}" method="post" enctype="multipart/form-data">
14+
<input type="text" class="form-control" name="reason" placeholder="Reason for removal.">
15+
<br />
1416
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-fw fa-close"></i> Close</button>
1517
<input type="hidden" name="remove" value="true">
1618
<button type="submit" class="btn btn-danger"><i class="fa fa-fw fa-ban"></i> Remove</button>

0 commit comments

Comments
 (0)