[core] Fix: List all configured channel permissions

in order to fix bot permission check when bot has not joined own channel

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-02-08 19:10:26 +01:00
parent 7e56cf52c7
commit 7420cf5007
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
2 changed files with 22 additions and 5 deletions

View file

@ -186,12 +186,15 @@ func configEditorHandleGeneralDeleteAuthToken(w http.ResponseWriter, r *http.Req
} }
func configEditorHandleGeneralGet(w http.ResponseWriter, r *http.Request) { func configEditorHandleGeneralGet(w http.ResponseWriter, r *http.Request) {
var ( channelScopes := make(map[string][]string)
channelScopes = make(map[string][]string)
err error
)
for _, ch := range config.Channels { channels, err := accessService.ListPermittedChannels()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, ch := range channels {
if channelScopes[ch], err = accessService.GetChannelPermissions(ch); err != nil { if channelScopes[ch], err = accessService.GetChannelPermissions(ch); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return

View file

@ -195,6 +195,20 @@ func (s Service) HasPermissionsForChannel(channel string, scopes ...string) (boo
return true, nil return true, nil
} }
func (s Service) ListPermittedChannels() ([]string, error) {
var perms []extendedPermission
if err := s.db.DB().Find(&perms).Error; err != nil {
return nil, errors.Wrap(err, "listing permissions")
}
var out []string
for _, perm := range perms {
out = append(out, perm.Channel)
}
return out, nil
}
func (s Service) RemoveExendedTwitchCredentials(channel string) error { func (s Service) RemoveExendedTwitchCredentials(channel string) error {
return errors.Wrap( return errors.Wrap(
s.db.DB().Delete(&extendedPermission{}, "channel = ?", channel).Error, s.db.DB().Delete(&extendedPermission{}, "channel = ?", channel).Error,