Skip to content

Commit 11455f6

Browse files
nvazquezPearl1594
andauthored
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 <[email protected]>
1 parent 22b753e commit 11455f6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

ui/public/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"basicZoneEnabled": true,
9999
"multipleServer": false,
100100
"allowSettingTheme": true,
101+
"displayProjectFieldOnLogin": false,
101102
"imageSelectionInterface": "modern",
102103
"showUserCategoryForModernImageSelection": true,
103104
"showAllCategoryForModernImageSelection": false,

ui/src/views/auth/Login.vue

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@
9191
type="text"
9292
:placeholder="$t('label.domain')"
9393
v-model:value="form.domain"
94+
>
95+
<template #prefix>
96+
<project-outlined />
97+
</template>
98+
</a-input>
99+
</a-form-item>
100+
<a-form-item ref="project" name="project" v-if="$config.displayProjectFieldOnLogin">
101+
<a-input
102+
size="large"
103+
type="text"
104+
:placeholder="$t('label.project')"
105+
v-model:value="form.project"
94106
>
95107
<template #prefix>
96108
<block-outlined />
@@ -230,7 +242,8 @@ export default {
230242
loginType: 0
231243
},
232244
server: '',
233-
forgotPasswordEnabled: false
245+
forgotPasswordEnabled: false,
246+
project: null
234247
}
235248
},
236249
created () {
@@ -255,7 +268,8 @@ export default {
255268
this.form = reactive({
256269
server: (this.server.apiHost || '') + this.server.apiBase,
257270
username: this.$route.query?.username || '',
258-
domain: this.$route.query?.domain || ''
271+
domain: this.$route.query?.domain || '',
272+
project: null
259273
})
260274
this.rules = reactive({})
261275
this.setRules()
@@ -447,7 +461,7 @@ export default {
447461
})
448462
})
449463
},
450-
loginSuccess (res) {
464+
async loginSuccess (res) {
451465
this.$notification.destroy()
452466
this.$store.commit('SET_COUNT_NOTIFY', 0)
453467
if (store.getters.twoFaEnabled === true && store.getters.twoFaProvider !== '' && store.getters.twoFaProvider !== undefined) {
@@ -456,9 +470,33 @@ export default {
456470
this.$router.push({ path: '/setup2FA' }).catch(() => {})
457471
} else {
458472
this.$store.commit('SET_LOGIN_FLAG', true)
473+
const values = toRaw(this.form)
474+
if (values.project) {
475+
await this.getProject(values.project)
476+
this.$store.dispatch('ProjectView', this.project.id)
477+
this.$store.dispatch('SetProject', this.project)
478+
this.$store.dispatch('ToggleTheme', this.project.id === undefined ? 'light' : 'dark')
479+
}
459480
this.$router.push({ path: '/dashboard' }).catch(() => {})
460481
}
461482
},
483+
getProject (projectName) {
484+
return new Promise((resolve, reject) => {
485+
api('listProjects', {
486+
response: 'json',
487+
domainId: this.selectedDomain,
488+
details: 'min'
489+
}).then((response) => {
490+
const projects = response.listprojectsresponse.project
491+
this.project = projects.filter(project => project.name === projectName)?.[0] || null
492+
resolve(this.project)
493+
}).catch((error) => {
494+
this.$notifyError(error)
495+
}).finally(() => {
496+
this.loading = false
497+
})
498+
})
499+
},
462500
requestFailed (err) {
463501
if (err && err.response && err.response.data && err.response.data.loginresponse) {
464502
const error = err.response.data.loginresponse.errorcode + ': ' + err.response.data.loginresponse.errortext

0 commit comments

Comments
 (0)