Phase 9: application services and admin completion
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
Implements PLAN.md Phase 9. internal/appservice reads registration files (appservice.config_files), matches namespaces the way Synapse does (anchored at the start), and delivers events to each service as transactions read from the roomserver's event stream at a cursor kept in appservice_state. A transaction in flight is recorded, so after a restart it is resent under the same ID; failures back off from 2s to 5m, and a successful ping cuts the backoff short. In the Client-Server API an as_token acts as the service's sender or, with ?user_id=, as any existing user in its namespace. Services register and log in their users with m.login.application_service; exclusive user and alias namespaces are refused to everybody else with M_EXCLUSIVE. Unknown aliases and users in a namespace are asked of the service first. The ping endpoint reports M_URL_NOT_SET, M_BAD_STATUS, M_CONNECTION_FAILED and M_CONNECTION_TIMEOUT. Services' own requests, and their users' when rate_limited is false, skip the rate limiter. Users can change their password (POST /account/password) and deactivate their account (POST /account/deactivate), both behind the password. Deactivation revokes tokens, deletes devices, optionally erases the profile and leaves every room through a new userapi.AccountObserver. The admin API is complete: user detail, the admin flag, deactivation and reactivation, password resets, devices, media quotas (media.max_user_storage_bytes plus per-user overrides), registration tokens with use limits and expiry (registration.require_token), server notices (internal/servernotices, server_notices.*), an editor for the federation allow/deny lists persisted in server_settings, a delivery view of the application services, and an audit log of every change. Migration 0011 adds the registration token, server notice room, media quota, audit log and appservice cursor tables. Policy lists are now returned sorted. The Complement entrypoint loads the registrations Complement mounts in /complement/appservice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b507753172
commit
a94794b866
69 files changed
+6922
-124
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package adminapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/dariuszjaniak/warp/server/internal/httputil"
|
||||
"github.com/dariuszjaniak/warp/server/internal/servernotices"
|
||||
"github.com/dariuszjaniak/warp/server/internal/userapi"
|
||||
)
|
||||
|
||||
// serverNoticeRequest is the POST /server_notices body.
|
||||
type serverNoticeRequest struct {
|
||||
UserID string `json:"user_id"`
|
||||
|
||||
// Content is an m.room.message content. A body is required; a missing
|
||||
// msgtype becomes m.text.
|
||||
Content map[string]any `json:"content"`
|
||||
}
|
||||
|
||||
// handlePostServerNotice implements POST /_warp/admin/v1/server_notices:
|
||||
// send a message from the server to one of its users.
|
||||
//
|
||||
// The notice goes into the user's server notice room, which is made the
|
||||
// first time and which the user is invited back to if they left it. The
|
||||
// user does not have to be online or to accept anything first: the
|
||||
// invite and the message wait for them.
|
||||
func (a *AdminAPI) handlePostServerNotice(w http.ResponseWriter, r *http.Request, auth userapi.Authenticated) error {
|
||||
if a.notices == nil {
|
||||
return httputil.NewError(http.StatusConflict, httputil.ErrCodeForbidden,
|
||||
"Server notices are not configured (server_notices.enabled is false, or the server has no signing key)")
|
||||
}
|
||||
var req serverNoticeRequest
|
||||
if err := httputil.DecodeJSON(w, r, &req); err != nil {
|
||||
return err
|
||||
}
|
||||
if req.UserID == "" {
|
||||
return httputil.MissingParam("user_id is required")
|
||||
}
|
||||
if body, _ := req.Content["body"].(string); body == "" {
|
||||
return httputil.MissingParam("content.body is required")
|
||||
}
|
||||
localpart, err := a.users.ParseLocalUserID(req.UserID)
|
||||
if err != nil {
|
||||
return httputil.InvalidParam("%s is not a user of this server", req.UserID)
|
||||
}
|
||||
|
||||
roomID, eventID, err := a.notices.Send(r.Context(), localpart, req.Content)
|
||||
switch {
|
||||
case errors.Is(err, servernotices.ErrNoSuchUser):
|
||||
return httputil.NotFound("No such user")
|
||||
case errors.Is(err, servernotices.ErrDeactivated):
|
||||
return httputil.Forbidden("%s is deactivated", req.UserID)
|
||||
case err != nil:
|
||||
return roomError(err)
|
||||
}
|
||||
a.audit(r.Context(), auth, auditServerNotice, a.users.UserID(localpart), map[string]any{
|
||||
"room_id": roomID, "event_id": eventID,
|
||||
})
|
||||
httputil.WriteJSON(w, http.StatusOK, map[string]string{"room_id": roomID, "event_id": eventID})
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user