1
1
<template >
2
2
<div >
3
+ <!-- Authorize badge -->
3
4
<div v-if =" hasAuthorizedBadge" >
4
5
<b-badge
5
6
pill
6
7
:variant =" isAuthorized ? 'success' : 'warning'"
7
8
>
8
- <span v-if =" isAuthorized" >{{ $t(' Authorized' ) }}</span >
9
- <span v-else >{{ $t(' Not Authorized' ) }}</span >
9
+ <span v-if =" isAuthorized" >{{ $t(" Authorized" ) }}</span >
10
+ <span v-else >{{ $t(" Not Authorized" ) }}</span >
10
11
</b-badge >
11
12
</div >
12
13
<div v-else >
13
- Empty
14
+ {{ $t(" Empty") }}
14
15
</div >
16
+
17
+ <!-- Connection properties modal -->
15
18
<b-modal
16
19
v-model =" showModal"
17
20
class =" setting-object-modal"
24
27
class="d-block"
25
28
>
26
29
<div >
27
- <h5
28
- v-if =" setting.name"
29
- class =" mb-0"
30
- >
31
- {{ $t(setting.name) }}
32
- </h5 >
33
- <h5
34
- v-else
35
- class =" mb-0"
36
- >
37
- {{ setting.key }}
30
+ <h5 class =" mb-0" >
31
+ <span v-if =" setting.name" >{{ $t(setting.name) }}</span >
32
+ <span v-else >{{ $t(setting.key) }}</span >
38
33
</h5 >
39
- <small class =" form-text text-muted" >{{ $t('Configure the driver connection properties.') }}</small >
34
+ <small class =" form-text text-muted" >
35
+ {{ $t("Configure the driver connection properties.") }}
36
+ </small >
40
37
</div >
41
38
<button
42
39
type =" button"
43
- :aria-label =" $t('Close')"
44
40
class =" close"
41
+ :aria-label =" $t('Close')"
45
42
@click =" onCancel"
46
43
>
47
- ×
44
+ & times ;
48
45
</button >
49
46
</template >
50
47
<div >
51
- <b-form-group
52
- required
53
- :label =" $t('Client ID')"
54
- :description =" formDescription('The client ID assigned when you register your application.', 'client_id', errors)"
55
- :invalid-feedback =" errorMessage('client_id', errors)"
56
- :state =" errorState('client_id', errors)"
57
- >
58
- <b-form-input
59
- v-model =" formData.client_id"
60
- required
61
- autofocus
62
- autocomplete =" off"
63
- :state =" errorState('client_id', errors)"
64
- name =" client_id"
65
- data-cy =" client_id"
66
- />
67
- </b-form-group >
68
-
69
- <b-form-group
70
- required
71
- :label =" $t('Client Secret')"
72
- :description =" formDescription('The client secret assigned when you register your application.', 'client_secret', errors)"
73
- :invalid-feedback =" errorMessage('client_secret', errors)"
74
- :state =" errorState('client_secret', errors)"
75
- >
76
- <b-input-group >
77
- <b-form-input
78
- v-model =" formData.client_secret"
79
- required
80
- autofocus
81
- autocomplete =" off"
82
- trim
83
- :type =" type"
84
- :state =" errorState('client_secret', errors)"
85
- name =" client_secret"
86
- data-cy =" client_secret"
87
- />
88
- <b-input-group-append >
89
- <b-button
90
- :aria-label =" $t('Toggle Show Password')"
91
- variant =" secondary"
92
- @click =" togglePassword"
93
- >
94
- <i
95
- class =" fas"
96
- :class =" icon"
97
- />
98
- </b-button >
99
- </b-input-group-append >
100
- </b-input-group >
101
- </b-form-group >
102
-
103
- <b-form-group
104
- required
105
- :label =" $t('Redirect URL')"
106
- :description =" formDescription('This value must match the callback URL you specify in your app settings.', 'callback_url', errors)"
107
- :invalid-feedback =" errorMessage('callback_url', errors)"
108
- :state =" errorState('callback_url', errors)"
109
- >
110
- <b-input-group >
111
- <b-form-input
112
- v-model =" formData.callback_url"
113
- autofocus
114
- readonly
115
- autocomplete =" off"
116
- :state =" errorState('callback_url', errors)"
117
- name =" callback_url"
118
- data-cy =" callback_url"
119
- />
120
- <b-input-group-append >
121
- <b-button
122
- :aria-label =" $t('Copy')"
123
- variant =" secondary"
124
- @click =" onCopy"
125
- >
126
- <i class =" fas fa-copy" />
127
- </b-button >
128
- </b-input-group-append >
129
- </b-input-group >
130
- </b-form-group >
48
+ <component
49
+ :is =" authSchemeToComponent(setting.config?.AuthScheme)"
50
+ :form-data =" formData"
51
+ :auth-scheme =" setting.config?.AuthScheme"
52
+ @updateFormData =" updateFormData"
53
+ />
131
54
132
55
<additional-driver-connection-properties
133
56
:driver-key =" setting?.key"
145
68
data-cy =" cancel-button"
146
69
@click =" onCancel"
147
70
>
148
- {{ $t(' Cancel' ) }}
71
+ {{ $t(" Cancel" ) }}
149
72
</button >
150
73
<button
151
74
type =" button"
152
75
class =" btn btn-secondary ml-3"
153
76
data-cy =" authorize-button"
154
- :disabled =" isButtonDisabled"
155
77
@click =" onSave"
156
78
>
157
- {{ $t(' Authorize' ) }}
79
+ {{ $t(" Authorize" ) }}
158
80
</button >
159
81
</div >
160
82
</b-modal >
161
83
84
+ <!-- Authorizing modal -->
162
85
<b-modal
163
86
v-model =" showAuthorizingModal"
164
87
class =" setting-object-modal"
169
92
no-fade
170
93
>
171
94
<div class =" text-center" >
172
- <h3 >{{ $t(' Connecting Driver' ) }}</h3 >
95
+ <h3 >{{ $t(" Connecting Driver" ) }}</h3 >
173
96
<i class =" fas fa-circle-notch fa-spin fa-3x p-0 text-primary" />
174
97
</div >
175
98
</b-modal >
176
99
</div >
177
100
</template >
178
-
179
101
<script >
180
102
// eslint-disable-next-line import/no-unresolved
181
103
import { FormErrorsMixin , Required } from " SharedComponents" ;
182
104
import settingMixin from " ../mixins/setting" ;
183
105
import AdditionalDriverConnectionProperties from " ./AdditionalDriverConnectionProperties.vue" ;
106
+ import OauthConnectionProperties from " ./cdata/OauthConnectionProperties.vue" ;
107
+ import NoneConnectionProperties from " ./cdata/NoneConnectionProperties.vue" ;
108
+ import PasswordConnectionProperties from " ./cdata/PasswordConnectionProperties.vue" ;
184
109
185
110
export default {
186
- components: { AdditionalDriverConnectionProperties },
111
+ components: {
112
+ AdditionalDriverConnectionProperties,
113
+ OauthConnectionProperties,
114
+ NoneConnectionProperties,
115
+ PasswordConnectionProperties,
116
+ },
187
117
mixins: [settingMixin, FormErrorsMixin, Required],
188
118
props: {
189
119
setting: {
190
120
type: [Object , null ],
191
- default: null ,
121
+ default : () => ({}) ,
192
122
},
193
123
value: {
194
124
type: Object ,
@@ -198,19 +128,19 @@ export default {
198
128
data () {
199
129
return {
200
130
input: " " ,
201
- formData: {
202
- client_id: " " ,
203
- client_secret: " " ,
204
- callback_url: " " ,
205
- },
131
+ formData: {},
206
132
selected: null ,
207
133
showModal: false ,
208
134
showAuthorizingModal: false ,
209
135
transformed: null ,
210
136
errors: {},
211
- isInvalid: true ,
212
- type: " password" ,
213
137
resetData: true ,
138
+ componentsMap: {
139
+ OAuth: " oauth-connection-properties" ,
140
+ None: " none-connection-properties" ,
141
+ Password: " password-connection-properties" ,
142
+ Basic: " password-connection-properties" ,
143
+ },
214
144
};
215
145
},
216
146
computed: {
@@ -227,57 +157,18 @@ export default {
227
157
}
228
158
return false ;
229
159
},
230
- changed () {
231
- return JSON .stringify (this .formData ) !== JSON .stringify (this .transformed );
232
- },
233
- icon () {
234
- if (this .type === " password" ) {
235
- return " fa-eye" ;
236
- }
237
- return " fa-eye-slash" ;
238
- },
239
- isButtonDisabled () {
240
- return this .isInvalid || (this .isAuthorized && ! this .changed );
241
- },
242
- },
243
- watch: {
244
- formData: {
245
- handler () {
246
- this .isInvalid = this .validateData ();
247
- },
248
- deep: true ,
249
- },
250
160
},
251
161
mounted () {
252
162
if (this .value === null ) {
253
163
this .resetFormData ();
254
164
} else {
255
165
this .formData = this .value ;
256
166
}
257
- this .isInvalid = this .validateData ();
258
167
this .transformed = this .copy (this .formData );
259
168
},
260
169
methods: {
261
- onCopy () {
262
- navigator .clipboard .writeText (this .formData .callback_url ).then (() => {
263
- ProcessMaker .alert (this .$t (" The setting was copied to your clipboard." ), " success" );
264
- }, () => {
265
- ProcessMaker .alert (this .$t (" The setting was not copied to your clipboard." ), " danger" );
266
- });
267
- },
268
- togglePassword () {
269
- if (this .type === " text" ) {
270
- this .type = " password" ;
271
- } else {
272
- this .type = " text" ;
273
- }
274
- },
275
- validateData () {
276
- // Check if client_id and client_secret are empty
277
- const clientIdEmpty = _ .isEmpty (this .formData .client_id );
278
- const clientSecretEmpty = _ .isEmpty (this .formData .client_secret );
279
-
280
- return _ .isEmpty (this .formData ) || clientIdEmpty || clientSecretEmpty;
170
+ authSchemeToComponent (scheme ) {
171
+ return this .componentsMap [scheme] || null ;
281
172
},
282
173
onCancel () {
283
174
this .showModal = false ;
@@ -294,14 +185,48 @@ export default {
294
185
onModalHidden () {
295
186
this .resetFormData ();
296
187
},
188
+ generateCallbackUrl (item ) {
189
+ if (item .config .AuthScheme === " OAuth" ) {
190
+ const name = item .key .split (" cdata." )[1 ];
191
+ const appUrl = document .head .querySelector (" meta[name=\" app-url\" ]" ).content ;
192
+
193
+ this .formData .callback_url = ` ${ appUrl} /external-integrations/${ name} ` ;
194
+ }
195
+ },
297
196
authorizeConnection () {
298
197
this .showAuthorizingModal = true ;
299
198
this .showModal = false ;
300
199
this .resetData = false ;
301
- ProcessMaker .apiClient .post (` settings/${ this .setting .id } /get-oauth-url` , this .formData )
200
+
201
+ if (this .setting .config .AuthScheme === " OAuth" ) {
202
+ this .authorizeOAuthConnection ();
203
+ } else {
204
+ this .authorizeNoneConnection ();
205
+ }
206
+ },
207
+ authorizeOAuthConnection () {
208
+ ProcessMaker .apiClient
209
+ .post (` settings/${ this .setting .id } /get-oauth-url` , this .formData )
302
210
.then ((response ) => {
303
211
window .location = response .data ? .url ;
304
212
})
213
+ .catch ((error ) => {
214
+ const errorMessage = error .response ? .data ? .message || error .message ;
215
+ ProcessMaker .alert (errorMessage, " danger" );
216
+ })
217
+ .finally (() => {
218
+ this .showModal = true ;
219
+ this .showAuthorizingModal = false ;
220
+ });
221
+ },
222
+ authorizeNoneConnection () {
223
+ ProcessMaker .apiClient
224
+ .post (` settings/${ this .setting .id } /authorize-driver` , this .formData )
225
+ .then ((response ) => {
226
+ window .location = response .data .url ;
227
+ this .showModal = false ;
228
+ this .showAuthorizingModal = true ;
229
+ })
305
230
.catch ((error ) => {
306
231
const errorMessage = error .response ? .data ? .message || error .message ;
307
232
ProcessMaker .alert (errorMessage, " danger" );
@@ -310,18 +235,11 @@ export default {
310
235
});
311
236
},
312
237
onSave () {
313
- const driver = this .setting .key .split (" cdata." )[1 ];
314
-
315
- this .formData .driver = driver;
238
+ this .formData .name = this .setting .config ? .name ;
239
+ this .formData .driver = this .setting .config ? .driver ;
316
240
this .transformed = { ... this .formData };
317
241
this .authorizeConnection ();
318
242
},
319
- generateCallbackUrl (data ) {
320
- const name = data .key .split (" cdata." )[1 ];
321
- const appUrl = document .head .querySelector (" meta[name=\" app-url\" ]" ).content ;
322
-
323
- this .formData .callback_url = ` ${ appUrl} /external-integrations/${ name} ` ;
324
- },
325
243
resetFormData () {
326
244
if (this .resetData ) {
327
245
this .formData = {
0 commit comments