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.
This commit is contained in:
Дамян Минков 2020-02-11 15:14:01 +00:00 committed by GitHub
parent 06fa175a6c
commit 9bb789472e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 18 deletions

View File

@ -46,8 +46,7 @@ export function bootstrapCalendarIntegration(): Function {
return Promise.resolve()
.then(() => {
if (googleApiApplicationClientID) {
return dispatch(
loadGoogleAPI(googleApiApplicationClientID));
return dispatch(loadGoogleAPI());
}
})
.then(() => {

View File

@ -43,12 +43,7 @@ export const googleCalendarApi = {
* @returns {function(Dispatch<any>, Function): Promise<void>}
*/
load() {
return (dispatch: Dispatch<any>, getState: Function) => {
const { googleApiApplicationClientID }
= getState()['features/base/config'];
return dispatch(loadGoogleAPI(googleApiApplicationClientID));
};
return (dispatch: Dispatch<any>) => dispatch(loadGoogleAPI());
},
/**

View File

@ -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<any>, 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();

View File

@ -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);

View File

@ -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));
}