Now that we use Match() in allowAdmin() as well, it's awkward to have it return `true` when called with an empty admin list. No admins defined was taken to mean "everyone is an admin". We can either have a `len(users) == 0` check in `allowAdmin` which rejects the request, or we can change `Match()` so that it doesn't return positive responses when called with an empty list. Doing the latter sounds better. It's more natural that matching against an empty list will yield "no match".
43 lines
806 B
Go
43 lines
806 B
Go
package bot
|
|
|
|
import (
|
|
"context"
|
|
|
|
"maunium.net/go/mautrix/id"
|
|
|
|
"gitlab.com/etke.cc/postmoogle/utils"
|
|
)
|
|
|
|
func (b *Bot) allowAnyone(actorID id.UserID, targetRoomID id.RoomID) bool {
|
|
return true
|
|
}
|
|
|
|
func (b *Bot) allowOwner(actorID id.UserID, targetRoomID id.RoomID) bool {
|
|
if len(b.allowedUsers) != 0 {
|
|
if !utils.Match(actorID.String(), b.allowedUsers) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
if b.noowner {
|
|
return true
|
|
}
|
|
|
|
cfg, err := b.getSettings(targetRoomID)
|
|
if err != nil {
|
|
b.Error(context.Background(), targetRoomID, "failed to retrieve settings: %v", err)
|
|
return false
|
|
}
|
|
|
|
owner := cfg.Owner()
|
|
if owner == "" {
|
|
return true
|
|
}
|
|
|
|
return owner == actorID.String()
|
|
}
|
|
|
|
func (b *Bot) allowAdmin(actorID id.UserID, targetRoomID id.RoomID) bool {
|
|
return utils.Match(actorID.String(), b.allowedAdmins)
|
|
}
|