mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Add debug logging
This commit is contained in:
parent
031cc48f1a
commit
7d6f606d1c
1 changed files with 11 additions and 2 deletions
|
@ -190,16 +190,20 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
joinRules gomatrixserverlib.JoinRuleContent,
|
joinRules gomatrixserverlib.JoinRuleContent,
|
||||||
userID string,
|
userID string,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
logger := util.GetLogger(httpReq.Context()).WithField("restricted_join", userID)
|
||||||
|
|
||||||
// As a last effort, see if any of the restricted join rules match.
|
// As a last effort, see if any of the restricted join rules match.
|
||||||
// If so, we might be able to modify and sign the event so that it
|
// If so, we might be able to modify and sign the event so that it
|
||||||
// does pass auth.
|
// does pass auth.
|
||||||
var powerLevels gomatrixserverlib.PowerLevelContent
|
var powerLevels gomatrixserverlib.PowerLevelContent
|
||||||
if powerLevelsEvent, err := provider.PowerLevels(); err != nil {
|
if powerLevelsEvent, err := provider.PowerLevels(); err != nil {
|
||||||
|
logger.WithError(err).Error("Failed to get power levels from auth events")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnableToAuthoriseJoin("Room power levels do not exist"),
|
JSON: jsonerror.UnableToAuthoriseJoin("Room power levels do not exist"),
|
||||||
}
|
}
|
||||||
} else if err := json.Unmarshal(powerLevelsEvent.Content(), &powerLevels); err != nil {
|
} else if err := json.Unmarshal(powerLevelsEvent.Content(), &powerLevels); err != nil {
|
||||||
|
logger.WithError(err).Error("Failed to unmarshal power levels")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnableToAuthoriseJoin("Failed to unmarshal room power levels"),
|
JSON: jsonerror.UnableToAuthoriseJoin("Failed to unmarshal room power levels"),
|
||||||
|
@ -211,6 +215,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
for _, allowed := range joinRules.Allow {
|
for _, allowed := range joinRules.Allow {
|
||||||
// Skip types that we don't know about.
|
// Skip types that we don't know about.
|
||||||
if allowed.Type != gomatrixserverlib.MRoomMembership {
|
if allowed.Type != gomatrixserverlib.MRoomMembership {
|
||||||
|
logger.Infof("Skipping unknown join rule type %q", allowed.Type)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +226,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
}
|
}
|
||||||
queryRes := &api.QueryMembershipsForRoomResponse{}
|
queryRes := &api.QueryMembershipsForRoomResponse{}
|
||||||
if err := rsAPI.QueryMembershipsForRoom(httpReq.Context(), queryReq, queryRes); err != nil {
|
if err := rsAPI.QueryMembershipsForRoom(httpReq.Context(), queryReq, queryRes); err != nil {
|
||||||
|
logger.WithError(err).Errorf("Failed to query membership for room %q", queryReq.RoomID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +245,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
|
|
||||||
// The user doesn't seem to exist in this room, try the next one.
|
// The user doesn't seem to exist in this room, try the next one.
|
||||||
if !found {
|
if !found {
|
||||||
|
logger.Infof("User %q is not in room %q", userID, queryReq.RoomID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +277,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
"join_authorised_via_users_server": *member.StateKey,
|
"join_authorised_via_users_server": *member.StateKey,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("builder.SetContent failed")
|
logger.WithError(err).Error("builder.SetContent failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +288,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
}
|
}
|
||||||
event, err := eventutil.QueryAndBuildEvent(httpReq.Context(), builder, cfg.Matrix, time.Now(), rsAPI, &queryRes)
|
event, err := eventutil.QueryAndBuildEvent(httpReq.Context(), builder, cfg.Matrix, time.Now(), rsAPI, &queryRes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.GetLogger(httpReq.Context()).WithError(err).Error("builder.SetContent failed")
|
logger.WithError(err).Error("builder.SetContent failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +301,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
// Now, see if the join is valid with the new changes. If it isn't
|
// Now, see if the join is valid with the new changes. If it isn't
|
||||||
// then something else is forbidding the join.
|
// then something else is forbidding the join.
|
||||||
if err = gomatrixserverlib.Allowed(&signed, &provider); err != nil {
|
if err = gomatrixserverlib.Allowed(&signed, &provider); err != nil {
|
||||||
|
logger.WithError(err).Error("Join is not allowed")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusForbidden,
|
Code: http.StatusForbidden,
|
||||||
JSON: jsonerror.Forbidden(err.Error()),
|
JSON: jsonerror.Forbidden(err.Error()),
|
||||||
|
@ -312,6 +320,7 @@ func attemptMakeJoinForRestrictedMembership(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Error("No room matching join rule memberships found")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnableToAuthoriseJoin("You are not joined to any allowed rooms"),
|
JSON: jsonerror.UnableToAuthoriseJoin("You are not joined to any allowed rooms"),
|
||||||
|
|
Loading…
Reference in a new issue