Put command access checks on the command level

Checking using `settings.Allowed` is odd. Not all commands are related
to setting configuration settings. Admin commands are coming in the
future, for which this is certainly not the case.

We now do access checks early on (during command processing), so command
handlers can be clean of access checks. If we're inside of a command
handler, the user is privileged to run it.
This commit is contained in:
Slavi Pantaleev
2022-08-29 10:25:17 +03:00
parent a62dc0df4f
commit a057654962
5 changed files with 146 additions and 103 deletions

View File

@@ -98,21 +98,3 @@ func (b *Bot) getSettings(roomID id.RoomID) (settings, error) {
func (b *Bot) setSettings(roomID id.RoomID, cfg settings) error {
return utils.UnwrapError(b.lp.GetClient().SetRoomAccountData(roomID, settingskey, cfg))
}
// Allowed checks if change is allowed
func (b *Bot) Allowed(userID id.UserID, cfg settings) bool {
if !utils.Match(userID.String(), b.allowedUsers) {
return false
}
if b.noowner {
return true
}
owner := cfg.Owner()
if owner == "" {
return true
}
return owner == userID.String()
}