2020-05-08 20:43:51 +02:00
|
|
|
import {CONFIG} from '../mutation-types'
|
2020-10-11 12:13:35 +02:00
|
|
|
import {HTTPFactory} from '@/http-common'
|
2020-11-21 17:38:40 +01:00
|
|
|
import {objectToCamelCase} from '@/helpers/case'
|
2021-08-15 12:02:29 +02:00
|
|
|
import {redirectToProvider} from '../../helpers/redirectToProvider'
|
2021-10-26 22:58:02 +02:00
|
|
|
import {parseURL} from 'ufo'
|
2020-05-08 20:43:51 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state: () => ({
|
|
|
|
// These are the api defaults.
|
|
|
|
version: '',
|
|
|
|
frontendUrl: '',
|
|
|
|
motd: '',
|
|
|
|
linkSharingEnabled: true,
|
|
|
|
maxFileSize: '20MB',
|
|
|
|
registrationEnabled: true,
|
|
|
|
availableMigrators: [],
|
|
|
|
taskAttachmentsEnabled: true,
|
2020-05-29 18:49:50 +02:00
|
|
|
totpEnabled: true,
|
2020-05-31 21:17:10 +02:00
|
|
|
enabledBackgroundProviders: [],
|
2020-07-18 21:39:30 +02:00
|
|
|
legal: {
|
|
|
|
imprintUrl: '',
|
|
|
|
privacyPolicyUrl: '',
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2020-10-03 14:58:33 +02:00
|
|
|
caldavEnabled: false,
|
2021-08-11 21:08:18 +02:00
|
|
|
userDeletionEnabled: true,
|
2021-09-26 13:44:13 +02:00
|
|
|
taskCommentsEnabled: true,
|
2020-11-21 17:38:40 +01:00
|
|
|
auth: {
|
|
|
|
local: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
openidConnect: {
|
|
|
|
enabled: false,
|
|
|
|
redirectUrl: '',
|
|
|
|
providers: [],
|
|
|
|
},
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
}),
|
2021-10-26 22:58:02 +02:00
|
|
|
getters: {
|
|
|
|
migratorsEnabled: state => state.availableMigrators?.length > 0,
|
|
|
|
apiBase() {
|
|
|
|
const {host, protocol} = parseURL(window.API_URL)
|
|
|
|
return protocol + '//' + host
|
|
|
|
},
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
mutations: {
|
|
|
|
[CONFIG](state, config) {
|
|
|
|
state.version = config.version
|
|
|
|
state.frontendUrl = config.frontend_url
|
|
|
|
state.motd = config.motd
|
|
|
|
state.linkSharingEnabled = config.link_sharing_enabled
|
|
|
|
state.maxFileSize = config.max_file_size
|
|
|
|
state.registrationEnabled = config.registration_enabled
|
|
|
|
state.availableMigrators = config.available_migrators
|
|
|
|
state.taskAttachmentsEnabled = config.task_attachments_enabled
|
2020-05-29 18:49:50 +02:00
|
|
|
state.totpEnabled = config.totp_enabled
|
2020-05-31 21:17:10 +02:00
|
|
|
state.enabledBackgroundProviders = config.enabled_background_providers
|
2020-07-18 21:39:30 +02:00
|
|
|
state.legal.imprintUrl = config.legal.imprint_url
|
|
|
|
state.legal.privacyPolicyUrl = config.legal.privacy_policy_url
|
2020-10-03 14:58:33 +02:00
|
|
|
state.caldavEnabled = config.caldav_enabled
|
2021-08-11 21:08:18 +02:00
|
|
|
state.userDeletionEnabled = config.user_deletion_enabled
|
2021-09-26 13:44:13 +02:00
|
|
|
state.taskCommentsEnabled = config.task_comments_enabled
|
2020-11-21 17:38:40 +01:00
|
|
|
const auth = objectToCamelCase(config.auth)
|
|
|
|
state.auth.local.enabled = auth.local.enabled
|
|
|
|
state.auth.openidConnect.enabled = auth.openidConnect.enabled
|
|
|
|
state.auth.openidConnect.redirectUrl = auth.openidConnect.redirectUrl
|
2021-08-19 21:35:38 +02:00
|
|
|
state.auth.openidConnect.providers = auth.openidConnect.providers
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
2021-10-11 19:37:20 +02:00
|
|
|
async update(ctx) {
|
2020-10-11 12:13:35 +02:00
|
|
|
const HTTP = HTTPFactory()
|
|
|
|
|
2021-10-26 22:58:02 +02:00
|
|
|
const {data: info} = await HTTP.get('info')
|
2021-10-11 19:37:20 +02:00
|
|
|
ctx.commit(CONFIG, info)
|
|
|
|
return info
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
2021-10-11 19:37:20 +02:00
|
|
|
|
2021-08-15 12:02:29 +02:00
|
|
|
redirectToProviderIfNothingElseIsEnabled(ctx) {
|
|
|
|
if (ctx.state.auth.local.enabled === false &&
|
|
|
|
ctx.state.auth.openidConnect.enabled &&
|
|
|
|
ctx.state.auth.openidConnect.providers &&
|
|
|
|
ctx.state.auth.openidConnect.providers.length === 1 &&
|
|
|
|
window.location.pathname.startsWith('/login') // Kinda hacky, but prevents an endless loop.
|
|
|
|
) {
|
|
|
|
redirectToProvider(ctx.state.auth.openidConnect.providers[0], ctx.state.auth.openidConnect.redirectUrl)
|
|
|
|
}
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
}
|