From 2a9e006095d9e46bc6a897b2250e2232301fb3f4 Mon Sep 17 00:00:00 2001 From: Asklv <47499836+IRONICBo@users.noreply.github.com> Date: Mon, 7 Aug 2023 09:27:19 +0800 Subject: [PATCH] feat: Add platform pages. (#152) --- .gitignore | 2 + server/config.docker.yaml | 11 +- server/config.example.yaml | 11 +- server/config.yaml | 11 +- server/internal/api/platform.go | 53 +++++ server/internal/config/config.go | 21 ++ .../internal/middleware/hooks/gen_jwt_hook.go | 1 + server/internal/params/response/platform.go | 26 +++ server/internal/router/router.go | 9 + server/internal/service/slack.go | 48 +++++ web/src/api/index/platform.ts | 27 +++ web/src/api/response/platformModel.ts | 9 + web/src/constants/index.ts | 26 +++ web/src/style/reset-tdesign.less | 4 + web/src/types/interface.d.ts | 9 + .../platform/components/PlatformCard.vue | 114 +++++++++++ .../platform/components/PlatformDialog.vue | 188 ++++++++++++++++++ web/src/views/platform/index.less | 43 ++++ web/src/views/platform/index.vue | 130 +++++++++++- 19 files changed, 737 insertions(+), 6 deletions(-) create mode 100644 server/internal/api/platform.go create mode 100644 server/internal/params/response/platform.go create mode 100644 server/internal/service/slack.go create mode 100644 web/src/api/index/platform.ts create mode 100644 web/src/api/response/platformModel.ts create mode 100644 web/src/views/platform/components/PlatformCard.vue create mode 100644 web/src/views/platform/components/PlatformDialog.vue create mode 100644 web/src/views/platform/index.less diff --git a/.gitignore b/.gitignore index 727ea98..fc9a703 100644 --- a/.gitignore +++ b/.gitignore @@ -356,3 +356,5 @@ dist # config files, may contain sensitive information dist/ +# OpenKF dev config +server/config.yaml \ No newline at end of file diff --git a/server/config.docker.yaml b/server/config.docker.yaml index 8c1c0c8..fb9e4f8 100644 --- a/server/config.docker.yaml +++ b/server/config.docker.yaml @@ -64,4 +64,13 @@ openim: secret: openkf ip: 127.0.0.1 api_port: 10002 - platform_id: 5 # web \ No newline at end of file + platform_id: 5 # web + +slack: + bot_token: + app_token: + app_id: # need to give string, like '1821.42' + client_id: + client_secret: + signing_secret: + verification_token: \ No newline at end of file diff --git a/server/config.example.yaml b/server/config.example.yaml index ec3cda0..eb1fcab 100644 --- a/server/config.example.yaml +++ b/server/config.example.yaml @@ -64,4 +64,13 @@ openim: secret: openkf ip: 127.0.0.1 api_port: 10002 - platform_id: 5 # web \ No newline at end of file + platform_id: 5 # web + +slack: + bot_token: + app_token: + app_id: # need to give string, like '1821.42' + client_id: + client_secret: + signing_secret: + verification_token: \ No newline at end of file diff --git a/server/config.yaml b/server/config.yaml index ec3cda0..eb1fcab 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -64,4 +64,13 @@ openim: secret: openkf ip: 127.0.0.1 api_port: 10002 - platform_id: 5 # web \ No newline at end of file + platform_id: 5 # web + +slack: + bot_token: + app_token: + app_id: # need to give string, like '1821.42' + client_id: + client_secret: + signing_secret: + verification_token: \ No newline at end of file diff --git a/server/internal/api/platform.go b/server/internal/api/platform.go new file mode 100644 index 0000000..0672446 --- /dev/null +++ b/server/internal/api/platform.go @@ -0,0 +1,53 @@ +// Copyright © 2023 OpenIM open source community. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package api + +import ( + "github.com/gin-gonic/gin" + + "github.com/OpenIMSDK/OpenKF/server/internal/common" + "github.com/OpenIMSDK/OpenKF/server/internal/common/response" + "github.com/OpenIMSDK/OpenKF/server/internal/service" + "github.com/OpenIMSDK/OpenKF/server/internal/utils" +) + +// SlackConfig +// @Tags platform +// @Summary SlackConfig +// @Description Get slack config +// @Produce application/json +// @Security ApiKeyAuth +// @Success 200 {object} response.Response{msg=string} "Success" +// @Router /api/v1/platform/slack/config [get]. +func SlackConfig(c *gin.Context) { + // TODO: Check user role. + if _, err := utils.GetUserUUID(c); err != nil { + response.FailWithCode(common.UNAUTHORIZED, c) + + return + } + + svc := service.NewSlackService(c) + // TODO: Add a table and save config to db. + // Now it only read from config file. + resp, err := svc.GetSlackConfig() + if err != nil { + response.FailWithCode(common.KF_RECORD_NOT_FOUND, c) + + return + } + + response.SuccessWithData(resp, c) +} diff --git a/server/internal/config/config.go b/server/internal/config/config.go index 268f915..bc4346e 100644 --- a/server/internal/config/config.go +++ b/server/internal/config/config.go @@ -78,6 +78,15 @@ func ConfigInit(configPath string) { ApiPort: GetIntOrDefault("openim.api_port", 10002), PlatformID: GetIntOrDefault("openim.platform_id", 5), }, + Slack: Slack{ + BotToken: GetString("slack.bot_token"), + AppToken: GetString("slack.app_token"), + AppID: GetString("slack.app_id"), + ClientID: GetString("slack.client_id"), + ClientSecret: GetString("slack.client_secret"), + SigningSecret: GetString("slack.signing_secret"), + VerificationToken: GetString("slack.verification_token"), + }, } } @@ -90,6 +99,7 @@ type config struct { Minio Minio Email Email OpenIM OpenIM + Slack Slack } // App config. @@ -161,3 +171,14 @@ type OpenIM struct { ApiPort int `mapstructure:"api_port"` PlatformID int `mapstructure:"platform_id"` } + +// Slack Bot config. +type Slack struct { + BotToken string `mapstructure:"bot_token"` + AppToken string `mapstructure:"app_token"` + AppID string `mapstructure:"app_id"` + ClientID string `mapstructure:"client_id"` + ClientSecret string `mapstructure:"client_secret"` + SigningSecret string `mapstructure:"signing_secret"` + VerificationToken string `mapstructure:"verification_token"` +} diff --git a/server/internal/middleware/hooks/gen_jwt_hook.go b/server/internal/middleware/hooks/gen_jwt_hook.go index fb38545..42c91cd 100644 --- a/server/internal/middleware/hooks/gen_jwt_hook.go +++ b/server/internal/middleware/hooks/gen_jwt_hook.go @@ -43,6 +43,7 @@ func (h *JWT) Patterns() []string { "/api/v1/user/*", "/api/v1/community/*", "/api/v1/admin/*", + "/api/v1/platform/*", } } diff --git a/server/internal/params/response/platform.go b/server/internal/params/response/platform.go new file mode 100644 index 0000000..2777063 --- /dev/null +++ b/server/internal/params/response/platform.go @@ -0,0 +1,26 @@ +// Copyright © 2023 OpenIM open source community. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package responseparams + +// SlackConfigResponse slack config response. +type SlackConfigResponse struct { + BotToken string `json:"bot_token"` + AppToken string `json:"app_token"` + AppID string `json:"app_id"` + ClientID string `json:"client_id"` + ClientSecret string `json:"client_secret"` + SigningSecret string `json:"signing_secret"` + VerificationToken string `json:"verification_token"` +} diff --git a/server/internal/router/router.go b/server/internal/router/router.go index e4dccd3..5931bf7 100644 --- a/server/internal/router/router.go +++ b/server/internal/router/router.go @@ -117,6 +117,15 @@ func InitRouter() *gin.Engine { command.POST("/callbackOfflinePushCommand", api.OfflinePush) command.POST("/callbackOnlinePushCommand", api.OnlinePush) } + + // Platform callback api + platform := apiv1.Group("/platform") + { + slack := platform.Group("/slack") + { + slack.GET("/config", api.SlackConfig) + } + } } return r diff --git a/server/internal/service/slack.go b/server/internal/service/slack.go new file mode 100644 index 0000000..1ac56d2 --- /dev/null +++ b/server/internal/service/slack.go @@ -0,0 +1,48 @@ +// Copyright © 2023 OpenIM open source community. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package service + +import ( + "github.com/OpenIMSDK/OpenKF/server/internal/config" + responseparams "github.com/OpenIMSDK/OpenKF/server/internal/params/response" + "github.com/gin-gonic/gin" +) + +// SlackService bot service. +type SlackService struct { + Service +} + +// NewSlackService return new service with gin context. +func NewSlackService(c *gin.Context) *SlackService { + return &SlackService{ + Service: Service{ + ctx: c, + }, + } +} + +// GetSlackConfig get slack config. +func (svc *SlackService) GetSlackConfig() (*responseparams.SlackConfigResponse, error) { + return &responseparams.SlackConfigResponse{ + BotToken: config.Config.Slack.BotToken, + AppToken: config.Config.Slack.AppToken, + AppID: config.Config.Slack.AppID, + ClientID: config.Config.Slack.ClientID, + ClientSecret: config.Config.Slack.ClientSecret, + SigningSecret: config.Config.Slack.SigningSecret, + VerificationToken: config.Config.Slack.VerificationToken, + }, nil +} diff --git a/web/src/api/index/platform.ts b/web/src/api/index/platform.ts new file mode 100644 index 0000000..fd2720e --- /dev/null +++ b/web/src/api/index/platform.ts @@ -0,0 +1,27 @@ +// Copyright © 2023 OpenIM open source community. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { request } from '@/utils/request'; +import { GetSlackConfigResponse } from '@/api/response/platformModel'; + +const API = { + SlackConfig: '/platform/slack/config', +}; + +// get slack info +export function getSlackConfig() { + return request.get({ + url: API.SlackConfig, + }); +} diff --git a/web/src/api/response/platformModel.ts b/web/src/api/response/platformModel.ts new file mode 100644 index 0000000..53e04c6 --- /dev/null +++ b/web/src/api/response/platformModel.ts @@ -0,0 +1,9 @@ +export interface GetSlackConfigResponse { + bot_token: string, + app_token: string, + app_id: string, + client_id: string, + client_secret: string, + signing_secret: string, + verification_token: string, +} \ No newline at end of file diff --git a/web/src/constants/index.ts b/web/src/constants/index.ts index cbdb799..12e6ff1 100644 --- a/web/src/constants/index.ts +++ b/web/src/constants/index.ts @@ -26,3 +26,29 @@ export enum ContentTypeEnum { FormURLEncoded = 'application/x-www-form-urlencoded;charset=UTF-8', FormData = 'multipart/form-data;charset=UTF-8', } + +// Platform type +export enum PlatformType { + Slack = 'Slack', + Web = 'Web', +} + +// Define support platforms +export const PLATFORMS = [ + { + order: 1, + avatar: 'https://github.com/OpenIMSDK/OpenKF/assets/47499836/73b94766-9968-4b66-b0b6-cc7a6ebfda69', + name: PlatformType.Slack, + description: 'Slack is a new way to communicate with your customer. It\'s faster, better organized, and more secure than email.', + is_enable: true, + tags: ['Slack', 'LLM'], + }, + { + order: 2, + avatar: 'https://github.com/OpenIMSDK/OpenKF/assets/47499836/13292e53-68df-46f8-948c-1296ba3bf330', + name: PlatformType.Web, + description: 'Web is a basic way to communicate with your customer. It\'s light and easy to intergrate with your products.', + is_enable: false, + tags: ['Web', 'AI'], + } +]; \ No newline at end of file diff --git a/web/src/style/reset-tdesign.less b/web/src/style/reset-tdesign.less index c44599f..2a608c3 100644 --- a/web/src/style/reset-tdesign.less +++ b/web/src/style/reset-tdesign.less @@ -1,4 +1,8 @@ // reset for openkf +.t-menu__logo { + min-height: var(--td-comp-size-xxxxxl); +} + .kf-config-input { .t-input { border-radius: var(--td-radius-large); diff --git a/web/src/types/interface.d.ts b/web/src/types/interface.d.ts index 5cd3d3b..8fb17a6 100644 --- a/web/src/types/interface.d.ts +++ b/web/src/types/interface.d.ts @@ -22,3 +22,12 @@ export interface MenuRoute { name: string; icon: string; } + +export interface Platform { + order: number; + avatar: string; + name: string; + description: string; + is_enable: boolean; + tags: string[]; +} diff --git a/web/src/views/platform/components/PlatformCard.vue b/web/src/views/platform/components/PlatformCard.vue new file mode 100644 index 0000000..addf778 --- /dev/null +++ b/web/src/views/platform/components/PlatformCard.vue @@ -0,0 +1,114 @@ + + + + + + + + \ No newline at end of file diff --git a/web/src/views/platform/components/PlatformDialog.vue b/web/src/views/platform/components/PlatformDialog.vue new file mode 100644 index 0000000..fbf3879 --- /dev/null +++ b/web/src/views/platform/components/PlatformDialog.vue @@ -0,0 +1,188 @@ + + + + + + + diff --git a/web/src/views/platform/index.less b/web/src/views/platform/index.less new file mode 100644 index 0000000..c415405 --- /dev/null +++ b/web/src/views/platform/index.less @@ -0,0 +1,43 @@ +.light { + &.platform-wrapper { + background-color: var(--td-bg-color-page); + } +} + +.dark { + &.platform-wrapper { + background-color: var(--td-bg-color-page); + } +} + +.platform-wrapper { + min-height: 100vh; + display: flex; + flex-direction: column; + background-size: cover; + background-position: 100%; + position: relative; +} + +.platform-header { + position: relative; + padding: var(--td-comp-paddingTB-l) var(--td-comp-paddingLR-xl); + border-bottom: 1px solid var(--td-component-border); + background-color: var(--td-font-white-1); + height: var(--td-comp-size-xxxxxl); + + .welcome { + font-size: var(--td-font-size-title-large); + font-weight: 700; + } + .sub-title { + font-size: var(--td-font-size-body-small); + font-weight: 400; + } +} + +.t-list-wrapper { + border: 1px solid var(--td-component-border); + border-radius: var(--td-radius-large); + margin-bottom: var(--td-comp-margin-l); +} \ No newline at end of file diff --git a/web/src/views/platform/index.vue b/web/src/views/platform/index.vue index e47c182..34efa6d 100644 --- a/web/src/views/platform/index.vue +++ b/web/src/views/platform/index.vue @@ -1,7 +1,131 @@ - + - + + +