Skip to content

Commit

Permalink
Some more verbose logging when rejecting knocks
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 48d500d
Author: Neil Alexander <[email protected]>
Date:   Thu Jul 22 09:38:56 2021 +0100

    More logging still

commit 0378db3
Author: Neil Alexander <[email protected]>
Date:   Thu Jul 22 09:33:34 2021 +0100

    More verbose reporting
  • Loading branch information
neilalexander committed Jul 22, 2021
1 parent ae88543 commit b9eb787
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions eventauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,10 @@ func (m *membershipAllower) membershipAllowedSelf() error { // nolint: gocyclo
}
if m.newMember.Membership == Knock {
if m.joinRule.JoinRule != Knock {
return m.membershipFailed()
return errorf(
"%q is not allowed to change their membership from %q to %q as the join rule %q does not allow knocking",
m.targetID, m.oldMember.Membership, m.newMember.Membership, m.joinRule.JoinRule,
)
}
// A user that is not in the room is allowed to knock if the join
// rules are "knock" and they are not already joined to, invited to
Expand All @@ -1028,13 +1031,19 @@ func (m *membershipAllower) membershipAllowedSelf() error { // nolint: gocyclo
if supported, err := m.roomVersion.AllowKnockingInEventAuth(); err != nil {
return fmt.Errorf("m.roomVersion.AllowKnockingInEventAuth: %w", err)
} else if !supported {
return m.membershipFailed()
return errorf(
"%q is not allowed to change their membership from %q to %q as room version %q does not support knocking",
m.targetID, m.oldMember.Membership, m.newMember.Membership, m.roomVersion,
)
}
switch m.oldMember.Membership {
case Join, Invite, Ban:
// The user is already joined, invited or banned, therefore they
// can't knock.
return m.membershipFailed()
return errorf(
"%q is not allowed to change their membership from %q to %q as they are already joined/invited/banned",
m.targetID, m.oldMember.Membership, m.newMember.Membership,
)
default:
// A non-joined, non-invited, non-banned user is allowed to knock.
return nil
Expand Down Expand Up @@ -1122,11 +1131,20 @@ func (m *membershipAllower) membershipAllowedOther() error { // nolint: gocyclo
return nil
}
// A user can invite in response to a knock.
if m.joinRule.JoinRule == Knock && m.oldMember.Membership == Knock && senderLevel >= m.powerLevels.Invite {
if m.oldMember.Membership == Knock && senderLevel >= m.powerLevels.Invite {
if m.joinRule.JoinRule != Knock {
return errorf(
"%q is not allowed to change the membership of %q from %q to %q as the join rule %q does not allow knocking",
m.senderID, m.targetID, m.oldMember.Membership, m.newMember.Membership, m.joinRule.JoinRule,
)
}
if supported, err := m.roomVersion.AllowKnockingInEventAuth(); err != nil {
return fmt.Errorf("m.roomVersion.AllowKnockingInEventAuth: %w", err)
} else if !supported {
return m.membershipFailed()
return errorf(
"%q is not allowed to change the membership of %q from %q to %q as room version %q does not support knocking",
m.senderID, m.targetID, m.oldMember.Membership, m.newMember.Membership, m.roomVersion,
)
}
return nil
}
Expand Down

0 comments on commit b9eb787

Please sign in to comment.