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

Conversation

gullyn
Copy link
Contributor

@gullyn gullyn commented Feb 10, 2022

This issue was raised in 2019 and was worked on, but no pull request was made. I've adapted @paul-111's code, updating the API request and fixing the formatting. This is what the warning looks like:
Screenshot from 2022-02-10 17-41-28

Copy link

@primefac primefac left a comment

Choose a reason for hiding this comment

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

I tested this with both a blocked and glocked user (who was also locally blocked on TestWiki) and neither of them showed up. Both users were put into the |u= parameter

@gullyn
Copy link
Contributor Author

gullyn commented Feb 17, 2022

@primefac I think that's happening because I'm using the afchPage.getCreator function, which just returns the user who created the page (not the one who submitted it). I could potentially use a regex to parse the pageText to find the |u= parameter, since I don't think there is a function to do that right now.

@primefac
Copy link

primefac commented Feb 17, 2022

90% of the time, the page creator will likely be the one who submitted the draft, but I've seen cases where (for example) a promo username violator created the page, got blocked, and then created a valid new account; the "creator's account" is blocked but the submitting editor isn't.

In other words, if it's possible, try to use the editor that submitted the draft over the page creator.

@@ -1135,12 +1135,27 @@
} );
}

function checkForBlocks() {
var deferred = $.Deferred();
afchPage.getCreator().then( function ( creator ) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use afchSubmission.getSubmitter

@@ -2017,6 +2032,31 @@
}
}

function checkIfUserIsBlocked( userName ) {
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.

using $.Deferred() is not needed here. You can just put a return in front of AFCH.api.get and and in front of blockData and null in the then/catch branches.

} ).then( function ( data ) {
var blocks = data.query.blocks;
var blockData = null;
var currentTime = new Date().toJSON();
Copy link
Member

Choose a reason for hiding this comment

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

suggest using toISOString instead which has same output but makes the intent clear

src/modules/submissions.js Show resolved Hide resolved
@gullyn
Copy link
Contributor Author

gullyn commented Feb 17, 2022

@siddharthvp I've implemented the suggestions you've made. I tested it on https://test.wikipedia.org/wiki/Draft:AFCH_Issue_106 and it works fine.

@@ -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

@siddharthvp siddharthvp linked an issue Feb 19, 2022 that may be closed by this pull request
@gullyn
Copy link
Contributor Author

gullyn commented Feb 19, 2022

Okay, I've removed the $.Deferred. I'm not an expert on promises, as I usually use async/await. I tested it to make sure and it does still work.

Copy link
Member

@siddharthvp siddharthvp left a comment

Choose a reason for hiding this comment

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

Last few comments

return afchSubmission.getSubmitter().then( function ( creator ) {
return 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.

return afchSubmission.getSubmitter().then( function ( creator ) {
return 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.

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.

@gullyn
Copy link
Contributor Author

gullyn commented Feb 19, 2022

I've made those changes. The Date object is really annoying and doesn't have a format function like most other languages, so I've made it format like this:
image

@siddharthvp
Copy link
Member

Looks good to me now, thanks!

@siddharthvp siddharthvp changed the title Add warning for blocked users Add warning is submitter is blocked Feb 27, 2022
@siddharthvp siddharthvp merged commit 2b8f4d3 into wikimedia-gadgets:master Feb 27, 2022
@siddharthvp siddharthvp changed the title Add warning is submitter is blocked Add warning if submitter is blocked Feb 27, 2022
@siddharthvp
Copy link
Member

^ my bad, accidentally merged this with a typo in the commit message

@gullyn gullyn deleted the check-if-blocked branch March 1, 2022 02:08
ptsgrn added a commit to ptsgrn/afch-rewrite that referenced this pull request Mar 2, 2022
* replaced https with http (wikimedia-gadgets#207)

* Updates to server.js: new setup

* properly enable mockItUp in server.js

* Show live preview while writing comments (wikimedia-gadgets#199)

* Handle slashes in article titles (wikimedia-gadgets#198)

Closes wikimedia-gadgets#110.

* Add comment to title subpage logic

* show copyvio warning (wikimedia-gadgets#197)

* Avoid use of deprecated token types (wikimedia-gadgets#192)

'edit' and 'options' token types are deprecated in favour of csrf token. Have used the function postWithEditToken() here that uses csrf token - which should be more stable than using `postWithToken( 'csrf', ... )`.

* Remove {{promising draft}}, and unify template removal logic (wikimedia-gadgets#189)

* update readme: npm start runs npm install automatically

* Remove acceptance form fields whose values aren't used (wikimedia-gadgets#191)

Values entered here have been unused since persondata was removed in wikimedia-gadgets@9632e4fd (2015).

* Use toolforge cdn's hogan, fixing licensing issue

https://en.wikipedia.org/wiki/Wikipedia:Miscellany_for_deletion/MediaWiki:Gadget-afchelper.js/core.js

* Revert "Use toolforge cdn's hogan, fixing licensing issue "

This reverts commit 7b87347.

* server.js: clarify instructions

* Log page name for mockItUp edits

* resolve nowiki issue

when this was uploaded, the hogan part would contain some stuff that
would get misread as a mediawiki template, so this change adds a
"banner" in the grunt concat config that puts a nowiki tag at the top
(and, as a side effect - hopefully harmless - a random nowiki in the
middle).

* Fix comment preview (wikimedia-gadgets#218)

- fix afc comment template - previous version did not work with some custom signatures
- hide comment preview after text box is emptied

* Show live preview for decline/reject reasons (wikimedia-gadgets#211)

As requested en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Articles_for_creation&diff=1066284130

* Add warning is submitter is blocked (wikimedia-gadgets#219)

* Support adding/editing short description (wikimedia-gadgets#196)

Co-authored-by: Diksha <75247382+dikshatakyar@users.noreply.github.com>
Co-authored-by: Enterprisey <danielhglus@gmail.com>
Co-authored-by: Siddharth VP <siddharthvp@gmail.com>
Co-authored-by: gullyn <74876079+gullyn@users.noreply.github.com>
ptsgrn added a commit to ptsgrn/afch-rewrite that referenced this pull request Apr 17, 2022
* replaced https with http (wikimedia-gadgets#207)

* Updates to server.js: new setup

* properly enable mockItUp in server.js

* Show live preview while writing comments (wikimedia-gadgets#199)

* Handle slashes in article titles (wikimedia-gadgets#198)

Closes wikimedia-gadgets#110.

* Add comment to title subpage logic

* show copyvio warning (wikimedia-gadgets#197)

* Avoid use of deprecated token types (wikimedia-gadgets#192)

'edit' and 'options' token types are deprecated in favour of csrf token. Have used the function postWithEditToken() here that uses csrf token - which should be more stable than using `postWithToken( 'csrf', ... )`.

* Remove {{promising draft}}, and unify template removal logic (wikimedia-gadgets#189)

* update readme: npm start runs npm install automatically

* Remove acceptance form fields whose values aren't used (wikimedia-gadgets#191)

Values entered here have been unused since persondata was removed in wikimedia-gadgets@9632e4fd (2015).

* Use toolforge cdn's hogan, fixing licensing issue

https://en.wikipedia.org/wiki/Wikipedia:Miscellany_for_deletion/MediaWiki:Gadget-afchelper.js/core.js

* Revert "Use toolforge cdn's hogan, fixing licensing issue "

This reverts commit 7b87347.

* server.js: clarify instructions

* Log page name for mockItUp edits

* resolve nowiki issue

when this was uploaded, the hogan part would contain some stuff that
would get misread as a mediawiki template, so this change adds a
"banner" in the grunt concat config that puts a nowiki tag at the top
(and, as a side effect - hopefully harmless - a random nowiki in the
middle).

* Fix comment preview (wikimedia-gadgets#218)

- fix afc comment template - previous version did not work with some custom signatures
- hide comment preview after text box is emptied

* Show live preview for decline/reject reasons (wikimedia-gadgets#211)

As requested en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Articles_for_creation&diff=1066284130

* Add warning is submitter is blocked (wikimedia-gadgets#219)

* Support adding/editing short description (wikimedia-gadgets#196)

* l10n after sync with updtream

Co-authored-by: Diksha <75247382+dikshatakyar@users.noreply.github.com>
Co-authored-by: Enterprisey <danielhglus@gmail.com>
Co-authored-by: Siddharth VP <siddharthvp@gmail.com>
Co-authored-by: gullyn <74876079+gullyn@users.noreply.github.com>
ptsgrn added a commit to ptsgrn/afch-rewrite that referenced this pull request Aug 21, 2022
* replaced https with http (wikimedia-gadgets#207)

* Updates to server.js: new setup

* properly enable mockItUp in server.js

* Show live preview while writing comments (wikimedia-gadgets#199)

* Handle slashes in article titles (wikimedia-gadgets#198)

Closes wikimedia-gadgets#110.

* Add comment to title subpage logic

* show copyvio warning (wikimedia-gadgets#197)

* Avoid use of deprecated token types (wikimedia-gadgets#192)

'edit' and 'options' token types are deprecated in favour of csrf token. Have used the function postWithEditToken() here that uses csrf token - which should be more stable than using `postWithToken( 'csrf', ... )`.

* Remove {{promising draft}}, and unify template removal logic (wikimedia-gadgets#189)

* update readme: npm start runs npm install automatically

* Remove acceptance form fields whose values aren't used (wikimedia-gadgets#191)

Values entered here have been unused since persondata was removed in wikimedia-gadgets@9632e4fd (2015).

* Use toolforge cdn's hogan, fixing licensing issue

https://en.wikipedia.org/wiki/Wikipedia:Miscellany_for_deletion/MediaWiki:Gadget-afchelper.js/core.js

* Revert "Use toolforge cdn's hogan, fixing licensing issue "

This reverts commit 7b87347.

* server.js: clarify instructions

* Log page name for mockItUp edits

* resolve nowiki issue

when this was uploaded, the hogan part would contain some stuff that
would get misread as a mediawiki template, so this change adds a
"banner" in the grunt concat config that puts a nowiki tag at the top
(and, as a side effect - hopefully harmless - a random nowiki in the
middle).

* Fix comment preview (wikimedia-gadgets#218)

- fix afc comment template - previous version did not work with some custom signatures
- hide comment preview after text box is emptied

* Show live preview for decline/reject reasons (wikimedia-gadgets#211)

As requested en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Articles_for_creation&diff=1066284130

* Add warning is submitter is blocked (wikimedia-gadgets#219)

* Support adding/editing short description (wikimedia-gadgets#196)

* Add missing parentheses to Line 2559 to fix wikimedia-gadgets#103 (wikimedia-gadgets#224)

This fixes wikimedia-gadgets#103 by adding missing parentheses to Line 2559 so that the part before "isDecline ? 'declined' : 'rejected'" correctly appears in the edit summary.

* fix toomanyvalues API error (wikimedia-gadgets#239)

* switch to GitHub Actions continuous integration (wikimedia-gadgets#236)

* style: eslinting

Co-authored-by: Diksha <75247382+dikshatakyar@users.noreply.github.com>
Co-authored-by: Enterprisey <danielhglus@gmail.com>
Co-authored-by: Siddharth VP <siddharthvp@gmail.com>
Co-authored-by: gullyn <74876079+gullyn@users.noreply.github.com>
Co-authored-by: GeoffreyTrang <geoffreytrang@gmail.com>
Co-authored-by: NovemLinguae <79697282+NovemLinguae@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if draft creator/submitter is blocked
3 participants