Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Add admin API to send a server_notice to one/all users#3531

Closed
krombel wants to merge 3 commits into
matrix-org:developfrom
krombel:extend_server_notices_sendToAll
Closed

Add admin API to send a server_notice to one/all users#3531
krombel wants to merge 3 commits into
matrix-org:developfrom
krombel:extend_server_notices_sendToAll

Conversation

@krombel
Copy link
Copy Markdown
Contributor

@krombel krombel commented Jul 13, 2018

In #3525 it got requested to have an easier way to send a server notice
to all users on the server.

Besides the query that got mentioned there this adds another command
which can be called via manhole to send those messages.

This PR adds admin API as follows:

http://localhost:8008/_matrix/client/api/v1/admin/send_server_notice/@dest:user?access_token=admin_access_token
JsonBodyToSend:
    {
        "event": {'msgtype':'m.text', 'body':'This is my message'}
    }
    or simply
    {
        'event_body': 'This is my message'
    }

@dest:user is optional

This would fix #3532

Signed-Off-By: Matthias Kesler krombel@krombel.de

@matrixbot
Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

1 similar comment
@matrixbot
Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

@krombel krombel force-pushed the extend_server_notices_sendToAll branch from 994826b to 5ed5a60 Compare July 13, 2018 14:51
@richvdh
Copy link
Copy Markdown
Member

richvdh commented Jul 13, 2018

let's not add too much magic which is only meant to be used via the manhole. better to add admin apis.

@krombel krombel force-pushed the extend_server_notices_sendToAll branch from 692dd05 to f4c79ea Compare July 13, 2018 16:37
@krombel krombel changed the title Adds method to send a server_notice to all rooms Adds admin API to send a server_notice to one/all users Jul 13, 2018
@krombel krombel force-pushed the extend_server_notices_sendToAll branch 2 times, most recently from 692dd05 to f4c79ea Compare July 13, 2018 17:34
@t3chguy
Copy link
Copy Markdown
Member

t3chguy commented Jul 13, 2018

Seems like all the Admin_APIs in https://github.com/matrix-org/synapse/tree/master/docs/admin_api reference r0, your example references v1

Comment thread synapse/rest/client/v1/admin.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you seem to switch between v1 and r0 interchangeably...

Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

so is it r0 or v1?

Copy link
Copy Markdown
Contributor Author

@krombel krombel Jul 13, 2018

Choose a reason for hiding this comment

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

it was a copy/paste error. I got confused by the doc strings of the other methods.
It should be r0 AFAIK. I have changed it now

Comment thread synapse/rest/client/v1/admin.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it seems like it is actually v1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is that class but it adds the /client/r0/ endpoints as well.

@krombel krombel force-pushed the extend_server_notices_sendToAll branch 3 times, most recently from 37b755d to d1141bc Compare July 25, 2018 14:55
@richvdh richvdh requested a review from a team August 10, 2018 22:06
@krombel krombel force-pushed the extend_server_notices_sendToAll branch from d1141bc to e9c2acd Compare August 10, 2018 22:53
@richvdh richvdh changed the title Adds admin API to send a server_notice to one/all users Add admin API to send a server_notice to one/all users Aug 13, 2018
Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you stick this under docs/admin_api, with a link here to say "there is an API which is documented at [...]"?

Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

under

Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"a lot of users". Or better: "a large number of registered users."

Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/with//

Comment thread synapse/rest/client/v1/admin.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if you drop the access_token (which is kinda obvious), does this fit on one line?

If not, can you indent this line more?

also, I suggest @user:host rather than @dest:user

Comment thread docs/server_notices.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like sending a message to all users is a dangerous thing that might happen by accident. Would it be better to have separate APIs

/admin/send_server_notice_to_user/<user_id>

/admin/send_server_notice_to_all_users

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would cause some code duplication as I would have to create a new servlet for that.
Personally I think there is a reason why we require an admin token so that the admin should take care that (s)he does it right.
But I can change it if you like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

well, fair enough. I won't insist.

Comment thread synapse/rest/client/v1/admin.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

surely we should yield here to wait for the request to complete?

In matrix-org#3525 it got requested to have an easier way to send a server notice
to all users on the server.

Besides the query that got mentioned there this adds another command
which can be called via manhole to send those messages.

Signed-Off-By: Matthias Kesler <krombel@krombel.de>
@krombel krombel force-pushed the extend_server_notices_sendToAll branch 2 times, most recently from a926483 to 240c23e Compare August 13, 2018 19:12
@krombel krombel force-pushed the extend_server_notices_sendToAll branch from 240c23e to a5dd1e9 Compare August 13, 2018 19:16


class ServerNoticeRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/admin/send_server_notice(/(?P<user_id>[^/]+))?")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm trying to figure out whether there is a difference in behaviour between /admin/send_server_notice/ (with a trailing slash and an empty user_id) and /admin/send_server_notice (with no trailing slash). AFAICT the former will fail, but the docs say it is valid?

I'd suggest that you should not accept /admin/send_server_notice/, and the docs should be updated to clarify.

@richvdh
Copy link
Copy Markdown
Member

richvdh commented May 2, 2019

I have taken this PR as a basis for another implementation, over in #5121. It doesn't currently implement the "send-to-all" functionality, so that is left for a future PR. My feeling is that should be a separate endpoint anyway.

In the meantime, I'm going to close this PR. Thank you for your work on this, @krombel!

@richvdh richvdh closed this May 2, 2019
@krombel krombel deleted the extend_server_notices_sendToAll branch July 26, 2019 09:00
@eMPee584
Copy link
Copy Markdown

[…]
So is it currently possible to use a wildcard for the /admin/send_server_notice_to_user/ endpoint to send everyone a notice, or would it need to be scripted? @krombel's well-looking draft implementation of an endpoint seems to have been /dev/nulled?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server notices need admin APIs

5 participants