diff --git a/src/assets/img/auth/cas_logo.png b/src/assets/img/auth/cas_logo.png new file mode 100644 index 000000000..c6288af5b Binary files /dev/null and b/src/assets/img/auth/cas_logo.png differ diff --git a/src/assets/img/auth/dingtalk_logo.webp b/src/assets/img/auth/dingtalk_logo.webp new file mode 100644 index 000000000..3c409328e Binary files /dev/null and b/src/assets/img/auth/dingtalk_logo.webp differ diff --git a/src/assets/img/auth/feishu_logo.png b/src/assets/img/auth/feishu_logo.png new file mode 100644 index 000000000..1b9b51cf4 Binary files /dev/null and b/src/assets/img/auth/feishu_logo.png differ diff --git a/src/assets/img/auth/lark_logo.png b/src/assets/img/auth/lark_logo.png new file mode 100644 index 000000000..d33daa3d6 Binary files /dev/null and b/src/assets/img/auth/lark_logo.png differ diff --git a/src/assets/img/auth/ldap_logo.png b/src/assets/img/auth/ldap_logo.png new file mode 100644 index 000000000..a9225bb7e Binary files /dev/null and b/src/assets/img/auth/ldap_logo.png differ diff --git a/src/assets/img/auth/oauth2_logo.png b/src/assets/img/auth/oauth2_logo.png new file mode 100644 index 000000000..0c0979bb9 Binary files /dev/null and b/src/assets/img/auth/oauth2_logo.png differ diff --git a/src/assets/img/auth/oidc_logo.png b/src/assets/img/auth/oidc_logo.png new file mode 100644 index 000000000..b21c90a3d Binary files /dev/null and b/src/assets/img/auth/oidc_logo.png differ diff --git a/src/assets/img/auth/passkey_logo.png b/src/assets/img/auth/passkey_logo.png new file mode 100644 index 000000000..7e2f4e4a9 Binary files /dev/null and b/src/assets/img/auth/passkey_logo.png differ diff --git a/src/assets/img/auth/radius_logo.png b/src/assets/img/auth/radius_logo.png new file mode 100644 index 000000000..8d035ce2f Binary files /dev/null and b/src/assets/img/auth/radius_logo.png differ diff --git a/src/assets/img/auth/saml2_logo.png b/src/assets/img/auth/saml2_logo.png new file mode 100644 index 000000000..91dc418bb Binary files /dev/null and b/src/assets/img/auth/saml2_logo.png differ diff --git a/src/assets/img/auth/slack_logo.png b/src/assets/img/auth/slack_logo.png new file mode 100644 index 000000000..33399287e Binary files /dev/null and b/src/assets/img/auth/slack_logo.png differ diff --git a/src/assets/img/auth/wecom_logo.png b/src/assets/img/auth/wecom_logo.png new file mode 100644 index 000000000..b3b435152 Binary files /dev/null and b/src/assets/img/auth/wecom_logo.png differ diff --git a/src/views/settings/Auth/AuthItem.vue b/src/views/settings/Auth/AuthItem.vue new file mode 100644 index 000000000..4049235c9 --- /dev/null +++ b/src/views/settings/Auth/AuthItem.vue @@ -0,0 +1,117 @@ + + + + + diff --git a/src/views/settings/Auth/Basic.vue b/src/views/settings/Auth/Basic.vue index 3c20218f8..8e5b5e435 100644 --- a/src/views/settings/Auth/Basic.vue +++ b/src/views/settings/Auth/Basic.vue @@ -1,23 +1,43 @@ - diff --git a/src/views/settings/Auth/const.js b/src/views/settings/Auth/const.js index aedcbd20c..492fa2346 100644 --- a/src/views/settings/Auth/const.js +++ b/src/views/settings/Auth/const.js @@ -1,5 +1,8 @@ -import { Select2 } from '@/components/Form/FormFields' import store from '@/store' +import { Select2 } from '@/components/Form/FormFields' +import { ObjectLocalStorage } from '@/utils/common' + +export const authLocalStorage = new ObjectLocalStorage('auth') export function getOrgSelect2Meta() { return { @@ -18,3 +21,137 @@ export function getOrgSelect2Meta() { } } } + +export const getAuthItem = (vm) => { + const storageItems = authLocalStorage.get('authItems') + + if (storageItems) { + return storageItems + } + + const ldapHABackends = [ + { + logo: require('@/assets/img/auth/ldap_logo.png'), + title: vm.$t('LDAP HA'), + authKey: 'AUTH_LDAP_HA', + description: '', + enabled: false + } + ] + + const extraBackends = [ + { + logo: require('@/assets/img/auth/oidc_logo.png'), + title: vm.$t('OIDC'), + authKey: 'AUTH_OPENID', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/saml2_logo.png'), + title: vm.$t('SAML2'), + authKey: 'AUTH_SAML2', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/oauth2_logo.png'), + title: vm.$t('OAuth2'), + authKey: 'AUTH_OAUTH2', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/wecom_logo.png'), + title: vm.$t('WeCom'), + authKey: 'AUTH_WECOM', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/dingtalk_logo.webp'), + title: vm.$t('DingTalk'), + authKey: 'AUTH_DINGTALK', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/feishu_logo.png'), + title: vm.$t('FeiShu'), + authKey: 'AUTH_FEISHU', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/lark_logo.png'), + title: vm.$t('Lark'), + authKey: 'AUTH_LARK', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/slack_logo.png'), + title: vm.$t('Slack'), + authKey: 'AUTH_SLACK', + description: '', + enabled: false + }, + { + logo: require('@/assets/img/auth/radius_logo.png'), + title: vm.$t('Radius'), + authKey: 'AUTH_RADIUS', + description: '', + enabled: false + } + ] + + const authItems = [ + { + logo: require('@/assets/img/auth/ldap_logo.png'), + title: vm.$t('Ldap'), + authKey: 'AUTH_LDAP', + description: '', + enabled: true + }, + { + logo: require('@/assets/img/auth/cas_logo.png'), + title: vm.$t('CAS'), + authKey: 'AUTH_CAS', + description: '', + enabled: true + }, + { + logo: require('@/assets/img/auth/passkey_logo.png'), + title: vm.$t('Passkey'), + authKey: 'AUTH_PASSKEY', + description: '', + enabled: true + } + ] + + if (store.getters.hasValidLicense) { + // 把 AUTH_LDAP_HA 加到 authItems 中的 AUTH_LDAP 后面 + const ldapIndex = authItems.findIndex(item => item.authKey === 'AUTH_LDAP') + + if (ldapIndex !== -1) { + authItems.splice(ldapIndex + 1, 0, ...ldapHABackends) + } + + authItems.push(...extraBackends) + } + + authLocalStorage.set('authItems', authItems) + + return authItems +} + +export const setAuthItem = (value, authKey) => { + const authItems = authLocalStorage.get('authItems') + const authItem = authItems.find(item => item.authKey === authKey) + + if (authItem) { + authItem.enabled = value + authLocalStorage.set('authItems', authItems) + } +} + diff --git a/src/views/settings/Auth/index.vue b/src/views/settings/Auth/index.vue index 8dde8d8c6..88268c814 100644 --- a/src/views/settings/Auth/index.vue +++ b/src/views/settings/Auth/index.vue @@ -1,7 +1,7 @@ @@ -24,6 +24,7 @@ import SAML2 from './SAML2' import OAuth2 from './OAuth2' import Passkey from './Passkey.vue' import Slack from './Slack.vue' +import { authLocalStorage } from './const' export default { components: { @@ -46,10 +47,27 @@ export default { Slack }, data() { - let extraBackends = [] - let ldapHABackends = [] - if (this.$store.getters.hasValidLicense) { - extraBackends = [ + return { + loading: true, + activeMenu: 'Basic', + defaultBackends: [ + { + title: this.$t('Ldap'), + name: 'LDAP', + key: 'AUTH_LDAP' + }, + { + title: this.$t('CAS'), + name: 'CAS', + key: 'AUTH_CAS' + }, + { + title: this.$t('Passkey'), + name: 'Passkey', + key: 'AUTH_PASSKEY' + } + ], + extraBackends: [ { title: this.$t('OIDC'), name: 'OIDC', @@ -95,41 +113,15 @@ export default { name: 'Radius', key: 'AUTH_RADIUS' } - ] - ldapHABackends = [ + ], + ldapHABackends: [ { title: this.$t('LDAP HA'), name: 'LdapHA', key: 'AUTH_LDAP_HA' } - ] - } - return { - loading: true, - activeMenu: 'Basic', - submenu: [ - { - title: this.$t('Basic'), - name: 'Basic' - }, - { - title: this.$t('Ldap'), - name: 'LDAP', - key: 'AUTH_LDAP' - }, - ...ldapHABackends, - { - title: this.$t('CAS'), - name: 'CAS', - key: 'AUTH_CAS' - }, - { - title: this.$t('Passkey'), - name: 'Passkey', - key: 'AUTH_PASSKEY' - }, - ...extraBackends - ] + ], + submenu: [] } }, computed: { @@ -137,6 +129,9 @@ export default { return {} } }, + created() { + this.filterAuthItems() + }, mounted() { this.$axios.get('/api/v1/settings/setting/?category=auth').then(res => { for (const item of this.submenu) { @@ -152,7 +147,45 @@ export default { this.loading = false }) }, - methods: {} + methods: { + updateActiveMenu(key, status) { + const targetTab = + this.extraBackends.find((item) => item.key === key) || + this.ldapHABackends.find((item) => item.key === key) || + this.defaultBackends.find((item) => item.key === key) + + status ? this.submenu.push(targetTab) : this.submenu.splice(this.submenu.indexOf(targetTab), 1) + }, + filterAuthItems() { + const authItems = authLocalStorage.get('authItems') + + const defaultBackends = this.defaultBackends.filter((defaultItem) => { + const authItem = authItems.find((item) => item.enabled && item.authKey === defaultItem.key) + + return authItem + }) + const ldapHABackends = this.ldapHABackends.filter((ldapHABackendItem) => { + const authItem = authItems.find((item) => item.enabled && item.authKey === ldapHABackendItem.key) + + return authItem + }) + const extraBackends = this.extraBackends.filter((extraItem) => { + const authItem = authItems.find((item) => item.enabled && item.authKey === extraItem.key) + + return authItem + }) + + this.submenu = [ + { + title: this.$t('Basic'), + name: 'Basic' + }, + ...defaultBackends, + ...ldapHABackends, + ...extraBackends + ] + } + } }