-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathOAuthConnectButton.vue
116 lines (111 loc) · 3.27 KB
/
OAuthConnectButton.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
<template>
<NcButton v-if="!!isAdminConfigOk"
class="oauth-connect--button"
@click="onOAuthClick">
<template #icon>
<OpenInNewIcon :size="20" />
</template>
{{ t('integration_openproject', 'Connect to OpenProject') }}
</NcButton>
<div v-else class="oauth-connect--message" v-html="adminConfigNotOkMessage" /> <!-- eslint-disable-line vue/no-v-html -->
</template>
<script>
import axios from '@nextcloud/axios'
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
import { generateUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
import { translate as t } from '@nextcloud/l10n'
import '@nextcloud/dialogs/styles/toast.scss'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import dompurify from 'dompurify'
export default {
name: 'OAuthConnectButton',
components: {
NcButton,
OpenInNewIcon,
},
props: {
isAdminConfigOk: {
type: Boolean,
required: true,
},
fileInfo: {
type: Object,
default() {
return {}
},
},
},
computed: {
adminConfigNotOkMessage() {
if (getCurrentUser().isAdmin) {
const linkText = t('integration_openproject', 'Administration Settings > OpenProject')
const url = generateUrl('/settings/admin/openproject')
const htmlLink = `<a class="link" href="${url}" target="_blank" title="${linkText}">${linkText}</a>`
const hintText = t('integration_openproject', 'Some OpenProject Integration application settings are not working. '
+ 'Configure the OpenProject Integration in: {htmlLink}', { htmlLink }, null, { escape: false, sanitize: false })
return dompurify.sanitize(hintText, { ADD_ATTR: ['target'] })
}
return t('integration_openproject', 'Some OpenProject Integration application settings are not working.'
+ ' Please contact your Nextcloud administrator.')
},
},
methods: {
getOauthJourneyStartingPage() {
if (window.location.pathname.includes('dashboard')) {
return { page: 'dashboard' }
}
if (window.location.pathname.includes('apps/files') && this.fileInfo.id !== undefined) {
return { page: 'files', file: this.fileInfo }
}
if (window.location.pathname.includes('apps/files') && Object.keys(this.fileInfo).length === 0) {
return { page: 'files' }
}
if (window.location.pathname.includes('call')) {
return { page: 'spreed', callUrl: window.location.href }
}
return { page: 'settings' }
},
async onOAuthClick() {
const url = generateUrl('/apps/integration_openproject/op-oauth-url')
axios.get(url)
.then((result) => {
const req = {
values: {
oauth_journey_starting_page: JSON.stringify(this.getOauthJourneyStartingPage()),
},
}
const url = generateUrl('/apps/integration_openproject/config')
axios.put(url, req)
.then(() => {
window.location.replace(result.data)
})
})
.catch((error) => {
showError(
t('integration_openproject', 'Failed to redirect to OpenProject')
+ ': ' + error.message
)
})
},
},
}
</script>
<style lang="scss" scoped>
.oauth-connect {
&--message {
font-size: 1rem;
text-align: center;
font-weight: 400;
padding: 0 18px;
line-height: 1.4rem;
}
}
</style>
<style>
.link {
color: #1a67a3 !important;
font-style: italic;
}
</style>