Skip to content

Commit

Permalink
Merge branch 'master' into fix-oauth-refresh-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmister committed Jul 28, 2022
2 parents c865594 + 38cd3c1 commit 640ac12
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mainConfiguration: https://github.com/mattermost/mattermost-gitpod-config
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ifneq ($(wildcard $(ASSETS_DIR)/.),)
cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/
endif
ifneq ($(HAS_PUBLIC),)
cp -r public/ dist/$(PLUGIN_ID)/
cp -r public/ dist/$(PLUGIN_ID)/public/
endif
ifneq ($(HAS_SERVER),)
mkdir -p dist/$(PLUGIN_ID)/server/dist;
Expand Down
2 changes: 1 addition & 1 deletion build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func findManifest() (*model.Manifest, error) {
// we don't want to accidentally clobber anything we won't preserve.
var manifest model.Manifest
decoder := json.NewDecoder(manifestFile)
decoder.DisallowUnknownFields()
// decoder.DisallowUnknownFields() // Commented out until circleci image is updated: https://github.com/mattermost/mattermost-plugin-zoom/pull/269#discussion_r927075701
if err = decoder.Decode(&manifest); err != nil {
return nil, errors.Wrap(err, "failed to parse manifest")
}
Expand Down
9 changes: 6 additions & 3 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"type": "bool",
"help_text": "When true, OAuth will be used as the authentication means with Zoom. \n When false, JWT will be used as the authentication means with Zoom. \n If you're currently using a JWT Zoom application and switch to OAuth, all users will need to connect their Zoom account using OAuth the next time they try to start a meeting. [More information](https://mattermost.gitbook.io/plugin-zoom/installation/zoom-configuration).",
"placeholder": "",
"default": false
"default": true,
"hosting": "on-prem"
},
{
"key": "AccountLevelApp",
Expand Down Expand Up @@ -88,15 +89,17 @@
"type": "text",
"help_text": "The API key generated by Zoom, used to create meetings and pull user data.",
"placeholder": "",
"default": null
"default": null,
"hosting": "on-prem"
},
{
"key": "APISecret",
"display_name": "API Secret:",
"type": "text",
"help_text": "The API secret generated by Zoom for your API key.",
"placeholder": "",
"default": null
"default": null,
"hosting": "on-prem"
},
{
"key": "WebhookSecret",
Expand Down
Binary file added public/app-bar-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (p *Plugin) executeCommand(c *plugin.Context, args *model.CommandArgs) (str
}

func (p *Plugin) canConnect(user *model.User) bool {
return p.configuration.EnableOAuth && // we are not on JWT
return p.OAuthEnabled() && // we are not on JWT
(!p.configuration.AccountLevelApp || // we are on user managed app
user.IsSystemAdmin()) // admins can connect Account level apps
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func (p *Plugin) runHelpCommand(user *model.User) (string, error) {
// getAutocompleteData retrieves auto-complete data for the "/zoom" command
func (p *Plugin) getAutocompleteData() *model.AutocompleteData {
available := "start, help"
if p.configuration.EnableOAuth && !p.configuration.AccountLevelApp {
if p.OAuthEnabled() && !p.configuration.AccountLevelApp {
available = "start, connect, disconnect, help"
}
zoom := model.NewAutocompleteData("zoom", "[command]", fmt.Sprintf("Available commands: %s", available))
Expand All @@ -241,7 +241,7 @@ func (p *Plugin) getAutocompleteData() *model.AutocompleteData {
zoom.AddCommand(start)

// no point in showing the 'disconnect' option if OAuth is not enabled
if p.configuration.EnableOAuth && !p.configuration.AccountLevelApp {
if p.OAuthEnabled() && !p.configuration.AccountLevelApp {
connect := model.NewAutocompleteData("connect", "", "Connect to Zoom")
disconnect := model.NewAutocompleteData("disconnect", "", "Disonnects from Zoom")
zoom.AddCommand(connect)
Expand Down
8 changes: 3 additions & 5 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ func (c *configuration) Clone() *configuration {
}

// IsValid checks if all needed fields are set.
func (c *configuration) IsValid() error {
func (c *configuration) IsValid(isCloud bool) error {
switch {
case !c.EnableOAuth:
case !c.EnableOAuth && !isCloud: // JWT for on-prem
switch {
case len(c.APIKey) == 0:
return errors.New("please configure APIKey")

case len(c.APISecret) == 0:
return errors.New("please configure APISecret")
}
case c.EnableOAuth:
case c.EnableOAuth || isCloud: // OAuth for either platform
switch {
case len(c.OAuthClientSecret) == 0:
return errors.New("please configure OAuthClientSecret")
Expand All @@ -72,8 +72,6 @@ func (c *configuration) IsValid() error {
case len(c.EncryptionKey) == 0:
return errors.New("please generate EncryptionKey from Zoom plugin settings")
}
default:
return errors.New("please select either OAuth or Password based authentication")
}

if len(c.WebhookSecret) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type startMeetingRequest struct {

func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
config := p.getConfiguration()
if err := config.IsValid(); err != nil {
if err := config.IsValid(p.isCloudLicense()); err != nil {
http.Error(w, "This plugin is not configured.", http.StatusNotImplemented)
return
}
Expand Down
18 changes: 16 additions & 2 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *Plugin) OnActivate() error {
p.client = pluginapi.NewClient(p.API, p.Driver)

config := p.getConfiguration()
if err := config.IsValid(); err != nil {
if err := config.IsValid(p.isCloudLicense()); err != nil {
return err
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (p *Plugin) getActiveClient(user *model.User) (zoom.Client, string, error)
config := p.getConfiguration()

// JWT
if !config.EnableOAuth {
if !p.OAuthEnabled() {
return p.jwtClient, "", nil
}

Expand Down Expand Up @@ -257,3 +257,17 @@ func (p *Plugin) UpdateZoomOAuthUserInfo(userID string, info *zoom.OAuthUserInfo

return nil
}

func (p *Plugin) isCloudLicense() bool {
license := p.API.GetLicense()
return license != nil && *license.Features.Cloud
}

func (p *Plugin) OAuthEnabled() bool {
config := p.getConfiguration()
if config.EnableOAuth {
return true
}

return p.isCloudLicense()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {makeStyleFromTheme} from 'mattermost-redux/utils/theme_utils';

import {Svgs} from '../../constants';

export default class Icon extends React.PureComponent {
export default class ChannelHeaderIcon extends React.PureComponent {
static propTypes = {
useSVG: PropTypes.bool.isRequired,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {connect} from 'react-redux';
import {getServerVersion} from 'mattermost-redux/selectors/entities/general';
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';

import Icon from './icon.jsx';
import ChannelHeaderIcon from './channel-header-icon';

function mapStateToProps(state, ownProps) {
return {
Expand All @@ -15,4 +15,4 @@ function mapStateToProps(state, ownProps) {
};
}

export default connect(mapStateToProps)(Icon);
export default connect(mapStateToProps)(ChannelHeaderIcon);
35 changes: 16 additions & 19 deletions webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,40 @@

import React from 'react';

import {getConfig} from 'mattermost-redux/selectors/entities/general';

import {id as pluginId} from './manifest';

import Icon from './components/icon';
import ChannelHeaderIcon from './components/channel-header-icon';
import PostTypeZoom from './components/post_type_zoom';
import {startMeeting} from './actions';
import Client from './client';
import {getPluginURL, getServerRoute} from './selectors';

class Plugin {
// eslint-disable-next-line no-unused-vars
initialize(registry, store) {
registry.registerChannelHeaderButtonAction(
<Icon/>,
<ChannelHeaderIcon/>,
(channel) => {
startMeeting(channel.id)(store.dispatch, store.getState);
},
'Start Zoom Meeting',
'Start Zoom Meeting',
);

if (registry.registerAppBarComponent) {
const iconURL = getPluginURL(store.getState()) + '/public/app-bar-icon.png';
registry.registerAppBarComponent(
iconURL,
(channel) => {
startMeeting(channel.id)(store.dispatch, store.getState);
},
'Start Zoom Meeting',
);
}

registry.registerPostTypeComponent('custom_zoom', PostTypeZoom);
Client.setServerRoute(getServerRoute(store.getState()));
}
}

window.registerPlugin(pluginId, new Plugin());

const getServerRoute = (state) => {
const config = getConfig(state);

let basePath = '';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;

if (basePath && basePath[basePath.length - 1] === '/') {
basePath = basePath.substr(0, basePath.length - 1);
}
}

return basePath;
};
23 changes: 23 additions & 0 deletions webapp/src/selectors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {getConfig} from 'mattermost-redux/selectors/entities/general';

import {id} from '../manifest';

export const getServerRoute = (state) => {
const config = getConfig(state);

let basePath = '';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;

if (basePath && basePath[basePath.length - 1] === '/') {
basePath = basePath.substr(0, basePath.length - 1);
}
}

return basePath;
};

export const getPluginURL = (state) => {
const siteURL = getServerRoute(state);
return siteURL + '/plugins/' + id;
};

0 comments on commit 640ac12

Please sign in to comment.