diff --git a/plugin.json b/plugin.json index 90576352c..2c35428cd 100644 --- a/plugin.json +++ b/plugin.json @@ -21,6 +21,13 @@ "settings_schema": { "header": "The GitHub plugin for Mattermost allows users to Subscribe to notifications, stay up-to-date with reviews, see the status of your pull requests at a glance, and other common GitHub actions - directly from Mattermost. \n \n Instructions for setup are [available here](https://www.mattermost.com/pl/default-github-plugin#configuration)", "settings": [ + { + "key": "EnableUI", + "display_name": "Enable UI", + "type": "bool", + "help_text": "", + "default": true + }, { "key": "GitHubOAuthClientID", "display_name": "GitHub OAuth Client ID", diff --git a/server/plugin/api.go b/server/plugin/api.go index ebc300823..8cf7fd8ae 100644 --- a/server/plugin/api.go +++ b/server/plugin/api.go @@ -108,6 +108,7 @@ func (p *Plugin) initializeAPI() { oauthRouter.HandleFunc("/connect", p.extractUserMiddleWare(p.connectUserToGitHub, ResponseTypePlain)).Methods(http.MethodGet) oauthRouter.HandleFunc("/complete", p.extractUserMiddleWare(p.completeConnectUserToGitHub, ResponseTypePlain)).Methods(http.MethodGet) + apiRouter.HandleFunc("/settingsinfo", p.getSettingsInfo).Methods(http.MethodGet) apiRouter.HandleFunc("/connected", p.getConnected).Methods(http.MethodGet) apiRouter.HandleFunc("/todo", p.extractUserMiddleWare(p.postToDo, ResponseTypeJSON)).Methods(http.MethodPost) apiRouter.HandleFunc("/reviews", p.extractUserMiddleWare(p.getReviews, ResponseTypePlain)).Methods(http.MethodGet) @@ -193,6 +194,16 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req p.router.ServeHTTP(w, r) } +func (p *Plugin) getSettingsInfo(w http.ResponseWriter, _ *http.Request) { + resp := struct { + UIEnabled bool `json:"ui_enabled"` + }{ + UIEnabled: p.getConfiguration().EnableUI, + } + + p.writeJSON(w, resp) +} + func (p *Plugin) connectUserToGitHub(w http.ResponseWriter, r *http.Request, userID string) { privateAllowed := false pValBool, _ := strconv.ParseBool(r.URL.Query().Get("private")) diff --git a/server/plugin/configuration.go b/server/plugin/configuration.go index 8384648ab..e7403ca67 100644 --- a/server/plugin/configuration.go +++ b/server/plugin/configuration.go @@ -18,6 +18,7 @@ import ( // If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep // copy appropriate for your types. type Configuration struct { + EnableUI bool GitHubOrg string GitHubOAuthClientID string GitHubOAuthClientSecret string diff --git a/server/plugin/manifest.go b/server/plugin/manifest.go index f58ebafa4..8fe479645 100644 --- a/server/plugin/manifest.go +++ b/server/plugin/manifest.go @@ -36,6 +36,14 @@ const manifestStr = ` "header": "The GitHub plugin for Mattermost allows users to Subscribe to notifications, stay up-to-date with reviews, see the status of your pull requests at a glance, and other common GitHub actions - directly from Mattermost. \n \n Instructions for setup are [available here](https://www.mattermost.com/pl/default-github-plugin#configuration)", "footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost/mattermost-plugin-github).", "settings": [ + { + "key": "EnableUI", + "display_name": "Enable UI", + "type": "bool", + "help_text": "", + "placeholder": "", + "default": true + }, { "key": "GitHubOAuthClientID", "display_name": "GitHub OAuth Client ID", diff --git a/webapp/package-lock.json b/webapp/package-lock.json index b234203e4..4d8bbdcf3 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -15412,9 +15412,9 @@ }, "dependencies": { "safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true } } diff --git a/webapp/src/actions/index.js b/webapp/src/actions/index.js index d32141fb7..170932545 100644 --- a/webapp/src/actions/index.js +++ b/webapp/src/actions/index.js @@ -6,6 +6,15 @@ import ActionTypes from '../action_types'; import {id as pluginId} from '../manifest'; +export async function getSettings() { + let data; + try { + data = await Client.getSettings(); + } catch (error) { + return {error}; + } + return {data}; +} export function getConnected(reminder = false) { return async (dispatch) => { let data; diff --git a/webapp/src/client/client.js b/webapp/src/client/client.js index ed54e14b2..774554f4e 100644 --- a/webapp/src/client/client.js +++ b/webapp/src/client/client.js @@ -9,6 +9,10 @@ export default class Client { this.url = '/plugins/github/api/v1'; } + getSettings = async () => { + return this.doGet(`${this.url}/settingsinfo`); + } + getConnected = async (reminder = false) => { return this.doGet(`${this.url}/connected?reminder=${reminder}`); } diff --git a/webapp/src/index.js b/webapp/src/index.js index 05fdc7b3d..17b9f1c46 100644 --- a/webapp/src/index.js +++ b/webapp/src/index.js @@ -11,7 +11,7 @@ import UserAttribute from './components/user_attribute'; import SidebarRight from './components/sidebar_right'; import LinkTooltip from './components/link_tooltip'; import Reducer from './reducers'; -import {getConnected, setShowRHSAction} from './actions'; +import {getConnected, setShowRHSAction, getSettings} from './actions'; import {handleConnect, handleDisconnect, handleReconnect, handleRefresh} from './websocket'; let activityFunc; @@ -22,23 +22,26 @@ class PluginClass { async initialize(registry, store) { registry.registerReducer(Reducer); + const {data: settings} = await getSettings(store.getState); + await getConnected(true)(store.dispatch, store.getState); - registry.registerLeftSidebarHeaderComponent(SidebarHeader); - registry.registerBottomTeamSidebarComponent(TeamSidebar); - registry.registerPopoverUserAttributesComponent(UserAttribute); - registry.registerRootComponent(CreateIssueModal); - registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction); - registry.registerRootComponent(AttachCommentToIssueModal); - registry.registerPostDropdownMenuComponent(AttachCommentToIssuePostMenuAction); - registry.registerLinkTooltipComponent(LinkTooltip); - - const {showRHSPlugin} = registry.registerRightHandSidebarComponent(SidebarRight, 'GitHub'); - store.dispatch(setShowRHSAction(() => store.dispatch(showRHSPlugin))); - - registry.registerWebSocketEventHandler('custom_github_connect', handleConnect(store)); - registry.registerWebSocketEventHandler('custom_github_disconnect', handleDisconnect(store)); - registry.registerWebSocketEventHandler('custom_github_refresh', handleRefresh(store)); + if (settings && settings.ui_enabled) { + registry.registerLeftSidebarHeaderComponent(SidebarHeader); + registry.registerBottomTeamSidebarComponent(TeamSidebar); + registry.registerPopoverUserAttributesComponent(UserAttribute); + registry.registerRootComponent(CreateIssueModal); + registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction); + registry.registerRootComponent(AttachCommentToIssueModal); + registry.registerPostDropdownMenuComponent(AttachCommentToIssuePostMenuAction); + registry.registerLinkTooltipComponent(LinkTooltip); + const {showRHSPlugin} = registry.registerRightHandSidebarComponent(SidebarRight, 'GitHub'); + store.dispatch(setShowRHSAction(() => store.dispatch(showRHSPlugin))); + + registry.registerWebSocketEventHandler('custom_github_connect', handleConnect(store)); + registry.registerWebSocketEventHandler('custom_github_disconnect', handleDisconnect(store)); + registry.registerWebSocketEventHandler('custom_github_refresh', handleRefresh(store)); + } registry.registerReconnectHandler(handleReconnect(store)); activityFunc = () => { diff --git a/webapp/src/manifest.ts b/webapp/src/manifest.ts index 60ddd06a5..e0485954c 100644 --- a/webapp/src/manifest.ts +++ b/webapp/src/manifest.ts @@ -26,6 +26,14 @@ const manifest = JSON.parse(` "header": "The GitHub plugin for Mattermost allows users to Subscribe to notifications, stay up-to-date with reviews, see the status of your pull requests at a glance, and other common GitHub actions - directly from Mattermost. \\n \\n Instructions for setup are [available here](https://www.mattermost.com/pl/default-github-plugin#configuration)", "footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost/mattermost-plugin-github).", "settings": [ + { + "key": "EnableUI", + "display_name": "Enable UI", + "type": "bool", + "help_text": "", + "placeholder": "", + "default": true + }, { "key": "GitHubOAuthClientID", "display_name": "GitHub OAuth Client ID",