Skip to content

Commit 849a38b

Browse files
nvazquezPearl1594
authored andcommitted
UI: Add option to Login to a specific Project view via setting on config.json (apache#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 3cea827 commit 849a38b

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
@@ -96,6 +96,7 @@
9696
"basicZoneEnabled": true,
9797
"multipleServer": false,
9898
"allowSettingTheme": true,
99+
"displayProjectFieldOnLogin": false,
99100
"imageSelectionInterface": "modern",
100101
"showUserCategoryForModernImageSelection": true,
101102
"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 />
@@ -243,7 +255,8 @@ export default {
243255
forgotPasswordEnabled: false,
244256
loginTitle: this.$config.loginTitle,
245257
buildVersion: this.$config.buildVersion,
246-
logoPath: this.$config.logo
258+
logoPath: this.$config.logo,
259+
project: null
247260
}
248261
},
249262
created () {
@@ -268,7 +281,8 @@ export default {
268281
this.form = reactive({
269282
server: (this.server.apiHost || '') + this.server.apiBase,
270283
username: this.$route.query?.username || '',
271-
domain: this.$route.query?.domain || ''
284+
domain: this.$route.query?.domain || '',
285+
project: null
272286
})
273287
this.rules = reactive({})
274288
this.setRules()
@@ -468,7 +482,7 @@ export default {
468482
})
469483
})
470484
},
471-
loginSuccess (res) {
485+
async loginSuccess (res) {
472486
this.$notification.destroy()
473487
this.$store.commit('SET_COUNT_NOTIFY', 0)
474488
if (store.getters.twoFaEnabled === true && store.getters.twoFaProvider !== '' && store.getters.twoFaProvider !== undefined) {
@@ -479,9 +493,33 @@ export default {
479493
this.$router.push({ path: '/firstLogin' }).catch(() => {})
480494
} else {
481495
this.$store.commit('SET_LOGIN_FLAG', true)
496+
const values = toRaw(this.form)
497+
if (values.project) {
498+
await this.getProject(values.project)
499+
this.$store.dispatch('ProjectView', this.project.id)
500+
this.$store.dispatch('SetProject', this.project)
501+
this.$store.dispatch('ToggleTheme', this.project.id === undefined ? 'light' : 'dark')
502+
}
482503
this.$router.push({ path: '/dashboard' }).catch(() => {})
483504
}
484505
},
506+
getProject (projectName) {
507+
return new Promise((resolve, reject) => {
508+
api('listProjects', {
509+
response: 'json',
510+
domainId: this.selectedDomain,
511+
details: 'min'
512+
}).then((response) => {
513+
const projects = response.listprojectsresponse.project
514+
this.project = projects.filter(project => project.name === projectName)?.[0] || null
515+
resolve(this.project)
516+
}).catch((error) => {
517+
this.$notifyError(error)
518+
}).finally(() => {
519+
this.loading = false
520+
})
521+
})
522+
},
485523
requestFailed (err) {
486524
if (err && err.response && err.response.data && err.response.data.loginresponse) {
487525
const error = err.response.data.loginresponse.errorcode + ': ' + err.response.data.loginresponse.errortext

0 commit comments

Comments
 (0)