From 9bb789472e7d76e9a95dbe521ddd20a72f4ccd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8F=D0=BD=20=D0=9C=D0=B8=D0=BD=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Tue, 11 Feb 2020 15:14:01 +0000 Subject: [PATCH] Uses correct scopes for google API based on config.js values. (#5066) * Uses correct scopes for google API based on config.js values. * Lower the number of parameters that we pass around. * Fixes googleAPIState state checking. --- react/features/calendar-sync/actions.web.js | 3 +-- react/features/calendar-sync/web/googleCalendar.js | 7 +------ react/features/google-api/actions.js | 12 +++++++++--- react/features/google-api/googleApi.web.js | 13 ++++++++----- .../LiveStream/web/StartLiveStreamDialog.js | 3 +-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/react/features/calendar-sync/actions.web.js b/react/features/calendar-sync/actions.web.js index 64339f7d8..61107df02 100644 --- a/react/features/calendar-sync/actions.web.js +++ b/react/features/calendar-sync/actions.web.js @@ -46,8 +46,7 @@ export function bootstrapCalendarIntegration(): Function { return Promise.resolve() .then(() => { if (googleApiApplicationClientID) { - return dispatch( - loadGoogleAPI(googleApiApplicationClientID)); + return dispatch(loadGoogleAPI()); } }) .then(() => { diff --git a/react/features/calendar-sync/web/googleCalendar.js b/react/features/calendar-sync/web/googleCalendar.js index 11074e2c8..dfee6ad0e 100644 --- a/react/features/calendar-sync/web/googleCalendar.js +++ b/react/features/calendar-sync/web/googleCalendar.js @@ -43,12 +43,7 @@ export const googleCalendarApi = { * @returns {function(Dispatch, Function): Promise} */ load() { - return (dispatch: Dispatch, getState: Function) => { - const { googleApiApplicationClientID } - = getState()['features/base/config']; - - return dispatch(loadGoogleAPI(googleApiApplicationClientID)); - }; + return (dispatch: Dispatch) => dispatch(loadGoogleAPI()); }, /** diff --git a/react/features/google-api/actions.js b/react/features/google-api/actions.js index 468975411..cc9d371ab 100644 --- a/react/features/google-api/actions.js +++ b/react/features/google-api/actions.js @@ -29,16 +29,22 @@ export function getCalendarEntries( /** * Loads Google API. * - * @param {string} clientId - The client ID to be used with the API library. * @returns {Function} */ -export function loadGoogleAPI(clientId: string) { +export function loadGoogleAPI() { return (dispatch: Dispatch, getState: Function) => googleApi.get() .then(() => { + const { + liveStreamingEnabled, + enableCalendarIntegration, + googleApiApplicationClientID + } = getState()['features/base/config']; + if (getState()['features/google-api'].googleAPIState === GOOGLE_API_STATES.NEEDS_LOADING) { - return googleApi.initializeClient(clientId); + return googleApi.initializeClient( + googleApiApplicationClientID, liveStreamingEnabled, enableCalendarIntegration); } return Promise.resolve(); diff --git a/react/features/google-api/googleApi.web.js b/react/features/google-api/googleApi.web.js index a05b90fba..f3f147075 100644 --- a/react/features/google-api/googleApi.web.js +++ b/react/features/google-api/googleApi.web.js @@ -61,11 +61,17 @@ const googleApi = { * making Google API requests. * * @param {string} clientId - The client ID to be used with the API library. + * @param {boolean} enableYoutube - Whether youtube scope is enabled. + * @param {boolean} enableCalendar - Whether calendar scope is enabled. * @returns {Promise} */ - initializeClient(clientId) { + initializeClient(clientId, enableYoutube, enableCalendar) { return this.get() .then(api => new Promise((resolve, reject) => { + const scope + = `${enableYoutube ? GOOGLE_SCOPE_YOUTUBE : ''} ${enableCalendar ? GOOGLE_SCOPE_CALENDAR : ''}` + .trim(); + // setTimeout is used as a workaround for api.client.init not // resolving consistently when the Google API Client Library is // loaded asynchronously. See: @@ -74,10 +80,7 @@ const googleApi = { api.client.init({ clientId, discoveryDocs: DISCOVERY_DOCS, - scope: [ - GOOGLE_SCOPE_CALENDAR, - GOOGLE_SCOPE_YOUTUBE - ].join(' ') + scope }) .then(resolve) .catch(reject); diff --git a/react/features/recording/components/LiveStream/web/StartLiveStreamDialog.js b/react/features/recording/components/LiveStream/web/StartLiveStreamDialog.js index 51dee07bf..d3ce0e0eb 100644 --- a/react/features/recording/components/LiveStream/web/StartLiveStreamDialog.js +++ b/react/features/recording/components/LiveStream/web/StartLiveStreamDialog.js @@ -121,8 +121,7 @@ class StartLiveStreamDialog * @returns {void} */ _onInitializeGoogleApi() { - this.props.dispatch( - loadGoogleAPI(this.props._googleApiApplicationClientID)) + this.props.dispatch(loadGoogleAPI()) .catch(response => this._parseErrorFromResponse(response)); }