Skip to content

Conversation

@gflohr
Copy link

@gflohr gflohr commented May 31, 2024

Checklist

  • All new and existing tests are passing
  • (If adding features:) I have added tests to cover my changes
  • (If docs changes needed:) I have updated the documentation accordingly.
  • I have added an entry to CHANGES.rst because this is a user-facing change or an important bugfix
  • I have written proper commit message(s)

What changes does this Pull Request introduce?

This PR introduces a new API endpoint /pending which works like /latest with the following differences:

  • Requests must be authorized with HTTP basic authentication using username "admin" and the admin password.
  • The endpoint is enabled in the configuration with [general] pending-enabled set to "true".
  • The endpoint only returns posts in the moderation queue.
  • The endpoint additionally requires the admin interface to be enabled.

The last requirement is maybe a little bit paranoid. Rationale: the admin password is currently only used for the admin interface. The requirement is meant to ensure that people have changed the default password. On the other hand, the endpoint does not expose sensitive information but only potential spam.

The feature/endpoint only makes sense, when moderation is enabled. But this is not explicitly checked because it causes no harm if moderation is not enabled.

Why is this necessary?

If you want to implement an alternative notification mechanism for comments awaiting moderation, access to the moderation queue via the API is required. The existing /latest endpoint only returns accepted comments. The new endpoint should require authorization because it exposes comments that are not publicly visible.
...

@ix5 ix5 added server (Python) server code feature needs-decision Architectural/Behavioral decision by maintainers needed labels Jun 5, 2024
@ix5 ix5 added this to the 0.14 milestone Jun 5, 2024
Copy link
Member

@ix5 ix5 left a comment

Choose a reason for hiding this comment

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

In general, I think this idea is sensible. A few comments inline.

I don't think you really need a new config option for this though. Either someone has already enabled the admin interface, giving anyone with admin credentials access to all comments, or admin is disabled, which will also disable the new /pending endpoint. My concern is that going at this rate, the whole routing system will at some point in the future be (poorly) exposed through the configuration file.

self.assertEqual(self.app.db.comments.get(id_), None)

def testPendingWithoutAdmin(self):
self.conf.set("admin", "enabled", "false")
Copy link
Member

Choose a reason for hiding this comment

The 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 admin.enabled value at test end.

Copy link
Author

Choose a reason for hiding this comment

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

That is no longer an issue.

@gflohr
Copy link
Author

gflohr commented Jul 7, 2024

I'm afraid, I will need a couple of weeks to come back to this PR.

@jelmer
Copy link
Member

jelmer commented Jul 25, 2025

Hi @gflohr , any news on this?

@gflohr
Copy link
Author

gflohr commented Jul 26, 2025

I'll try to find time within the next couple of days.

gflohr added 4 commits August 6, 2025 09:21
It works exactly like `/latest` but returns only posts waiting
moderation.  The endpoint has to be explicitly enabled and requests must
be authorized with the admin password.  The admin interface also has to
be enabled to make sure that people have changed the password.
It should be mentioned that the endpoint /latest only returns accepted
comments.
Version 0.13.0 is already released. . Change to the probably next
version 0.13.1.
gflohr added 2 commits August 7, 2025 23:08
Instead of a separate endpoint /pending, the existing endpoint /latest
now has an optional mode parameter.
@gflohr gflohr requested a review from jelmer August 7, 2025 20:13
The quantity of last comments to retrieve
@apiExample {curl} Get the latest 5 comments
@apiQuery {Number{1,2}} [mode=1]
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

@jelmer jelmer Aug 10, 2025

Choose a reason for hiding this comment

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

mode=pending vs mode=accepted ?

Copy link
Author

Choose a reason for hiding this comment

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

Okay. I will change that then.

Copy link
Author

Choose a reason for hiding this comment

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

I have changed my mind after looking a little bit deeper into isso/views/comments.py. The mode property is a number in all API responses. Do you really want to change that to a string for requests?

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

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

One way to maintain full backwards compatibility would be to have mode still be a number, but an equivalent parameter state would expect strings. In the responses, both mode and string can then be given. And mode could be deprecated everywhere. But up to you, not my project.

@jelmer jelmer self-requested a review August 17, 2025 10:27
Copy link
Member

@jelmer jelmer left a comment

Choose a reason for hiding this comment

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

Please also take a look at the lint failures.

The quantity of last comments to retrieve
@apiExample {curl} Get the latest 5 comments
@apiQuery {Number{1,2}} [mode=1]
Copy link
Member

Choose a reason for hiding this comment

The 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.

gflohr added 3 commits August 18, 2025 14:54
The mode parameter switches between accepted comments and comments
pending moderation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature needs-decision Architectural/Behavioral decision by maintainers needed server (Python) server code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants