-
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
ce9d162
0f10436
ab1af62
000cd24
8f52bf6
9dfe376
b6fcad2
263da71
2b2bceb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,33 @@ def get_uri_from_url(url): | |
| return uri | ||
|
|
||
|
|
||
| def requires_auth(method): | ||
| def decorated(self, *args, **kwargs): | ||
| request = args[1] | ||
| auth = request.authorization | ||
| if not auth: | ||
| return Response( | ||
| "Unauthorized", 401, | ||
| {'WWW-Authenticate': 'Basic realm="Authentication Required"'}) | ||
| if not self.check_auth(auth.username, auth.password): | ||
| return Response( | ||
| "Wrong username or password", 401, | ||
| {'WWW-Authenticate': 'Basic realm="Authentication Required"'}) | ||
| return method(self, *args, **kwargs) | ||
| return decorated | ||
|
|
||
|
|
||
| def requires_admin(method): | ||
| def decorated(self, *args, **kwargs): | ||
| if not self.isso.conf.getboolean("admin", "enabled"): | ||
| return NotFound( | ||
| "Unavailable because 'admin' not enabled by site admin" | ||
| ) | ||
|
|
||
| return method(self, *args, **kwargs) | ||
| return decorated | ||
|
|
||
|
|
||
| class API(object): | ||
|
|
||
| FIELDS = set(['id', 'parent', 'text', 'author', 'website', | ||
|
|
@@ -1518,12 +1545,19 @@ def admin(self, env, req): | |
| @apiName latest | ||
| @apiVersion 0.12.6 | ||
| @apiDescription | ||
| Get the latest comments from the system, no matter which thread. Only available if `[general] latest-enabled` is set to `true` in server config. | ||
| Get the latest accepted comments from the system, no matter which thread. Only available if `[general] latest-enabled` is set to `true` in server config. | ||
|
gflohr marked this conversation as resolved.
Outdated
|
||
|
|
||
| @apiQuery {Number} limit | ||
| The quantity of last comments to retrieve | ||
|
|
||
| @apiExample {curl} Get the latest 5 comments | ||
| @apiQuery {Number{1,2}} [mode=1] | ||
|
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. can we make these strings? it's hard to remember what these integers mean
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. #1028 (comment) suggested the numeric constants. But make a suggestion for string constants.
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. mode=pending vs mode=accepted ?
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. Okay. I will change that then.
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. I have changed my mind after looking a little bit deeper into
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. Open to the idea of supporting both integers and strings, but I do strongly feel that we should move away from integers.
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. But that can only be done in requests. In the responses, it would break compatibility. So what should I do?
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. One way to maintain full backwards compatibility would be to have |
||
| The comments’ mode: | ||
| value | explanation | ||
| --- | --- | ||
| `1` | accepted: The comment was accepted by the server and is published. | ||
| `2` | in moderation queue: The comment was accepted by the server but awaits moderation. | ||
|
|
||
| @apiExample {curl} Get the latest 5 accepted comments | ||
| curl 'https://comments.example.com/latest?limit=5' | ||
|
|
||
| @apiUse commentResponse | ||
|
|
@@ -1565,6 +1599,23 @@ def latest(self, environ, request): | |
| "Unavailable because 'latest-enabled' not set by site admin" | ||
| ) | ||
|
|
||
| mode = request.args.get('mode', "1") | ||
|
|
||
| if mode != "1" and mode != "2": | ||
| return BadRequest( | ||
| "Mode must either be '1' for accepted comments or '2' for pedning comments waiting moderation" | ||
| ) | ||
|
|
||
| return self._latest(environ, request, mode) | ||
|
|
||
|
|
||
| def check_auth(self, username, password): | ||
| admin_password = self.isso.conf.get("admin", "password") | ||
|
|
||
| return username == 'admin' and password == admin_password | ||
|
|
||
|
|
||
| def _latest(self, environ, request, mode): | ||
| # get and check the limit | ||
| bad_limit_msg = "Query parameter 'limit' is mandatory (integer, >0)" | ||
| try: | ||
|
|
@@ -1575,7 +1626,7 @@ def latest(self, environ, request): | |
| return BadRequest(bad_limit_msg) | ||
|
|
||
| # retrieve the latest N comments from the DB | ||
| all_comments_gen = self.comments.fetchall(limit=None, order_by='created', mode='1') | ||
| all_comments_gen = self.comments.fetchall(limit=None, order_by='created', mode=mode) | ||
| comments = collections.deque(all_comments_gen, maxlen=limit) | ||
|
|
||
| # prepare a special set of fields (except text which is rendered specifically) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.