-
Notifications
You must be signed in to change notification settings - Fork 464
API Access to Moderation Queue #1028
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
Open
gflohr
wants to merge
9
commits into
isso-comments:master
Choose a base branch
from
gflohr:pending
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ce9d162
views, comments: add /pending endpoint
gflohr 0f10436
views, API docs: clarify /latest vs. /pending
gflohr ab1af62
CHANGES.rst: Document new endpoint `/pending`
gflohr 000cd24
views, comments: fix api version for /pending
gflohr 8f52bf6
re-implement moderation queue access
gflohr 9dfe376
document API access to moderation queue
gflohr b6fcad2
shut up linter
gflohr 263da71
Merge branch 'master' into pending
gflohr 2b2bceb
clarify semantics of /latest
gflohr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,12 @@ | |
| import re | ||
| import tempfile | ||
| import unittest | ||
| import base64 | ||
|
|
||
| from urllib.parse import urlencode | ||
|
|
||
| from werkzeug.wrappers import Response | ||
| from werkzeug.datastructures import Headers | ||
|
|
||
| from isso import Isso, core, config | ||
| from isso.utils import http | ||
|
|
@@ -705,6 +707,20 @@ def testLatestNotEnabled(self): | |
| response = self.get('/latest?limit=5') | ||
| self.assertEqual(response.status_code, 404) | ||
|
|
||
| def testPendingNotFound(self): | ||
| # load some comments in a mix of posts | ||
| saved = [] | ||
| for idx, post_id in enumerate([1, 2, 2, 1, 2, 1, 3, 1, 4, 2, 3, 4, 1, 2]): | ||
| text = 'text-{}'.format(idx) | ||
| post_uri = 'test-{}'.format(post_id) | ||
| self.post('/new?uri=' + post_uri, data=json.dumps({'text': text})) | ||
| saved.append((post_uri, text)) | ||
|
|
||
| response = self.get('/pending?limit=5') | ||
|
|
||
| # If the admin interface was not enabled we should get a 404. | ||
| self.assertEqual(response.status_code, 404) | ||
|
|
||
|
|
||
| class TestHostDependent(unittest.TestCase): | ||
|
|
||
|
|
@@ -779,13 +795,17 @@ def setUp(self): | |
| conf.set("moderation", "enabled", "true") | ||
| conf.set("guard", "enabled", "off") | ||
| conf.set("hash", "algorithm", "none") | ||
| conf.set("admin", "enabled", "true") | ||
| self.conf = conf | ||
|
|
||
| class App(Isso, core.Mixin): | ||
| pass | ||
|
|
||
| self.app = App(conf) | ||
| self.app.wsgi_app = FakeIP(self.app.wsgi_app, "192.168.1.1") | ||
| self.client = JSONClient(self.app, Response) | ||
| self.post = self.client.post | ||
| self.get = self.client.get | ||
|
|
||
| def tearDown(self): | ||
| os.unlink(self.path) | ||
|
|
@@ -860,6 +880,64 @@ def testModerateComment(self): | |
| # Comment should no longer exist | ||
| self.assertEqual(self.app.db.comments.get(id_), None) | ||
|
|
||
| def testPendingWithoutAdmin(self): | ||
| self.conf.set("admin", "enabled", "false") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these tests guaranteed to be run in order? I'd prefer you un-set the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is no longer an issue. |
||
| response = self.get('/pending?limit=5') | ||
| self.assertEqual(response.status_code, 404) | ||
|
|
||
| def testPendingUnauthorized(self): | ||
| response = self.get('/pending?limit=5') | ||
| self.assertEqual(response.status_code, 401) | ||
|
|
||
| def getAuthenticated(self, url, username, password): | ||
| credentials = f"{username}:{password}" | ||
| encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8') | ||
| headers = Headers() | ||
| headers.add('Authorization', f'Basic {encoded_credentials}') | ||
|
|
||
| return self.client.get(url, headers=headers) | ||
|
|
||
| def testPendingNotEnabled(self): | ||
| password = "s3cr3t" | ||
| self.conf.set("admin", "enabled", "true") | ||
| self.conf.set("admin", "password", password) | ||
| response = self.getAuthenticated('/pending?limit=5', 'admin', password) | ||
| self.assertEqual(response.status_code, 404) | ||
|
|
||
| def testPendingNotEnabled(self): | ||
|
gflohr marked this conversation as resolved.
Outdated
|
||
| password = "s3cr3t" | ||
| self.conf.set("admin", "enabled", "true") | ||
| self.conf.set("admin", "password", password) | ||
| self.conf.set("general", "pending-enabled", "true") | ||
| response = self.getAuthenticated('/pending?limit=5', 'admin', password) | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| body = loads(response.data) | ||
| self.assertEqual(body, []) | ||
|
|
||
| def testPendingPosts(self): | ||
| # load some comments in a mix of posts | ||
| saved = [] | ||
| for idx, post_id in enumerate([1, 2, 2, 1, 2, 1, 3, 1, 4, 2, 3, 4, 1, 2]): | ||
| text = 'text-{}'.format(idx) | ||
| post_uri = 'test-{}'.format(post_id) | ||
| self.post('/new?uri=' + post_uri, data=json.dumps({'text': text})) | ||
| saved.append((post_uri, text)) | ||
|
|
||
| password = "s3cr3t" | ||
| self.conf.set("admin", "enabled", "true") | ||
| self.conf.set("admin", "password", password) | ||
| self.conf.set("general", "pending-enabled", "true") | ||
| response = self.getAuthenticated('/pending?limit=5', 'admin', password) | ||
| self.assertEqual(response.status_code, 200) | ||
|
|
||
| body = loads(response.data) | ||
| expected_items = saved[-5:] # latest 5 | ||
| for reply, expected in zip(body, expected_items): | ||
| expected_uri, expected_text = expected | ||
| self.assertIn(expected_text, reply['text']) | ||
| self.assertEqual(expected_uri, reply['uri']) | ||
|
|
||
|
|
||
| class TestUnsubscribe(unittest.TestCase): | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.