-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathAdminSettings.vue
1207 lines (1194 loc) · 45 KB
/
AdminSettings.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<template>
<div id="openproject_prefs" class="section">
<TermsOfServiceUnsigned :is-all-terms-of-service-signed-for-user-open-project="isAllTermsOfServiceSignedForUserOpenProject" />
<SettingsTitle is-setting="admin" />
<NcNoteCard v-if="!isAdminAuditConfigurationSetUpCorrectly" class="audit-info-card" type="info">
<p class="audit-info-card--info" v-html="getAdminAuditConfigurationHint" /> <!-- eslint-disable-line vue/no-v-html -->
</NcNoteCard>
<div class="openproject-server-host">
<FormHeading index="1"
:title="t('integration_openproject', 'OpenProject server')"
:is-complete="isServerHostFormComplete"
:is-dark-theme="isDarkTheme" />
<FieldValue v-if="isServerHostFormInView"
is-required
class="pb-1"
:title="t('integration_openproject', 'OpenProject host')"
:value="state.openproject_instance_url" />
<TextInput v-else
id="openproject-oauth-instance"
ref="openproject-oauth-instance-input"
v-model="serverHostUrlForEdit"
is-required
:read-only="isServerHostUrlReadOnly"
class="pb-1"
:label="t('integration_openproject', 'OpenProject host')"
place-holder="https://www.my-openproject.com"
:hint-text="t('integration_openproject', 'Please introduce your OpenProject hostname')"
:error-message="serverHostErrorMessage"
:error-message-details="openProjectNotReachableErrorMessageDetails"
@click="isServerHostUrlReadOnly = false"
@input="isOpenProjectInstanceValid = null" />
<div class="form-actions">
<NcButton v-if="isServerHostFormInView"
data-test-id="reset-server-host-btn"
@click="setServerHostFormToEditMode">
<template #icon>
<PencilIcon :size="20" />
</template>
{{ t('integration_openproject', 'Edit server information') }}
</NcButton>
<NcButton v-if="isServerHostFormComplete && isServerHostFormInEdit"
class="mr-2"
data-test-id="cancel-edit-server-host-btn"
@click="setServerHostFormToViewMode">
{{ t('integration_openproject', 'Cancel') }}
</NcButton>
<NcButton v-if="isServerHostFormInEdit"
type="primary"
data-test-id="submit-server-host-form-btn"
:disabled="!serverHostUrlForEdit || serverHostUrlForEdit === state.openproject_instance_url"
@click="saveOpenProjectHostUrl">
<template #icon>
<NcLoadingIcon v-if="loadingServerHostForm" class="loading-spinner" :size="20" />
<CheckBoldIcon v-else fill-color="#FFFFFF" :size="20" />
</template>
{{ t('integration_openproject', 'Save') }}
</NcButton>
</div>
</div>
<div class="openproject-oauth-values">
<FormHeading index="2"
:title="t('integration_openproject', 'OpenProject OAuth settings')"
:is-complete="isOPOAuthFormComplete"
:is-disabled="isOPOAuthFormInDisableMode"
:is-dark-theme="isDarkTheme" />
<div v-if="isServerHostFormComplete">
<FieldValue v-if="isOPOAuthFormInView"
is-required
:value="state.openproject_client_id"
title="OpenProject OAuth client ID" />
<TextInput v-else
id="openproject-oauth-client-id"
v-model="state.openproject_client_id"
class="py-1"
is-required
label="OpenProject OAuth client ID"
:hint-text="openProjectClientHint" />
<FieldValue v-if="isOPOAuthFormInView"
is-required
class="pb-1"
encrypt-value
title="OpenProject OAuth client secret"
:value="state.openproject_client_secret" />
<TextInput v-else
id="openproject-oauth-client-secret"
v-model="state.openproject_client_secret"
is-required
class="py-1"
label="OpenProject OAuth client secret"
:hint-text="openProjectClientHint" />
<div class="form-actions">
<NcButton v-if="isOPOAuthFormComplete && isOPOAuthFormInView"
data-test-id="reset-op-oauth-btn"
@click="resetOPOAuthClientValues">
<template #icon>
<AutoRenewIcon :size="20" />
</template>
{{ t('integration_openproject', 'Replace OpenProject OAuth values') }}
</NcButton>
<NcButton v-else
data-test-id="submit-op-oauth-btn"
type="primary"
:disabled="!state.openproject_client_id || !state.openproject_client_secret"
@click="saveOPOAuthClientValues">
<template #icon>
<NcLoadingIcon v-if="loadingOPOauthForm" class="loading-spinner" :size="20" />
<CheckBoldIcon v-else fill-color="#FFFFFF" :size="20" />
</template>
{{ t('integration_openproject', 'Save') }}
</NcButton>
</div>
</div>
</div>
<div class="nextcloud-oauth-values">
<FormHeading index="3"
:title="t('integration_openproject', 'Nextcloud OAuth client')"
:is-complete="isNcOAuthFormComplete"
:is-disabled="isNcOAuthFormInDisableMode"
:is-dark-theme="isDarkTheme" />
<div v-if="state.nc_oauth_client">
<TextInput v-if="isNcOAuthFormInEdit"
id="nextcloud-oauth-client-id"
v-model="state.nc_oauth_client.nextcloud_client_id"
class="py-1"
read-only
is-required
with-copy-btn
label="Nextcloud OAuth client ID"
:hint-text="nextcloudClientHint" />
<FieldValue v-else
title="Nextcloud OAuth client ID"
:value="state.nc_oauth_client.nextcloud_client_id"
is-required />
<TextInput v-if="isNcOAuthFormInEdit"
id="nextcloud-oauth-client-secret"
v-model="state.nc_oauth_client.nextcloud_client_secret"
class="py-1"
read-only
is-required
with-copy-btn
label="Nextcloud OAuth client secret"
:hint-text="nextcloudClientHint" />
<FieldValue v-else
title="Nextcloud OAuth client secret"
is-required
encrypt-value
:value="ncClientSecret" />
<div class="form-actions">
<NcButton v-if="isNcOAuthFormInEdit"
type="primary"
:disabled="!ncClientId"
data-test-id="submit-nc-oauth-values-form-btn"
@click="setNCOAuthFormToViewMode">
<template #icon>
<CheckBoldIcon fill-color="#FFFFFF" :size="20" />
</template>
{{ t('integration_openproject', 'Yes, I have copied these values') }}
</NcButton>
<NcButton v-else
data-test-id="reset-nc-oauth-btn"
@click="resetNcOauthValues">
<template #icon>
<AutoRenewIcon :size="20" />
</template>
{{ t('integration_openproject', 'Replace Nextcloud OAuth values') }}
</NcButton>
</div>
</div>
<div v-if="!state.nc_oauth_client && isOPOAuthFormComplete && isOPOAuthFormInView && showDefaultManagedProjectFolders">
<NcButton data-test-id="reset-nc-oauth-btn"
@click="resetNcOauthValues">
<template #icon>
<AutoRenewIcon :size="20" />
</template>
{{ t('integration_openproject', 'Create Nextcloud OAuth values') }}
</NcButton>
</div>
</div>
<div class="project-folder-setup">
<FormHeading index="4"
:is-project-folder-setup-heading="true"
:title="t('integration_openproject', 'Project folders (recommended)')"
:is-setup-complete-without-project-folders="isSetupCompleteWithoutProjectFolders"
:is-there-error-after-project-folder-and-app-password-setup="isThereErrorAfterProjectFolderAndAppPasswordSetup"
:is-complete="isProjectFolderSetupCompleted"
:is-disabled="isProjectFolderSetUpInDisableMode"
:is-dark-theme="isDarkTheme" />
<div v-if="showDefaultManagedProjectFolders">
<div v-if="isProjectFolderSetupFormInEdit">
<NcCheckboxRadioSwitch type="switch" :checked.sync="isProjectFolderSwitchEnabled" @update:checked="changeProjectFolderSetUpState">
<b>{{ t('integration_openproject', 'Automatically managed folders') }}</b>
</NcCheckboxRadioSwitch>
<div v-if="isProjectFolderSwitchEnabled === false" class="complete-without-groupfolders">
<p class="project-folder-description">
{{
t('integration_openproject', 'We recommend using this functionality but it is not mandatory. Please activate it in case you want to use the automatic creation and management of project folders.')
}}
</p>
<div class="form-actions">
<NcButton type="primary"
data-test-id="complete-without-project-folder-form-btn"
@click="completeIntegrationWithoutProjectFolderSetUp">
<template #icon>
<CheckBoldIcon fill-color="#FFFFFF" :size="20" />
</template>
{{
textLabelProjectFolderSetupButton
}}
</NcButton>
</div>
</div>
<div v-else>
<p class="project-folder-description">
{{
t('integration_openproject', 'Let OpenProject create folders per project automatically. It will ensure that every team member has always the correct access permissions.')
}}
</p>
<br>
<b>{{ t('integration_openproject', 'OpenProject user, group and folder') }}</b>
<p class="project-folder-description">
{{
t('integration_openproject', 'For automatically managing project folders, this app needs to setup a special group folder, assigned to a group and managed by a user, each called "OpenProject".')
}} <br>
{{
t('integration_openproject', 'The app will never delete files or folders, even if you deactivate this later.')
}}
</p>
<ProjectFolderError
v-if="projectFolderSetupError !== null"
:project-folder-set-up-error-message-description="projectFolderSetUpErrorMessageDescription(projectFolderSetupError)"
:project-folder-set-up-error="projectFolderSetupError" />
<div class="form-actions">
<NcButton v-if="projectFolderSetupError === null"
type="primary"
data-test-id="complete-with-project-folders-form-btn"
@click="setUpProjectGroupFolders">
<template #icon>
<NcLoadingIcon v-if="loadingProjectFolderSetup" class="loading-spinner" :size="20" />
<CheckBoldIcon v-else fill-color="#FFFFFF" :size="20" />
</template>
{{ textLabelProjectFolderSetupButton }}
</NcButton>
<NcButton v-else-if="projectFolderSetupError"
type="primary"
data-test-id="complete-with-project-folders-form-btn"
@click="setUpProjectGroupFolders">
<template #icon>
<NcLoadingIcon v-if="loadingProjectFolderSetup" class="loading-spinner" :size="20" />
<RestoreIcon v-else fill-color="#FFFFFF" :size="20" />
</template>
{{ t('integration_openproject', 'Retry setup OpenProject user, group and folder') }}
</NcButton>
</div>
</div>
</div>
<div v-else class="project-folder-status">
<div class="project-folder-status-value">
<b>{{ t('integration_openproject','Automatically managed folders:') }}</b> {{ opUserAppPassword ? t('integration_openproject', 'Active') : t('integration_openproject', 'Inactive') }}
</div>
<ProjectFolderError
v-if="state.app_password_set && !isProjectFolderSetupCorrect"
:project-folder-set-up-error-message-description="projectFolderSetUpErrorMessageDescription(state.project_folder_info.errorMessage)"
:project-folder-set-up-error="state.project_folder_info.errorMessage" />
<div class="form-actions">
<NcButton
data-test-id="edit-project-folder-setup"
@click="setProjectFolderSetUpToEditMode">
<template #icon>
<PencilIcon :size="20" />
</template>
{{ t('integration_openproject', 'Edit project folders') }}
</NcButton>
</div>
</div>
</div>
</div>
<div v-if="state.app_password_set">
<FormHeading index="5"
:title="t('integration_openproject', 'Project folders application connection')"
:is-complete="isOPUserAppPasswordFormComplete"
:is-disabled="isOPUserAppPasswordInDisableMode"
:is-dark-theme="isDarkTheme" />
<div v-if="state.app_password_set">
<TextInput v-if="isOPUserAppPasswordFormInEdit"
id="openproject-system-password"
v-model="oPUserAppPassword"
class="py-1"
read-only
is-required
with-copy-btn
:label="t('integration_openproject', 'Application Password')"
:hint-text="userAppPasswordHint" />
<FieldValue v-else
:title="t('integration_openproject', 'Application Password')"
is-required
hide-value
with-inspection
value="" />
<div class="form-actions">
<NcButton v-if="isOPUserAppPasswordFormInEdit"
type="primary"
:disabled="!opUserAppPassword"
data-test-id="submit-op-system-password-form-btn"
@click="setOPUserAppPasswordToViewMode">
<template #icon>
<CheckBoldIcon fill-color="#FFFFFF" :size="20" />
</template>
{{ t('integration_openproject', 'Done, complete setup') }}
</NcButton>
<NcButton v-else
data-test-id="reset-user-app-password"
@click="resetOPUserAppPassword">
<template #icon>
<AutoRenewIcon :size="20" />
</template>
{{ t('integration_openproject', 'Replace application password') }}
</NcButton>
</div>
</div>
</div>
<NcButton id="reset-all-app-settings-btn"
type="error"
:disabled="isResetButtonDisabled"
@click="resetAllAppValuesConfirmation">
<template #icon>
<RestoreIcon :size="20" />
</template>
{{ t('integration_openproject', 'Reset') }}
</NcButton>
<div v-if="isIntegrationComplete" class="default-prefs">
<h2>{{ t('integration_openproject', 'Default user settings') }}</h2>
<p>
{{ t('integration_openproject', 'A new user will receive these defaults and they will be applied to the integration app till the user changes them.') }}
</p>
<br>
<CheckBox v-model="state.default_enable_navigation"
input-id="default-prefs--link"
:label="t('integration_openproject', 'Enable navigation link')"
@input="setDefaultConfig">
<template #hint>
<p class="user-setting-description" v-html="userSettingDescription.NAVIGATION_LINK_DESCRIPTION" /> <!-- eslint-disable-line vue/no-v-html -->
</template>
</CheckBox>
<CheckBox v-model="state.default_enable_unified_search"
input-id="default-prefs--u-search"
:label="t('integration_openproject', 'Enable unified search for tickets')"
@input="setDefaultConfig">
<template #hint>
<p class="user-setting-description" v-html="userSettingDescription.UNIFIED_SEARCH_DESCRIPTION" /> <!-- eslint-disable-line vue/no-v-html -->
</template>
</CheckBox>
</div>
</div>
</template>
<script>
import util from 'util'
import axios from '@nextcloud/axios'
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import { showSuccess, showError } from '@nextcloud/dialogs'
import CheckBoldIcon from 'vue-material-design-icons/CheckBold.vue'
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
import { NcLoadingIcon, NcCheckboxRadioSwitch, NcButton, NcNoteCard } from '@nextcloud/vue'
import RestoreIcon from 'vue-material-design-icons/Restore.vue'
import AutoRenewIcon from 'vue-material-design-icons/Autorenew.vue'
import TextInput from './admin/TextInput.vue'
import FieldValue from './admin/FieldValue.vue'
import FormHeading from './admin/FormHeading.vue'
import CheckBox from '../components/settings/CheckBox.vue'
import SettingsTitle from '../components/settings/SettingsTitle.vue'
import { F_MODES, FORM, USER_SETTINGS } from '../utils.js'
import ProjectFolderError from './admin/ProjectFolderError.vue'
import TermsOfServiceUnsigned from './admin/TermsOfServiceUnsigned.vue'
import dompurify from 'dompurify'
export default {
name: 'AdminSettings',
components: {
NcButton,
FieldValue,
FormHeading,
TextInput,
SettingsTitle,
CheckBoldIcon,
PencilIcon,
NcLoadingIcon,
AutoRenewIcon,
RestoreIcon,
CheckBox,
NcCheckboxRadioSwitch,
ProjectFolderError,
TermsOfServiceUnsigned,
NcNoteCard,
},
data() {
return {
formMode: {
// server host form is never disabled.
// it's either editable or view only
server: F_MODES.EDIT,
opOauth: F_MODES.DISABLE,
ncOauth: F_MODES.DISABLE,
opUserAppPassword: F_MODES.DISABLE,
projectFolderSetUp: F_MODES.DISABLE,
},
isFormCompleted: {
server: false, opOauth: false, ncOauth: false, opUserAppPassword: false, projectFolderSetUp: false,
},
buttonTextLabel: {
keepCurrentChange: t('integration_openproject', 'Keep current setup'),
completeWithoutProjectFolderSetup: t('integration_openproject', 'Complete without project folders'),
completeWithProjectFolderSetup: t('integration_openproject', 'Setup OpenProject user, group and folder'),
},
loadingServerHostForm: false,
loadingProjectFolderSetup: false,
loadingOPOauthForm: false,
isOpenProjectInstanceValid: null,
openProjectNotReachableErrorMessage: null,
openProjectNotReachableErrorMessageDetails: null,
state: loadState('integration_openproject', 'admin-config'),
isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'),
serverHostUrlForEdit: null,
isServerHostUrlReadOnly: true,
oPOAuthTokenRevokeStatus: null,
oPUserAppPassword: null,
isProjectFolderSwitchEnabled: null,
projectFolderSetupError: null,
isProjectFolderAlreadySetup: null,
// we assume this value as true and without error, it is set false when something goes wrong after the project folder setup is already completed
isProjectFolderSetupCorrect: true,
showDefaultManagedProjectFolders: false,
// this keeps track of the state of project folder when user has done some setup (with or without)
currentProjectFolderState: false,
textLabelProjectFolderSetupButton: null,
// pointer for which form the request is coming
isFormStep: null,
isDarkTheme: null,
isAllTermsOfServiceSignedForUserOpenProject: true,
userSettingDescription: USER_SETTINGS,
}
},
computed: {
ncClientId() {
return this.state.nc_oauth_client?.nextcloud_client_id
},
ncClientSecret() {
return '*******'
},
opUserAppPassword() {
return this.state.app_password_set
},
isAdminAuditConfigurationSetUpCorrectly() {
return this.state.admin_audit_configuration_correct
},
serverHostErrorMessage() {
if (
this.serverHostUrlForEdit === ''
|| this.isOpenProjectInstanceValid === null
|| this.isOpenProjectInstanceValid
) return null
return this.openProjectNotReachableErrorMessage
},
isServerHostFormComplete() {
return this.isFormCompleted.server
},
isOPOAuthFormComplete() {
return this.isFormCompleted.opOauth
},
isManagedGroupFolderSetUpComplete() {
return this.isFormCompleted.projectFolderSetUp
},
isOPUserAppPasswordFormComplete() {
return this.isFormCompleted.opUserAppPassword
},
isNcOAuthFormComplete() {
return this.isFormCompleted.ncOauth
},
isServerHostFormInView() {
return this.formMode.server === F_MODES.VIEW
},
isOPOAuthFormInView() {
return this.formMode.opOauth === F_MODES.VIEW
},
isServerHostFormInEdit() {
return this.formMode.server === F_MODES.EDIT
},
isNcOAuthFormInEdit() {
return this.formMode.ncOauth === F_MODES.EDIT
},
isOPOAuthFormInDisableMode() {
return this.formMode.opOauth === F_MODES.DISABLE
},
isOPUserAppPasswordFormInEdit() {
return this.formMode.opUserAppPassword === F_MODES.EDIT
},
isProjectFolderSetupFormInEdit() {
return this.formMode.projectFolderSetUp === F_MODES.EDIT
},
isNcOAuthFormInDisableMode() {
return this.formMode.ncOauth === F_MODES.DISABLE
},
isProjectFolderSetUpInDisableMode() {
return this.formMode.projectFolderSetUp === F_MODES.DISABLE
},
isOPUserAppPasswordInDisableMode() {
return this.formMode.opUserAppPassword === F_MODES.DISABLE
},
isThereErrorAfterProjectFolderAndAppPasswordSetup() {
return (this.opUserAppPassword && this.formMode.projectFolderSetUp !== F_MODES.EDIT && this.isProjectFolderSetupCorrect === false)
},
isProjectFolderSetupCompleted() {
return this.isProjectFolderSetupFormInEdit ? false : this.opUserAppPassword
},
adminFileStorageHref() {
let hostPart = ''
const urlPart = '%sadmin/settings/storages'
if (this.state?.openproject_instance_url.endsWith('/')) {
hostPart = this.state.openproject_instance_url
} else hostPart = this.state.openproject_instance_url + '/'
return util.format(urlPart, hostPart)
},
openProjectClientHint() {
const linkText = t('integration_openproject', 'Administration > File storages')
const htmlLink = `<a class="link" href="${this.adminFileStorageHref}" target="_blank" title="${linkText}">${linkText}</a>`
return t('integration_openproject', 'Go to your OpenProject {htmlLink} as an Administrator and start the setup and copy the values here.', { htmlLink }, null, { escape: false, sanitize: false })
},
nextcloudClientHint() {
const linkText = t('integration_openproject', 'Administration > File storages')
const htmlLink = `<a class="link" href="${this.adminFileStorageHref}" target="_blank" title="${linkText}">${linkText}</a>`
return t('integration_openproject', 'Copy the following values back into the OpenProject {htmlLink} as an Administrator.', { htmlLink }, null, { escape: false, sanitize: false })
},
userAppPasswordHint() {
const linkText = t('integration_openproject', 'Administration > File storages')
const htmlLink = `<a class="link" href="${this.adminFileStorageHref}" target="_blank" title="${linkText}">${linkText}</a>`
return t('integration_openproject', 'This value will only be accessible once. Now, as an administrator copy this password to OpenProject {htmlLink}.', { htmlLink }, null, { escape: false, sanitize: false })
},
errorHintForProjectFolderConfigAlreadyExists() {
const linkText = t('integration_openproject', 'troubleshooting guide')
const htmlLink = `<a class="link" href="https://www.openproject.org/docs/system-admin-guide/integrations/nextcloud/#troubleshooting" target="_blank" title="${linkText}">${linkText}</a>`
return t('integration_openproject', 'Setting up the OpenProject user, group and group folder was not possible. Please check this {htmlLink} on how to resolve this situation.', { htmlLink }, null, { escape: false, sanitize: false })
},
getAdminAuditConfigurationHint() {
const linkTextForAdminAudit = t('integration_openproject', 'Admin Audit')
const adminAuditAppUrlForDownload = generateUrl('settings/apps/featured/admin_audit')
const linkTextForDocumentation = t('integration_openproject', 'documentation')
const htmlLinkForAdminAudit = `<a class="link" href="${adminAuditAppUrlForDownload}" target="_blank" title="${linkTextForAdminAudit}">${linkTextForAdminAudit}</a>`
const htmlLinkForDocumentaion = `<a class="link" href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/logging_configuration.html#admin-audit-log-optional" target="_blank" title="${linkTextForDocumentation}">${linkTextForDocumentation}</a>`
const hintTextForAdminAudit = t('integration_openproject', 'To activate audit logs for the OpenProject integration, please enable the {htmlLinkForAdminAudit} app and follow the configuration steps outlined in the {htmlLinkForDocumentaion}.', { htmlLinkForAdminAudit, htmlLinkForDocumentaion }, null, { escape: false, sanitize: false })
return dompurify.sanitize(hintTextForAdminAudit, { ADD_ATTR: ['target'] })
},
isIntegrationComplete() {
return (this.isServerHostFormComplete
&& this.isOPOAuthFormComplete
&& this.isNcOAuthFormComplete
&& this.isManagedGroupFolderSetUpComplete
&& !this.isOPUserAppPasswordFormInEdit
)
},
isSetupCompleteWithoutProjectFolders() {
if (this.isProjectFolderSetupFormInEdit) {
return false
}
if (this.isFormCompleted.projectFolderSetUp === false && !this.opUserAppPassword) {
return false
}
return !this.opUserAppPassword
},
isResetButtonDisabled() {
return !(this.state.openproject_client_id || this.state.openproject_client_secret || this.state.openproject_instance_url)
},
},
created() {
this.init()
},
mounted() {
this.isDarkTheme = window.getComputedStyle(this.$el).getPropertyValue('--background-invert-if-dark') === 'invert(100%)'
},
methods: {
init() {
if (this.state) {
if (this.state.all_terms_of_services_signed === false) {
this.isAllTermsOfServiceSignedForUserOpenProject = false
}
if (this.state.project_folder_info) {
this.isProjectFolderSetupCorrect = this.state.project_folder_info.status
if (this.state.project_folder_info.status === true) {
this.isProjectFolderAlreadySetup = true
}
}
if (this.state.fresh_project_folder_setup === true) {
this.currentProjectFolderState = true
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithProjectFolderSetup
} else {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.keepCurrentChange
}
if (this.state.openproject_instance_url && this.state.openproject_client_id && this.state.openproject_client_secret && this.state.nc_oauth_client) {
this.showDefaultManagedProjectFolders = true
}
if (this.state.openproject_instance_url) {
this.formMode.server = F_MODES.VIEW
this.isFormCompleted.server = true
}
if (!!this.state.openproject_client_id && !!this.state.openproject_client_secret) {
this.formMode.opOauth = F_MODES.VIEW
this.isFormCompleted.opOauth = true
}
if (this.state.openproject_instance_url) {
if (!this.state.openproject_client_id || !this.state.openproject_client_secret) {
this.formMode.opOauth = F_MODES.EDIT
}
}
if (this.state.nc_oauth_client) {
this.formMode.ncOauth = F_MODES.VIEW
this.isFormCompleted.ncOauth = true
}
if (!this.state.nc_oauth_client
&& this.state.openproject_instance_url
&& this.state.openproject_client_id
&& this.state.openproject_client_secret
&& this.textLabelProjectFolderSetupButton === 'Keep current setup') {
this.showDefaultManagedProjectFolders = true
this.formMode.projectFolderSetUp = F_MODES.VIEW
this.isFormCompleted.projectFolderSetUp = true
}
if (this.formMode.ncOauth === F_MODES.VIEW) {
this.showDefaultManagedProjectFolders = true
}
if (this.showDefaultManagedProjectFolders) {
this.formMode.projectFolderSetUp = F_MODES.VIEW
this.isFormCompleted.projectFolderSetUp = true
}
if (this.state.app_password_set) {
this.formMode.opUserAppPassword = F_MODES.VIEW
this.isFormCompleted.opUserAppPassword = true
this.currentProjectFolderState = true
this.isProjectFolderSwitchEnabled = true
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.keepCurrentChange
}
this.isProjectFolderSwitchEnabled = this.currentProjectFolderState === true
}
},
projectFolderSetUpErrorMessageDescription(errorKey) {
const linkText = t('integration_openproject', 'Download and enable it here')
const url = generateUrl('settings/apps/files/groupfolders')
const htmlLink = `<a class="link" href="${url}" target="_blank" title="${linkText}">${linkText}</a>`
switch (errorKey) {
case 'The "Group folders" app is not installed' :
return t('integration_openproject', 'Please install the "Group folders" app to be able to use automatically managed folders. {htmlLink}', { htmlLink }, null, { escape: false, sanitize: false })
default:
return this.errorHintForProjectFolderConfigAlreadyExists
}
},
closeRequestModal() {
this.show = false
},
setServerHostFormToViewMode() {
this.formMode.server = F_MODES.VIEW
},
setServerHostFormToEditMode() {
this.formMode.server = F_MODES.EDIT
// set the edit variable to the current saved value
this.serverHostUrlForEdit = this.state.openproject_instance_url
this.isOpenProjectInstanceValid = null
},
setProjectFolderSetUpToEditMode() {
this.formMode.projectFolderSetUp = F_MODES.EDIT
this.isFormCompleted.projectFolderSetUp = false
this.isProjectFolderSwitchEnabled = this.currentProjectFolderState
},
setProjectFolderSetupToViewMode() {
this.currentProjectFolderState = true
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.keepCurrentChange
this.isFormCompleted.projectFolderSetUp = true
this.formMode.projectFolderSetUp = F_MODES.VIEW
this.isProjectFolderSetupCorrect = true
},
async setNCOAuthFormToViewMode() {
this.formMode.ncOauth = F_MODES.VIEW
this.isFormCompleted.ncOauth = true
if (!this.isIntegrationComplete && this.formMode.projectFolderSetUp !== F_MODES.EDIT && this.formMode.opUserAppPassword !== F_MODES.EDIT) {
this.formMode.projectFolderSetUp = F_MODES.EDIT
this.showDefaultManagedProjectFolders = true
this.isProjectFolderSwitchEnabled = true
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithProjectFolderSetup
}
},
setOPUserAppPasswordToViewMode() {
this.formMode.opUserAppPassword = F_MODES.VIEW
this.isFormCompleted.opUserAppPassword = true
},
changeProjectFolderSetUpState() {
if (this.opUserAppPassword === false) {
if (this.currentProjectFolderState === true && this.isProjectFolderSwitchEnabled === true) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithProjectFolderSetup
} else if (this.currentProjectFolderState === true && this.isProjectFolderSwitchEnabled === false) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithoutProjectFolderSetup
} else if (this.currentProjectFolderState === false && this.isProjectFolderSwitchEnabled === false) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.keepCurrentChange
} else if (this.currentProjectFolderState === false && this.isProjectFolderSwitchEnabled === true) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithProjectFolderSetup
}
} else if (this.currentProjectFolderState === true && this.isProjectFolderSwitchEnabled === true) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.keepCurrentChange
} else if (this.currentProjectFolderState === true && this.isProjectFolderSwitchEnabled === false) {
this.textLabelProjectFolderSetupButton = this.buttonTextLabel.completeWithoutProjectFolderSetup
}
},
async setUpProjectGroupFolders() {
this.isFormStep = FORM.GROUP_FOLDER
this.loadingProjectFolderSetup = true
this.isProjectFolderAlreadySetup = await this.checkIfProjectFolderIsAlreadyReadyForSetup()
if (this.isProjectFolderAlreadySetup) {
if (!this.opUserAppPassword) {
const success = await this.saveOPOptions()
if (success) {
this.formMode.opUserAppPassword = F_MODES.EDIT
this.setProjectFolderSetupToViewMode()
}
} else {
this.setProjectFolderSetupToViewMode()
}
} else {
// we will check for the error making the setup_project_folder === true
const success = await this.saveOPOptions()
if (success) {
this.setProjectFolderSetupToViewMode()
if ((this.formMode.opUserAppPassword === F_MODES.DISABLE && !this.opUserAppPassword) || this.formMode.opUserAppPassword === F_MODES.DISABLE) {
this.formMode.opUserAppPassword = F_MODES.EDIT
}
}
}
this.loadingProjectFolderSetup = false
if (this.formMode.projectFolderSetUp === F_MODES.VIEW) {
this.projectFolderSetupError = null
}
},
async saveOpenProjectHostUrl() {
this.isFormStep = FORM.SERVER
this.loadingServerHostForm = true
await this.validateOpenProjectInstance()
if (this.isOpenProjectInstanceValid) {
const saved = await this.saveOPOptions()
if (saved) {
this.state.openproject_instance_url = this.serverHostUrlForEdit
this.formMode.server = F_MODES.VIEW
this.isFormCompleted.server = true
if (!this.isFormCompleted.opOauth) {
this.formMode.opOauth = F_MODES.EDIT
}
}
}
this.loadingServerHostForm = false
},
async saveOPOAuthClientValues() {
this.isFormStep = FORM.OP_OAUTH
await this.saveOPOptions()
if (this.isAdminConfigOk) {
this.formMode.opOauth = F_MODES.VIEW
this.isFormCompleted.opOauth = true
// if we do not have Nextcloud OAuth client yet, a new client is created
if (!this.state.nc_oauth_client) {
this.createNCOAuthClient()
}
}
},
resetOPOAuthClientValues() {
OC.dialogs.confirmDestructive(
t('integration_openproject', 'If you proceed you will need to update these settings with the new OpenProject OAuth credentials. Also, all users will need to reauthorize access to their OpenProject account.'),
t('integration_openproject', 'Replace OpenProject OAuth values'),
{
type: OC.dialogs.YES_NO_BUTTONS,
confirm: t('integration_openproject', 'Yes, replace'),
confirmClasses: 'error',
cancel: t('integration_openproject', 'Cancel'),
},
async (result) => {
if (result) {
await this.clearOPOAuthClientValues()
}
},
true,
)
},
async clearOPOAuthClientValues() {
this.isFormStep = FORM.OP_OAUTH
this.formMode.opOauth = F_MODES.EDIT
this.isFormCompleted.opOauth = false
this.state.openproject_client_id = null
this.state.openproject_client_secret = null
const saved = await this.saveOPOptions()
if (!saved) {
this.formMode.opOauth = F_MODES.VIEW
this.isFormCompleted.opOauth = true
}
},
resetAllAppValuesConfirmation() {
OC.dialogs.confirmDestructive(
t('integration_openproject', 'Are you sure that you want to reset this app and delete all settings and all connections of all Nextcloud users to OpenProject?'),
t('integration_openproject', 'Reset OpenProject Integration'),
{
type: OC.dialogs.YES_NO_BUTTONS,
confirm: t('integration_openproject', 'Yes, reset'),
confirmClasses: 'error',
cancel: t('integration_openproject', 'Cancel'),
},
async (result) => {
if (result) {
await this.resetAllAppValues()
}
},
true,
)
},
async resetAllAppValues() {
// to avoid general console errors, we need to set the form to
// editor mode so that we can update the form fields with null values
// also, form completeness should be set to false
this.formMode.opOauth = F_MODES.EDIT
this.isFormCompleted.opOauth = false
this.formMode.server = F_MODES.EDIT
this.isFormCompleted.server = false
this.state.openproject_client_id = null
this.state.openproject_client_secret = null
this.state.default_enable_navigation = false
this.state.openproject_instance_url = null
this.state.default_enable_unified_search = false
this.oPUserAppPassword = null
await this.saveOPOptions()
window.location.reload()
},
async validateOpenProjectInstance() {
const url = generateUrl('/apps/integration_openproject/is-valid-op-instance')
const response = await axios.post(url, { url: this.serverHostUrlForEdit })
this.openProjectNotReachableErrorMessageDetails = null
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'Please introduce a valid OpenProject hostname',
)
if (response.data.result === true) {
this.isOpenProjectInstanceValid = true
this.state.openproject_instance_url = this.serverHostUrlForEdit
} else {
switch (response.data.result) {
case 'invalid':
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'URL is invalid',
)
this.openProjectNotReachableErrorMessageDetails = t(
'integration_openproject',
'The URL should have the form "https://openproject.org"',
)
break
case 'not_valid_body':
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'There is no valid OpenProject instance listening at that URL, please check the Nextcloud logs',
)
break
case 'client_exception': {
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'There is no valid OpenProject instance listening at that URL, please check the Nextcloud logs',
)
this.openProjectNotReachableErrorMessageDetails = t(
'integration_openproject',
'Response:',
) + ' "' + response.data.details + '"'
break
}
case 'server_exception': {
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'Server replied with an error message, please check the Nextcloud logs',
)
this.openProjectNotReachableErrorMessageDetails = response.data.details
break
}
case 'local_remote_servers_not_allowed': {
const linkText = t('integration_openproject', 'Documentation')
const htmlLink = `<a class="link" href="https://www.openproject.org/docs/system-admin-guide/integrations/nextcloud/" target="_blank" title="${linkText}">${linkText}</a>`
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'Accessing OpenProject servers with local addresses is not allowed.',
)
this.openProjectNotReachableErrorMessageDetails = t(
'integration_openproject',
'To be able to use an OpenProject server with a local address, enable the `allow_local_remote_servers` setting. {htmlLink}.',
{ htmlLink },
null,
{ escape: false, sanitize: false },
)
break
}
case 'redirected':
{
const location = response.data.details
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'The given URL redirects to \'{location}\'. Please do not use a URL that leads to a redirect.',
{ location },
)
break
}
case 'unexpected_error':
case 'network_error':
case 'request_exception':
default: {
this.openProjectNotReachableErrorMessage = t(
'integration_openproject',
'Could not connect to the given URL, please check the Nextcloud logs',
)
this.openProjectNotReachableErrorMessageDetails = response.data.details
break
}
}
this.isOpenProjectInstanceValid = false
await this.$nextTick()
await this.$refs['openproject-oauth-instance-input']?.$refs?.textInput?.focus()
}
},
getPayloadForSavingOPOptions() {
let values = {
openproject_client_id: this.state.openproject_client_id,
openproject_client_secret: this.state.openproject_client_secret,
openproject_instance_url: this.state.openproject_instance_url,
default_enable_navigation: this.state.default_enable_navigation,
default_enable_unified_search: this.state.default_enable_unified_search,
}
if (this.state.openproject_instance_url === null && this.state.openproject_client_secret === null && this.state.openproject_client_id === null) {
// doing whole reset
values = {
...values,
setup_project_folder: false,
setup_app_password: false,
}
} else if (this.isFormStep === FORM.GROUP_FOLDER) {
if (!this.isProjectFolderSwitchEnabled) {
values = {
setup_project_folder: false,
setup_app_password: false,
}
} else if (this.isProjectFolderSwitchEnabled === true) {
values = {
setup_project_folder: !this.isProjectFolderAlreadySetup,
setup_app_password: this.opUserAppPassword !== true,
}
}
} else if (this.isFormStep === FORM.APP_PASSWORD) {
values = {
setup_app_password: true,
}
}
return values
},
async saveOPOptions() {
let success = false
const url = generateUrl('/apps/integration_openproject/admin-config')
const req = {
values: this.getPayloadForSavingOPOptions(),
}
try {
const response = await axios.put(url, req)
// after successfully saving the admin credentials, the admin config status needs to be updated
this.isAdminConfigOk = response?.data?.status === true
if (response?.data?.oPUserAppPassword) {
this.state.app_password_set = true
this.oPUserAppPassword = response?.data?.oPUserAppPassword
}
this.oPOAuthTokenRevokeStatus = response?.data?.oPOAuthTokenRevokeStatus
showSuccess(t('integration_openproject', 'OpenProject admin options saved'))
success = true
} catch (error) {
console.error()
this.isAdminConfigOk = null
this.oPOAuthTokenRevokeStatus = null
if (error.response.data.error) {
this.projectFolderSetupError = error.response.data.error
}
showError(
t('integration_openproject', 'Failed to save OpenProject admin options'),
)
}
this.notifyAboutOPOAuthTokenRevoke()
return success
},
async checkIfProjectFolderIsAlreadyReadyForSetup() {
let success = false
try {
const url = generateUrl('/apps/integration_openproject/project-folder-status')
const response = await axios.get(url)
success = response?.data?.result
} catch (error) {
console.error(error)
}
return success
},