@@ -11,18 +11,40 @@ var Script = require('../models/script').Script;
1111var User = require ( '../models/user' ) . User ;
1212var 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
1518exports . 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 ( ! / m u l t i p a r t \/ f o r m - d a t a / . 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 === '' || / ^ U s e r r e m o v e d $ / 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
0 commit comments