Skip to content

Commit

Permalink
More verbose reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Jul 22, 2021
1 parent ae88543 commit 0378db3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions eventauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ func (m *membershipAllower) membershipAllowedSelf() error { // nolint: gocyclo
}
if m.newMember.Membership == Knock {
if m.joinRule.JoinRule != Knock {
return m.membershipFailed()
return errorf("the join rule %q does not allow knocking", 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 +1028,13 @@ 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("knocking is not supported in room version %q", 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("the knocking user is already joined/invited/banned")
default:
// A non-joined, non-invited, non-banned user is allowed to knock.
return nil
Expand Down Expand Up @@ -1122,11 +1122,14 @@ 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("the join rule %q does not allow knocking", 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("knocking is not supported in room version %q", m.roomVersion)
}
return nil
}
Expand Down

0 comments on commit 0378db3

Please sign in to comment.