UI: Add option to Login to a specific Project view via setting on config.json (#10935)

* UI: Login to a specific Project view

* Fix project icon

* Add the option to display project on login on the config.json file

---------

Co-authored-by: Pearl Dsilva <pearl1594@gmail.com>
This commit is contained in:
Nicolas Vazquez 2025-07-24 11:42:25 -03:00 committed by GitHub
parent 22b753e930
commit 11455f6d49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 3 deletions

View File

@ -98,6 +98,7 @@
"basicZoneEnabled": true, "basicZoneEnabled": true,
"multipleServer": false, "multipleServer": false,
"allowSettingTheme": true, "allowSettingTheme": true,
"displayProjectFieldOnLogin": false,
"imageSelectionInterface": "modern", "imageSelectionInterface": "modern",
"showUserCategoryForModernImageSelection": true, "showUserCategoryForModernImageSelection": true,
"showAllCategoryForModernImageSelection": false, "showAllCategoryForModernImageSelection": false,

View File

@ -91,6 +91,18 @@
type="text" type="text"
:placeholder="$t('label.domain')" :placeholder="$t('label.domain')"
v-model:value="form.domain" v-model:value="form.domain"
>
<template #prefix>
<project-outlined />
</template>
</a-input>
</a-form-item>
<a-form-item ref="project" name="project" v-if="$config.displayProjectFieldOnLogin">
<a-input
size="large"
type="text"
:placeholder="$t('label.project')"
v-model:value="form.project"
> >
<template #prefix> <template #prefix>
<block-outlined /> <block-outlined />
@ -230,7 +242,8 @@ export default {
loginType: 0 loginType: 0
}, },
server: '', server: '',
forgotPasswordEnabled: false forgotPasswordEnabled: false,
project: null
} }
}, },
created () { created () {
@ -255,7 +268,8 @@ export default {
this.form = reactive({ this.form = reactive({
server: (this.server.apiHost || '') + this.server.apiBase, server: (this.server.apiHost || '') + this.server.apiBase,
username: this.$route.query?.username || '', username: this.$route.query?.username || '',
domain: this.$route.query?.domain || '' domain: this.$route.query?.domain || '',
project: null
}) })
this.rules = reactive({}) this.rules = reactive({})
this.setRules() this.setRules()
@ -447,7 +461,7 @@ export default {
}) })
}) })
}, },
loginSuccess (res) { async loginSuccess (res) {
this.$notification.destroy() this.$notification.destroy()
this.$store.commit('SET_COUNT_NOTIFY', 0) this.$store.commit('SET_COUNT_NOTIFY', 0)
if (store.getters.twoFaEnabled === true && store.getters.twoFaProvider !== '' && store.getters.twoFaProvider !== undefined) { if (store.getters.twoFaEnabled === true && store.getters.twoFaProvider !== '' && store.getters.twoFaProvider !== undefined) {
@ -456,9 +470,33 @@ export default {
this.$router.push({ path: '/setup2FA' }).catch(() => {}) this.$router.push({ path: '/setup2FA' }).catch(() => {})
} else { } else {
this.$store.commit('SET_LOGIN_FLAG', true) this.$store.commit('SET_LOGIN_FLAG', true)
const values = toRaw(this.form)
if (values.project) {
await this.getProject(values.project)
this.$store.dispatch('ProjectView', this.project.id)
this.$store.dispatch('SetProject', this.project)
this.$store.dispatch('ToggleTheme', this.project.id === undefined ? 'light' : 'dark')
}
this.$router.push({ path: '/dashboard' }).catch(() => {}) this.$router.push({ path: '/dashboard' }).catch(() => {})
} }
}, },
getProject (projectName) {
return new Promise((resolve, reject) => {
api('listProjects', {
response: 'json',
domainId: this.selectedDomain,
details: 'min'
}).then((response) => {
const projects = response.listprojectsresponse.project
this.project = projects.filter(project => project.name === projectName)?.[0] || null
resolve(this.project)
}).catch((error) => {
this.$notifyError(error)
}).finally(() => {
this.loading = false
})
})
},
requestFailed (err) { requestFailed (err) {
if (err && err.response && err.response.data && err.response.data.loginresponse) { if (err && err.response && err.response.data && err.response.data.loginresponse) {
const error = err.response.data.loginresponse.errorcode + ': ' + err.response.data.loginresponse.errortext const error = err.response.data.loginresponse.errorcode + ': ' + err.response.data.loginresponse.errortext