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

@@ -22,6 +22,7 @@ type Bot struct {
domain string
allowedUsers []*regexp.Regexp
allowedAdmins []*regexp.Regexp
commands commandList
rooms sync.Map
log *logger.Logger
lp *linkpearl.Linkpearl
@@ -38,7 +39,7 @@ func New(
allowedUsers []*regexp.Regexp,
allowedAdmins []*regexp.Regexp,
) *Bot {
return &Bot{
b := &Bot{
noowner: noowner,
federation: federation,
prefix: prefix,
@@ -50,6 +51,10 @@ func New(
lp: lp,
mu: map[id.RoomID]*sync.Mutex{},
}
b.commands = b.buildCommandList()
return b
}
// Error message to the log and matrix room