mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Add check for admin account
Enable server notices for CI Return same values as Synapse
This commit is contained in:
parent
f4cca68939
commit
2e1e0c81a1
|
|
@ -38,6 +38,12 @@ func LeaveRoomByID(
|
||||||
|
|
||||||
// Ask the roomserver to perform the leave.
|
// Ask the roomserver to perform the leave.
|
||||||
if err := rsAPI.PerformLeave(req.Context(), &leaveReq, &leaveRes); err != nil {
|
if err := rsAPI.PerformLeave(req.Context(), &leaveReq, &leaveRes); err != nil {
|
||||||
|
if leaveRes.Code != 0 {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: leaveRes.Code,
|
||||||
|
JSON: jsonerror.Forbidden(leaveRes.Message),
|
||||||
|
}
|
||||||
|
}
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.Unknown(err.Error()),
|
JSON: jsonerror.Unknown(err.Error()),
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ func Setup(
|
||||||
|
|
||||||
// server notifications
|
// server notifications
|
||||||
if cfg.Matrix.ServerNotices.Enabled {
|
if cfg.Matrix.ServerNotices.Enabled {
|
||||||
|
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
|
||||||
serverNotificationSender, err := getSenderDevice(context.Background(), userAPI, accountDB, cfg)
|
serverNotificationSender, err := getSenderDevice(context.Background(), userAPI, accountDB, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
||||||
|
|
@ -170,8 +171,6 @@ func Setup(
|
||||||
).Methods(http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
v3mux.Handle("/createRoom",
|
v3mux.Handle("/createRoom",
|
||||||
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||||
if r := rateLimits.Limit(req); r != nil {
|
if r := rateLimits.Limit(req); r != nil {
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,11 @@ func SendServerNotice(
|
||||||
txnID *string,
|
txnID *string,
|
||||||
txnCache *transactions.Cache,
|
txnCache *transactions.Cache,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// TODO: Only allow admins to send notices
|
if device.AccountType != userapi.AccountTypeAdmin {
|
||||||
if !cfgNotices.Enabled {
|
return util.JSONResponse{
|
||||||
return util.MessageResponse(http.StatusBadRequest, "Server notices are not enabled on this server.")
|
Code: http.StatusForbidden,
|
||||||
|
JSON: jsonerror.Forbidden("This API can only be used by admin users."),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if txnID != nil {
|
if txnID != nil {
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,8 @@ type PerformLeaveRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformLeaveResponse struct {
|
type PerformLeaveResponse struct {
|
||||||
|
Code int `json:"code,omitempty"`
|
||||||
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformInviteRequest struct {
|
type PerformInviteRequest struct {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,10 @@ func (r *Leaver) performLeaveRoomByID(
|
||||||
return nil, fmt.Errorf("unable to unmarshal tag content")
|
return nil, fmt.Errorf("unable to unmarshal tag content")
|
||||||
}
|
}
|
||||||
if _, ok = tags.Tags["m.server_notice"]; ok {
|
if _, ok = tags.Tags["m.server_notice"]; ok {
|
||||||
return nil, fmt.Errorf("Unable to reject server notice invite")
|
// mimic the returned values from Synapse
|
||||||
|
res.Message = "You cannot reject this invite"
|
||||||
|
res.Code = 403
|
||||||
|
return nil, fmt.Errorf("You cannot reject this invite")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ func (c *Global) Defaults(generate bool) {
|
||||||
c.Metrics.Defaults(generate)
|
c.Metrics.Defaults(generate)
|
||||||
c.DNSCache.Defaults()
|
c.DNSCache.Defaults()
|
||||||
c.Sentry.Defaults()
|
c.Sentry.Defaults()
|
||||||
|
c.ServerNotices.Defaults(generate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
func (c *Global) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
||||||
|
|
@ -142,6 +143,7 @@ type ServerNotices struct {
|
||||||
|
|
||||||
func (c *ServerNotices) Defaults(generate bool) {
|
func (c *ServerNotices) Defaults(generate bool) {
|
||||||
if generate {
|
if generate {
|
||||||
|
c.Enabled = true
|
||||||
c.LocalPart = "_server"
|
c.LocalPart = "_server"
|
||||||
c.DisplayName = "Server Alert"
|
c.DisplayName = "Server Alert"
|
||||||
c.RoomName = "Server Alert"
|
c.RoomName = "Server Alert"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue