diff --git a/configEditor_general.go b/configEditor_general.go index a76abd0..4b618e0 100644 --- a/configEditor_general.go +++ b/configEditor_general.go @@ -186,12 +186,15 @@ func configEditorHandleGeneralDeleteAuthToken(w http.ResponseWriter, r *http.Req } func configEditorHandleGeneralGet(w http.ResponseWriter, r *http.Request) { - var ( - channelScopes = make(map[string][]string) - err error - ) + channelScopes := make(map[string][]string) - 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 { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/internal/service/access/access.go b/internal/service/access/access.go index a1cc9ca..84274c1 100644 --- a/internal/service/access/access.go +++ b/internal/service/access/access.go @@ -195,6 +195,20 @@ func (s Service) HasPermissionsForChannel(channel string, scopes ...string) (boo 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 { return errors.Wrap( s.db.DB().Delete(&extendedPermission{}, "channel = ?", channel).Error,