Browse Source

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.
master
Дамян Минков 5 years ago
parent
commit
9bb789472e
No account linked to committer's email address

+ 1
- 2
react/features/calendar-sync/actions.web.js View File

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

+ 1
- 6
react/features/calendar-sync/web/googleCalendar.js View File

@@ -43,12 +43,7 @@ export const googleCalendarApi = {
43 43
      * @returns {function(Dispatch<any>, Function): Promise<void>}
44 44
      */
45 45
     load() {
46
-        return (dispatch: Dispatch<any>, getState: Function) => {
47
-            const { googleApiApplicationClientID }
48
-                = getState()['features/base/config'];
49
-
50
-            return dispatch(loadGoogleAPI(googleApiApplicationClientID));
51
-        };
46
+        return (dispatch: Dispatch<any>) => dispatch(loadGoogleAPI());
52 47
     },
53 48
 
54 49
     /**

+ 9
- 3
react/features/google-api/actions.js View File

@@ -29,16 +29,22 @@ export function getCalendarEntries(
29 29
 /**
30 30
  * Loads Google API.
31 31
  *
32
- * @param {string} clientId - The client ID to be used with the API library.
33 32
  * @returns {Function}
34 33
  */
35
-export function loadGoogleAPI(clientId: string) {
34
+export function loadGoogleAPI() {
36 35
     return (dispatch: Dispatch<any>, getState: Function) =>
37 36
         googleApi.get()
38 37
         .then(() => {
38
+            const {
39
+                liveStreamingEnabled,
40
+                enableCalendarIntegration,
41
+                googleApiApplicationClientID
42
+            } = getState()['features/base/config'];
43
+
39 44
             if (getState()['features/google-api'].googleAPIState
40 45
                     === GOOGLE_API_STATES.NEEDS_LOADING) {
41
-                return googleApi.initializeClient(clientId);
46
+                return googleApi.initializeClient(
47
+                    googleApiApplicationClientID, liveStreamingEnabled, enableCalendarIntegration);
42 48
             }
43 49
 
44 50
             return Promise.resolve();

+ 8
- 5
react/features/google-api/googleApi.web.js View File

@@ -61,11 +61,17 @@ const googleApi = {
61 61
      * making Google API requests.
62 62
      *
63 63
      * @param {string} clientId - The client ID to be used with the API library.
64
+     * @param {boolean} enableYoutube - Whether youtube scope is enabled.
65
+     * @param {boolean} enableCalendar - Whether calendar scope is enabled.
64 66
      * @returns {Promise}
65 67
      */
66
-    initializeClient(clientId) {
68
+    initializeClient(clientId, enableYoutube, enableCalendar) {
67 69
         return this.get()
68 70
             .then(api => new Promise((resolve, reject) => {
71
+                const scope
72
+                    = `${enableYoutube ? GOOGLE_SCOPE_YOUTUBE : ''} ${enableCalendar ? GOOGLE_SCOPE_CALENDAR : ''}`
73
+                        .trim();
74
+
69 75
                 // setTimeout is used as a workaround for api.client.init not
70 76
                 // resolving consistently when the Google API Client Library is
71 77
                 // loaded asynchronously. See:
@@ -74,10 +80,7 @@ const googleApi = {
74 80
                     api.client.init({
75 81
                         clientId,
76 82
                         discoveryDocs: DISCOVERY_DOCS,
77
-                        scope: [
78
-                            GOOGLE_SCOPE_CALENDAR,
79
-                            GOOGLE_SCOPE_YOUTUBE
80
-                        ].join(' ')
83
+                        scope
81 84
                     })
82 85
                     .then(resolve)
83 86
                     .catch(reject);

+ 1
- 2
react/features/recording/components/LiveStream/web/StartLiveStreamDialog.js View File

@@ -121,8 +121,7 @@ class StartLiveStreamDialog
121 121
      * @returns {void}
122 122
      */
123 123
     _onInitializeGoogleApi() {
124
-        this.props.dispatch(
125
-            loadGoogleAPI(this.props._googleApiApplicationClientID))
124
+        this.props.dispatch(loadGoogleAPI())
126 125
         .catch(response => this._parseErrorFromResponse(response));
127 126
     }
128 127
 

Loading…
Cancel
Save