mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-09 16:50:01 +00:00
[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:
parent
7e56cf52c7
commit
7420cf5007
2 changed files with 22 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue