From 4b556fb2d405595a31764604ce41b19a34d1e91e Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 14 Aug 2024 15:53:09 +0200 Subject: [PATCH] Add channel editing interface Signed-off-by: Knut Ahlers --- botEditor.go | 12 +- src/components/channelOverview.vue | 220 ++++++++++++++++++++++++++ src/components/channelPermissions.vue | 201 +++++++++++++++++++++++ src/langs/en.json | 23 +++ src/main.ts | 8 + src/router.ts | 11 +- 6 files changed, 466 insertions(+), 9 deletions(-) create mode 100644 src/components/channelOverview.vue create mode 100644 src/components/channelPermissions.vue diff --git a/botEditor.go b/botEditor.go index f2e210b..a6c0d44 100644 --- a/botEditor.go +++ b/botEditor.go @@ -3,21 +3,23 @@ package main import ( "fmt" "net/http" - - "github.com/pkg/errors" + "strings" ) func getAuthorizationFromRequest(r *http.Request) (string, error) { - token := r.Header.Get("Authorization") - if token == "" { + _, token, hadPrefix := strings.Cut(r.Header.Get("Authorization"), " ") + if !hadPrefix { return "", fmt.Errorf("no authorization provided") } _, user, _, _, err := editorTokenService.ValidateLoginToken(token) //nolint:dogsled // Required at other places + if err != nil { + return "", fmt.Errorf("getting authorized user: %w", err) + } if user == "" { user = "API-User" } - return user, errors.Wrap(err, "getting authorized user") + return user, nil } diff --git a/src/components/channelOverview.vue b/src/components/channelOverview.vue new file mode 100644 index 0000000..51b9a1f --- /dev/null +++ b/src/components/channelOverview.vue @@ -0,0 +1,220 @@ + + + diff --git a/src/components/channelPermissions.vue b/src/components/channelPermissions.vue new file mode 100644 index 0000000..299e1a7 --- /dev/null +++ b/src/components/channelPermissions.vue @@ -0,0 +1,201 @@ + + + diff --git a/src/langs/en.json b/src/langs/en.json index a6e931b..12c0c13 100644 --- a/src/langs/en.json +++ b/src/langs/en.json @@ -9,6 +9,29 @@ ], "heading": "Updating Bot-Authorization" }, + "channel": { + "btnAdd": "Add Channel", + "permissionsAll": "…do all of the above!", + "permissionInfoHeader": "Explanation", + "permissionIntro": "In order to access non-public information as channel-point redemptions or take actions limited to the channel owner the bot needs additional permissions. The owner of the channel needs to grant those!", + "permissionIntroBullets": [ + "Select permissions on the left side", + "Copy the URL provided below", + "Pass the URL to the channel owner and tell them to open it with their personal account logged in", + "The bot will display a message containing the updated account" + ], + "permissionStart": "For #{channel} the bot should be able to…", + "table": { + "colChannel": "Channel", + "colPermissions": "Permissions", + "textPermissions": "{granted} of {avail} granted", + "titleAllPermissions": "Bot can use all available extra features", + "titleNoPermissions": "Bot can not use features aside of chatting", + "titlePartialPermissions": "Bot can use some extra features" + }, + "toastChannelAdded": "Channel added", + "toastChannelRemoved": "Channel removed" + }, "dashboard": { "activeRaffles": { "caption": "Active", diff --git a/src/main.ts b/src/main.ts index f8e5424..d7ef905 100644 --- a/src/main.ts +++ b/src/main.ts @@ -114,6 +114,14 @@ const app = createApp({ parseResponseFromJSON(resp: Response): Promise { this.check403(resp) + + if (resp.status === 204) { + // We can't expect content here + return new Promise(resolve => { + resolve({}) + }) + } + return resp.json() }, diff --git a/src/router.ts b/src/router.ts index 13641c8..e991797 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,6 +1,8 @@ import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router' import BothAuth from './components/botauth.vue' +import ChannelOverview from './components/channelOverview.vue' +import ChannelPermissions from './components/channelPermissions.vue' import Dashboard from './components/dashboard.vue' const routes = [ @@ -8,23 +10,24 @@ const routes = [ // General settings { component: BothAuth, name: 'botAuth', path: '/bot-auth' }, - { component: {}, name: 'channels', path: '/channels' }, + { component: ChannelOverview, name: 'channels', path: '/channels' }, + { component: ChannelPermissions, name: 'channelPermissions', path: '/channels/:channel/permissions', props: true }, { component: {}, name: 'editors', path: '/editors' }, { component: {}, name: 'tokens', path: '/tokens' }, // Auto-Messages { component: {}, name: 'autoMessagesList', path: '/auto-messages' }, - { component: {}, name: 'autoMessageEdit', path: '/auto-messages/edit/{id}' }, + { component: {}, name: 'autoMessageEdit', path: '/auto-messages/edit/:id' }, { component: {}, name: 'autoMessageNew', path: '/auto-messages/new' }, // Rules { component: {}, name: 'rulesList', path: '/rules' }, - { component: {}, name: 'rulesEdit', path: '/rules/edit/{id}' }, + { component: {}, name: 'rulesEdit', path: '/rules/edit/:id' }, { component: {}, name: 'rulesNew', path: '/rules/new' }, // Raffles { component: {}, name: 'rafflesList', path: '/raffles' }, - { component: {}, name: 'rafflesEdit', path: '/raffles/edit/{id}' }, + { component: {}, name: 'rafflesEdit', path: '/raffles/edit/:id' }, { component: {}, name: 'rafflesNew', path: '/raffles/new' }, ] as RouteRecordRaw[]