Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to disable webapp components #8

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions server/plugin/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions server/plugin/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
35 changes: 19 additions & 16 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = () => {
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down