Skip to content
This repository was archived by the owner on Jan 20, 2021. It is now read-only.

Commit bcf6e55

Browse files
davidjumaniyadvr
andauthored
saml: Adding Account Switcher for SAML Accounts (#575)
Adding Account Switcher for SAML Accounts in multiple domains matching the same saml user Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 45019cd commit bcf6e55

3 files changed

Lines changed: 129 additions & 1 deletion

File tree

src/components/header/ProjectMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default {
109109
<style lang="less" scoped>
110110
.project {
111111
&-select {
112-
width: 40vw;
112+
width: 30vw;
113113
}
114114
115115
&-icon {
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
<template>
19+
<span class="header-notice-opener" v-if="showSwitcher">
20+
<a-select
21+
class="domain-select"
22+
:loading="loading"
23+
:defaultValue="currentAccount"
24+
:value="currentAccount"
25+
@change="changeAccount"
26+
@focus="fetchData" >
27+
28+
<a-tooltip placement="bottom" slot="suffixIcon">
29+
<template slot="title">
30+
<span>{{ $t('label.domain') }}</span>
31+
</template>
32+
<span style="font-size: 20px; color: #999; margin-top: -5px">
33+
<a-icon v-if="!loading" type="block" />
34+
<a-icon v-else type="loading" />
35+
</span>
36+
</a-tooltip>
37+
38+
<a-select-option v-for="(account, index) in samlAccounts" :key="index">
39+
{{ `${account.accountName} (${account.domainName})` }}
40+
</a-select-option>
41+
</a-select>
42+
</span>
43+
</template>
44+
45+
<script>
46+
import store from '@/store'
47+
import { api } from '@/api'
48+
import _ from 'lodash'
49+
50+
export default {
51+
name: 'SamlDomainSwitcher',
52+
data () {
53+
return {
54+
showSwitcher: false,
55+
samlAccounts: [],
56+
currentAccount: '',
57+
loading: false
58+
}
59+
},
60+
mounted () {
61+
this.fetchData()
62+
},
63+
methods: {
64+
fetchData () {
65+
var page = 1
66+
const samlAccounts = []
67+
const getNextPage = () => {
68+
this.loading = true
69+
api('listAndSwitchSamlAccount', { listAll: true, details: 'min', page: page, pageSize: 500 }).then(json => {
70+
if (json && json.listandswitchsamlaccountresponse && json.listandswitchsamlaccountresponse.samluseraccount) {
71+
samlAccounts.push(...json.listandswitchsamlaccountresponse.samluseraccount)
72+
}
73+
if (samlAccounts.length < json.listandswitchsamlaccountresponse.count) {
74+
page++
75+
getNextPage()
76+
}
77+
}).catch(error => {
78+
console.log(error)
79+
}).finally(() => {
80+
if (samlAccounts.length < 2) {
81+
this.showSwitcher = false
82+
return
83+
}
84+
this.samlAccounts = _.orderBy(samlAccounts, ['domainPath'], ['asc'])
85+
const currentAccount = this.samlAccounts.filter(x => {
86+
return x.userId === store.getters.userInfo.id
87+
})[0]
88+
this.currentAccount = `${currentAccount.accountName} (${currentAccount.domainName})`
89+
this.loading = false
90+
this.showSwitcher = true
91+
})
92+
}
93+
getNextPage()
94+
},
95+
changeAccount (index) {
96+
const account = this.samlAccounts[index]
97+
api('listAndSwitchSamlAccount', {}, 'POST', {
98+
userid: account.userId,
99+
domainid: account.domainId
100+
}).then(response => {
101+
store.dispatch('GetInfo').then(() => {
102+
this.$message.success(`Switched to "${account.accountName} (${account.domainPath})"`)
103+
this.$router.go()
104+
})
105+
})
106+
}
107+
}
108+
}
109+
</script>
110+
111+
<style lang="less" scoped>
112+
.domain {
113+
&-select {
114+
width: 20vw;
115+
}
116+
117+
&-icon {
118+
font-size: 20px;
119+
line-height: 1;
120+
padding-top: 5px;
121+
padding-right: 5px;
122+
}
123+
}
124+
</style>

src/components/page/GlobalHeader.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
:type="collapsed ? 'menu-unfold' : 'menu-fold'"
3030
@click="toggle"/>
3131
<project-menu v-if="device !== 'mobile'" />
32+
<saml-domain-switcher style="margin-left: 20px" />
3233
<user-menu></user-menu>
3334
</div>
3435
<div v-else :class="['top-nav-header-index', theme]">
@@ -48,6 +49,7 @@
4849
@click="toggle"></a-icon>
4950
</div>
5051
<project-menu v-if="device !== 'mobile'" />
52+
<saml-domain-switcher style="margin-left: 20px" />
5153
<user-menu></user-menu>
5254
</div>
5355
</div>
@@ -60,6 +62,7 @@ import Breadcrumb from '@/components/widgets/Breadcrumb'
6062
import Logo from '../header/Logo'
6163
import SMenu from '../menu/'
6264
import ProjectMenu from '../header/ProjectMenu'
65+
import SamlDomainSwitcher from '../header/SamlDomainSwitcher'
6366
import UserMenu from '../header/UserMenu'
6467
6568
import { mixin } from '@/utils/mixin.js'
@@ -71,6 +74,7 @@ export default {
7174
Logo,
7275
SMenu,
7376
ProjectMenu,
77+
SamlDomainSwitcher,
7478
UserMenu
7579
},
7680
mixins: [mixin],

0 commit comments

Comments
 (0)