Skip to content

Commit

Permalink
Add warning is submitter is blocked (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
gullyn authored Feb 27, 2022
1 parent f8e34cb commit 2b8f4d3
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,12 +1135,30 @@
} );
}

function checkForBlocks() {
return afchSubmission.getSubmitter().then( function ( creator ) {
return checkIfUserIsBlocked( creator ).then( function ( blockData ) {
if ( blockData !== null ) {
var date = 'infinity';
if ( blockData.expiry !== 'infinity' ) {
var data = new Date( blockData.expiry );
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ];
date = data.getUTCDate() + ' ' + monthNames[ data.getUTCMonth() ] + ' ' + data.getUTCFullYear() + ' ' + data.getUTCHours() + ':' + data.getUTCMinutes() + ' UTC';
}
var warning = 'Submitter ' + creator + ' was blocked by ' + blockData.by + ' with an expiry time of ' + date + '. Reason: ' + blockData.reason;
addWarning( warning );
}
} );
} );
}

$.when(
checkReferences(),
checkDeletionLog(),
checkReviewState(),
checkLongComments(),
checkForCopyvio()
checkForCopyvio(),
checkForBlocks()
).then( function () {
deferred.resolve( warnings );
} );
Expand Down Expand Up @@ -2025,6 +2043,30 @@
}
}

function checkIfUserIsBlocked( userName ) {
return AFCH.api.get( {
action: 'query',
list: 'blocks',
bkusers: userName
} ).then( function ( data ) {
var blocks = data.query.blocks;
var blockData = null;
var currentTime = new Date().toISOString();

for ( var i = 0; i < blocks.length; i++ ) {
if ( blocks[ i ].expiry === 'infinity' || blocks[ i ].expiry > currentTime ) {
blockData = blocks[ i ];
break;
}
}

return blockData;
} ).catch( function ( err ) {
console.log( 'abort ' + err );
return null;
} );
}

function showCommentOptions() {
loadView( 'comment', {} );
$( '#commentText' ).on( 'keyup', mw.util.debounce( 500, function () {
Expand Down

0 comments on commit 2b8f4d3

Please sign in to comment.