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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user