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.
38 lines
706 B
Go
38 lines
706 B
Go
package bot
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"maunium.net/go/mautrix/id"
|
|
|
|
"gitlab.com/etke.cc/postmoogle/utils"
|
|
)
|
|
|
|
type accessCheckerFunc func(id.UserID, id.RoomID) (bool, error)
|
|
|
|
func (b *Bot) allowAnyone(actorID id.UserID, targetRoomID id.RoomID) (bool, error) {
|
|
return true, nil
|
|
}
|
|
|
|
func (b *Bot) allowOwner(actorID id.UserID, targetRoomID id.RoomID) (bool, error) {
|
|
if !utils.Match(actorID.String(), b.allowedUsers) {
|
|
return false, nil
|
|
}
|
|
|
|
if b.noowner {
|
|
return true, nil
|
|
}
|
|
|
|
cfg, err := b.getSettings(targetRoomID)
|
|
if err != nil {
|
|
return false, fmt.Errorf("failed to retrieve settings: %v", err)
|
|
}
|
|
|
|
owner := cfg.Owner()
|
|
if owner == "" {
|
|
return true, nil
|
|
}
|
|
|
|
return owner == actorID.String(), nil
|
|
}
|