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

Add warning if submitter is blocked #219

Merged
merged 6 commits into from
Feb 27, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/modules/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,12 +1135,27 @@
} );
}

function checkForBlocks() {
var deferred = $.Deferred();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too, explicit use of $.Deferred() can be removed, by putting a return on the next two lines

afchSubmission.getSubmitter().then( function ( creator ) {
checkIfUserIsBlocked( creator ).then( function ( blockData ) {
if ( blockData !== null ) {
var warning = creator + ' was blocked by ' + blockData.by + ' with an expiry time of ' + blockData.expiry + '. Reason: ' + blockData.reason;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var warning = creator + ' was blocked by ' + blockData.by + ' with an expiry time of ' + blockData.expiry + '. Reason: ' + blockData.reason;
var warning = 'Submitter' + creator + ' was blocked by ' + blockData.by + ' with an expiry time of ' + blockData.expiry + '. Reason: ' + blockData.reason;

otherwise it may not be always clear who the blocked user is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2022-02-20 at 12 26 48 AM

blockData.expiry is in ISO format which looks ugly when exposed in UI. Could it be changed to a more readable format?

Fine to leave for later though.

addWarning( warning );
}
deferred.resolve();
} );
} );
return deferred;
}

$.when(
checkReferences(),
checkDeletionLog(),
checkReviewState(),
checkLongComments(),
checkForCopyvio()
checkForCopyvio(),
checkForBlocks()
).then( function () {
deferred.resolve( warnings );
} );
Expand Down Expand Up @@ -2017,6 +2032,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 ];
siddharthvp marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}

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

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