aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authordevonh <devon.dmytro@gmail.com>2023-06-14 14:23:46 +0000
committerGitHub <noreply@github.com>2023-06-14 14:23:46 +0000
commite4665979bfbe006368d55189f074e456fe19b198 (patch)
treee909d694a022478d0dbe3cc58ee8a2dc289bc969 /clientapi
parent7a2e325d1014d76188b47a011730a42443f3c174 (diff)
Merge SenderID & Per Room User Key work (#3109)
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/directory.go23
-rw-r--r--clientapi/routing/membership.go26
-rw-r--r--clientapi/routing/profile.go6
-rw-r--r--clientapi/routing/redaction.go15
-rw-r--r--clientapi/routing/sendevent.go13
-rw-r--r--clientapi/routing/state.go13
-rw-r--r--clientapi/threepid/invites.go6
7 files changed, 81 insertions, 21 deletions
diff --git a/clientapi/routing/directory.go b/clientapi/routing/directory.go
index f01e24ec..d9129d1b 100644
--- a/clientapi/routing/directory.go
+++ b/clientapi/routing/directory.go
@@ -233,11 +233,18 @@ func RemoveLocalAlias(
}
}
- deviceSenderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomIDRes.RoomID, *userID)
+ validRoomID, err := spec.NewRoomID(roomIDRes.RoomID)
if err != nil {
return util.JSONResponse{
- Code: http.StatusInternalServerError,
- JSON: spec.InternalServerError{Err: "Could not find SenderID for this device"},
+ Code: http.StatusNotFound,
+ JSON: spec.NotFound("The alias does not exist."),
+ }
+ }
+ deviceSenderID, err := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *userID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusNotFound,
+ JSON: spec.NotFound("The alias does not exist."),
}
}
@@ -321,7 +328,15 @@ func SetVisibility(
JSON: spec.BadJSON("userID for this device is invalid"),
}
}
- senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomID, *deviceUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ util.GetLogger(req.Context()).WithError(err).Error("roomID is invalid")
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: spec.BadJSON("RoomID is invalid"),
+ }
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *deviceUserID)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go
index 03e85edb..bafc37b6 100644
--- a/clientapi/routing/membership.go
+++ b/clientapi/routing/membership.go
@@ -64,7 +64,14 @@ func SendBan(
JSON: spec.Forbidden("You don't have permission to ban this user, bad userID"),
}
}
- senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomID, *deviceUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: spec.BadJSON("RoomID is invalid"),
+ }
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *deviceUserID)
if err != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
@@ -155,7 +162,14 @@ func SendKick(
JSON: spec.Forbidden("You don't have permission to kick this user, bad userID"),
}
}
- senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomID, *deviceUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: spec.BadJSON("RoomID is invalid"),
+ }
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *deviceUserID)
if err != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
@@ -428,7 +442,11 @@ func buildMembershipEvent(
if err != nil {
return nil, err
}
- senderID, err := rsAPI.QuerySenderIDForUser(ctx, roomID, *userID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return nil, err
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *userID)
if err != nil {
return nil, err
}
@@ -437,7 +455,7 @@ func buildMembershipEvent(
if err != nil {
return nil, err
}
- targetSenderID, err := rsAPI.QuerySenderIDForUser(ctx, roomID, *targetID)
+ targetSenderID, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *targetID)
if err != nil {
return nil, err
}
diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go
index e734e2e4..8a44834e 100644
--- a/clientapi/routing/profile.go
+++ b/clientapi/routing/profile.go
@@ -368,7 +368,11 @@ func buildMembershipEvents(
return nil, err
}
for _, roomID := range roomIDs {
- senderID, err := rsAPI.QuerySenderIDForUser(ctx, roomID, *fullUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return nil, err
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *fullUserID)
if err != nil {
return nil, err
}
diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go
index da48e84d..42f02939 100644
--- a/clientapi/routing/redaction.go
+++ b/clientapi/routing/redaction.go
@@ -54,7 +54,14 @@ func SendRedaction(
JSON: spec.Forbidden("userID doesn't have power level to redact"),
}
}
- senderID, queryErr := rsAPI.QuerySenderIDForUser(req.Context(), roomID, *deviceUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: spec.BadJSON("RoomID is invalid"),
+ }
+ }
+ senderID, queryErr := rsAPI.QuerySenderIDForUser(req.Context(), *validRoomID, *deviceUserID)
if queryErr != nil {
return util.JSONResponse{
Code: http.StatusForbidden,
@@ -103,8 +110,8 @@ func SendRedaction(
JSON: spec.Forbidden("You don't have permission to redact this event, no power_levels event in this room."),
}
}
- pl, err := plEvent.PowerLevels()
- if err != nil {
+ pl, plErr := plEvent.PowerLevels()
+ if plErr != nil {
return util.JSONResponse{
Code: 403,
JSON: spec.Forbidden(
@@ -134,7 +141,7 @@ func SendRedaction(
Type: spec.MRoomRedaction,
Redacts: eventID,
}
- err := proto.SetContent(r)
+ err = proto.SetContent(r)
if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("proto.SetContent failed")
return util.JSONResponse{
diff --git a/clientapi/routing/sendevent.go b/clientapi/routing/sendevent.go
index 4d0a9f24..d51a570d 100644
--- a/clientapi/routing/sendevent.go
+++ b/clientapi/routing/sendevent.go
@@ -273,7 +273,14 @@ func generateSendEvent(
JSON: spec.BadJSON("Bad userID"),
}
}
- senderID, err := rsAPI.QuerySenderIDForUser(ctx, roomID, *fullUserID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return nil, &util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: spec.BadJSON("RoomID is invalid"),
+ }
+ }
+ senderID, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *fullUserID)
if err != nil {
return nil, &util.JSONResponse{
Code: http.StatusNotFound,
@@ -344,8 +351,8 @@ func generateSendEvent(
stateEvents[i] = queryRes.StateEvents[i].PDU
}
provider := gomatrixserverlib.NewAuthEvents(gomatrixserverlib.ToPDUs(stateEvents))
- if err = gomatrixserverlib.Allowed(e.PDU, &provider, func(roomID string, senderID spec.SenderID) (*spec.UserID, error) {
- return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
+ if err = gomatrixserverlib.Allowed(e.PDU, &provider, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
+ return rsAPI.QueryUserIDForSender(ctx, *validRoomID, senderID)
}); err != nil {
return nil, &util.JSONResponse{
Code: http.StatusForbidden,
diff --git a/clientapi/routing/state.go b/clientapi/routing/state.go
index e3a209b6..f53cb301 100644
--- a/clientapi/routing/state.go
+++ b/clientapi/routing/state.go
@@ -150,7 +150,7 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
for _, ev := range stateRes.StateEvents {
stateEvents = append(
stateEvents,
- synctypes.ToClientEventDefault(func(roomID string, senderID spec.SenderID) (*spec.UserID, error) {
+ synctypes.ToClientEventDefault(func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
}, ev),
)
@@ -173,14 +173,19 @@ func OnIncomingStateRequest(ctx context.Context, device *userapi.Device, rsAPI a
}
for _, ev := range stateAfterRes.StateEvents {
sender := spec.UserID{}
- userID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), ev.SenderID())
+ evRoomID, err := spec.NewRoomID(ev.RoomID())
+ if err != nil {
+ util.GetLogger(ctx).WithError(err).Error("Event roomID is invalid")
+ continue
+ }
+ userID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, ev.SenderID())
if err == nil && userID != nil {
sender = *userID
}
sk := ev.StateKey()
if sk != nil && *sk != "" {
- skUserID, err := rsAPI.QueryUserIDForSender(ctx, ev.RoomID(), spec.SenderID(*ev.StateKey()))
+ skUserID, err := rsAPI.QueryUserIDForSender(ctx, *evRoomID, spec.SenderID(*ev.StateKey()))
if err == nil && skUserID != nil {
skString := skUserID.String()
sk = &skString
@@ -367,7 +372,7 @@ func OnIncomingStateTypeRequest(
}
stateEvent := stateEventInStateResp{
- ClientEvent: synctypes.ToClientEventDefault(func(roomID string, senderID spec.SenderID) (*spec.UserID, error) {
+ ClientEvent: synctypes.ToClientEventDefault(func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
}, event),
}
diff --git a/clientapi/threepid/invites.go b/clientapi/threepid/invites.go
index e7ffbac2..d15cc6d4 100644
--- a/clientapi/threepid/invites.go
+++ b/clientapi/threepid/invites.go
@@ -359,7 +359,11 @@ func emit3PIDInviteEvent(
if err != nil {
return err
}
- sender, err := rsAPI.QuerySenderIDForUser(ctx, roomID, *userID)
+ validRoomID, err := spec.NewRoomID(roomID)
+ if err != nil {
+ return err
+ }
+ sender, err := rsAPI.QuerySenderIDForUser(ctx, *validRoomID, *userID)
if err != nil {
return err
}