Title: [261128] trunk/Tools
Revision
261128
Author
[email protected]
Date
2020-05-04 17:09:04 -0700 (Mon, 04 May 2020)

Log Message

block-spammers tool should hide attachments
https://bugs.webkit.org/show_bug.cgi?id=211406

Reviewed by Darin Adler.

The logic is nearly identical to hiding comments. Just need to limit fields in the
search, so that we don't have to download attachment data.

* Scripts/block-spammers:
(get_comments):
(get_bugs_with_attachments_created_by_user):
(get_attachments):
(hide_comments):
(hide_attachments):
(main):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (261127 => 261128)


--- trunk/Tools/ChangeLog	2020-05-05 00:03:54 UTC (rev 261127)
+++ trunk/Tools/ChangeLog	2020-05-05 00:09:04 UTC (rev 261128)
@@ -1,3 +1,21 @@
+2020-05-04  Alexey Proskuryakov  <[email protected]>
+
+        block-spammers tool should hide attachments
+        https://bugs.webkit.org/show_bug.cgi?id=211406
+
+        Reviewed by Darin Adler.
+
+        The logic is nearly identical to hiding comments. Just need to limit fields in the
+        search, so that we don't have to download attachment data.
+
+        * Scripts/block-spammers:
+        (get_comments):
+        (get_bugs_with_attachments_created_by_user):
+        (get_attachments):
+        (hide_comments):
+        (hide_attachments):
+        (main):
+
 2020-05-04  Darin Adler  <[email protected]>
 
         Remove unneeded USE(MEDIAREMOTE)

Modified: trunk/Tools/Scripts/block-spammers (261127 => 261128)


--- trunk/Tools/Scripts/block-spammers	2020-05-05 00:03:54 UTC (rev 261127)
+++ trunk/Tools/Scripts/block-spammers	2020-05-05 00:09:04 UTC (rev 261128)
@@ -102,6 +102,19 @@
     return response.json()['bugs'][str(bug_id)]["comments"]
 
 
+def get_bugs_with_attachments_created_by_user(id):
+    response = requests.get('https://bugs.webkit.org/rest/bug',
+        params={'product': ['WebKit', 'Security'], 'f1': 'attachments.submitter', 'o1': 'equals', 'v1': id,
+                'include_fields': 'id,summary,product', 'token': bugzilla_token})
+    return response.json()['bugs']
+
+
+def get_attachments(bug_id):
+    response = requests.get('https://bugs.webkit.org/rest/bug/' + str(bug_id) + '/attachment',
+        params={'include_fields': 'id,bug_id,creator,creation_time,summary,is_private', 'token': bugzilla_token})
+    return response.json()['bugs'][str(bug_id)]
+
+
 def hide_bug(bug_id):
     response = requests.put('https://bugs.webkit.org/rest/bug/' + str(bug_id),
         json={'product': 'Spam', 'component': 'Spam', 'version': 'unspecified', 'is_creator_accessible': False, 'is_cc_accessible': False},
@@ -115,7 +128,7 @@
         json={'comment_is_private': {str(id): True for id in comment_ids}},
         params={'token': bugzilla_token})
     if not response:
-        print '!!! Failed to hide comments for bug' + str(bug_id) + ': ' + response.text
+        print '!!! Failed to hide comments for bug ' + str(bug_id) + ': ' + response.text
     for comment_id in comment_ids:
         response = requests.put('https://bugs.webkit.org/rest/bug/comment/' + str(comment_id) + '/tags',
                                 json={'comment_id': comment_id, 'add': ['spam']},
@@ -123,7 +136,14 @@
         if not response:
             print '!!! Failed to mark comment with spam tag: ' + response.text
 
+def hide_attachments(bug_id, attachment_ids):
+    response = requests.put('https://bugs.webkit.org/rest/bug/attachment/1',
+        json={'ids': attachment_ids, 'is_private': True},
+        params={'token': bugzilla_token})
+    if not response:
+        print '!!! Failed to hide attachments for bug ' + str(bug_id) + ': ' + response.text
 
+
 def ask_yes_no(question, default='yes'):
     if default is None:
         prompt_string = ' [y/n] '
@@ -167,6 +187,9 @@
         user_info['bugs_commented'] = [x for x in get_bugs_commented_on_by_user(account_id) if x['id'] not in created_bug_ids]
         for bug in user_info['bugs_commented']:
             bug['comments'] = get_comments(bug['id'])
+        user_info['bugs_with_attachments_added'] = [x for x in get_bugs_with_attachments_created_by_user(account_id) if x['id'] not in created_bug_ids]
+        for bug in user_info['bugs_with_attachments_added']:
+            bug['attachments'] = get_attachments(bug['id'])
 
     for user in users_to_disable:
         print sanitized_string(user['real_name']) + ' <' + user['name'] + '>'
@@ -183,6 +206,13 @@
             for comment in bug['comments']:
                 if comment['creator'] == user['name']:
                     print 'Comment ' + str(comment['count']) + ', ' + str(parse(comment['creation_time'])) + ': ' + sanitized_string(comment['text'])
+        if user['bugs_with_attachments_added']:
+            print 'Added attachments to ' + str(len(user['bugs_with_attachments_added'])) + ' bug(s):'
+        for bug in user['bugs_with_attachments_added']:
+            print 'https://bugs.webkit.org/show_bug.cgi?id=' + str(bug['id']) + ' ' + sanitized_string(bug['summary'])
+            for attachment in bug['attachments']:
+                if attachment['creator'] == user['name']:
+                    print 'Attachment ' + str(attachment['id']) + ', ' + str(parse(attachment['creation_time'])) + ': ' + sanitized_string(attachment['summary'])
         print
 
     if not ask_yes_no("Block all these accounts, and hide their bugs and comments?"):
@@ -204,6 +234,7 @@
                 continue
             print 'Moving bug ' + str(bug['id']) + ' to the Spam product'
             hide_bug(bug['id'])
+
         for bug in user['bugs_commented']:
             comments_to_hide = []
             for comment in bug['comments']:
@@ -218,6 +249,20 @@
                 print 'Hiding comment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])
             hide_comments(bug['id'], comments_to_hide)
 
+        for bug in user['bugs_with_attachments_added']:
+            attachments_to_hide = []
+            for attachment in bug['attachments']:
+                if attachment['creator'] != user['name']:
+                    continue
+                if attachment['is_private']:
+                    print 'Attachment ' + str(attachment['id']) + ' on bug ' + str(bug['id']) + ' is already private, skipping'
+                    continue
+                assert(attachment['bug_id'] == bug['id'])
+                attachments_to_hide.append(attachment['id'])
+            if attachments_to_hide:
+                print 'Deleting attachment(s) from user ' + str(user['name']) + ' on bug ' + str(bug['id'])
+            hide_attachments(bug['id'], attachments_to_hide)
 
+
 if __name__ == "__main__":
     main()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to