🔨 perf(Oauth2): 支持配置创建账号配置权限组

This commit is contained in:
bwcx_jzy 2024-04-20 12:49:35 +08:00
parent 7751eb3bf4
commit 5d258913fa
6 changed files with 229 additions and 74 deletions

View File

@ -12,6 +12,7 @@
6. 【server】修复 系统管理中用户管理中登录日志无法筛选
7. 【server】优化 用户登录记录操作日志(保证操作监控能记录)
8. 【server】修复 系统管理中用户登录日志无法分页
9. 【server】优化 Oauth2 支持配置创建账号配置权限组
------

View File

@ -300,7 +300,7 @@ public class LoginControl extends BaseServerController implements InitializingBe
if (userModel == null) {
BaseOauth2Config oauth2Config = Oauth2Factory.getConfig(provide);
if (oauth2Config.autoCreteUser()) {
userModel = this.createUser(username, authUser, provide);
userModel = this.createUser(username, authUser, provide, oauth2Config.getPermissionGroup());
} else {
return new JsonMessage<>(400, username + " 用户不存在请联系管理创建");
}
@ -345,12 +345,13 @@ public class LoginControl extends BaseServerController implements InitializingBe
/**
* oauth2 创建用户账号
*
* @param username 用户名
* @param authUser 平台信息
* @param source 来源平台
* @param username 用户名
* @param authUser 平台信息
* @param source 来源平台
* @param permissionGroup 权限组
* @return 用户
*/
private UserModel createUser(String username, AuthUser authUser, String source) {
private UserModel createUser(String username, AuthUser authUser, String source, String permissionGroup) {
// 创建用户
UserModel where = new UserModel();
where.setSystemUser(1);
@ -368,6 +369,11 @@ public class LoginControl extends BaseServerController implements InitializingBe
userModel.setSystemUser(0);
userModel.setParent(first.getId());
userModel.setSource(source);
// 绑定权限组
List<String> permissionGroupList = StrUtil.split(permissionGroup, StrUtil.AT, true, true);
if (CollUtil.isNotEmpty(permissionGroupList)) {
userModel.setPermissionGroup(CollUtil.join(permissionGroupList, StrUtil.AT, StrUtil.AT, StrUtil.AT));
}
BaseServerController.resetInfo(first);
userService.insert(userModel);
return userModel;
@ -378,7 +384,7 @@ public class LoginControl extends BaseServerController implements InitializingBe
List<UserWorkspaceModel> bindWorkspaceModels = userService.myWorkspace(userModel);
Assert.notEmpty(bindWorkspaceModels, "当前账号没有绑定任何工作空间,请联系管理员处理");
UserLoginDto userLoginDto = userService.getUserJwtId(userModel);
// UserLoginDto userLoginDto = new UserLoginDto(JwtUtil.builder(userModel, jwtId), jwtId);
// UserLoginDto userLoginDto = new UserLoginDto(JwtUtil.builder(userModel, jwtId), jwtId);
userLoginDto.setBindWorkspaceModels(bindWorkspaceModels);
//
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);

View File

@ -65,6 +65,10 @@ public abstract class BaseOauth2Config {
*/
protected Boolean autoCreteUser;
protected Boolean ignoreCheckState;
/**
* 创建用户后自动关联权限组
*/
protected String permissionGroup;
/**

View File

@ -217,7 +217,9 @@ const getLoginConfig = () => {
const p = h('p', { innerHTML: demo.msg }, [])
$notification.info({
message: '温馨提示',
description: h('div', {}, [p])
description: h('div', {}, [p]),
key: 'login-tip',
duration: null
})
loginForm.loginName = demo.user
}
@ -389,30 +391,6 @@ const checkHasLoginInfo = () => {
}
}
const close = () => {
console.log('Notification was closed. Either the close button was clicked or duration time elapsed.')
}
const openNotification = () => {
const key = `open${Date.now()}`
$notification.open({
message: 'Notification Title',
description:
'A function will be be called after the notification is closed (automatically after the "duration" time of manually).',
btn: () =>
h(
Button,
{
type: 'primary',
size: 'small',
onClick: () => $notification.close(key)
},
{ default: () => 'Confirm' }
),
key,
onClose: close
})
}
const listener = () => {
if (document.hidden || document.visibilityState === 'hidden') {
//this.hidden()

View File

@ -30,16 +30,36 @@
placeholder="请输入回调重定向 url [redirectUri]"
/>
</a-form-item>
<!-- <a-form-item label="登录url">
<a-input :value="`${this.host}/oauth2-render-github`" type="text" />
</a-form-item> -->
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="dingtalk.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="dingtalk.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="dingtalk.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="权限组" name="permissionGroup" v-if="dingtalk.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="dingtalk.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" class="btn" @click="onSubmit('dingtalk')">提交</a-button>
</a-form-item>
@ -61,16 +81,36 @@
<template #help>参考地址{{ `${host}/oauth2-feishu` }}</template>
<a-input v-model:value="feishu.redirectUri" type="text" placeholder="请输入回调重定向 url [redirectUri]" />
</a-form-item>
<!-- <a-form-item label="登录url">
<a-input :value="`${this.host}/oauth2-render-github`" type="text" />
</a-form-item> -->
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="feishu.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="feishu.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="feishu.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="权限组" name="permissionGroup" v-if="feishu.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="feishu.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" class="btn" @click="onSubmit('feishu')">提交</a-button>
</a-form-item>
@ -108,13 +148,7 @@
placeholder="请输入回调重定向 url [redirectUri]"
/>
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch
v-model:checked="wechat_enterprise.autoCreteUser"
checked-children="启用"
un-checked-children="停用"
/>
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch
v-model:checked="wechat_enterprise.ignoreCheckState"
@ -122,7 +156,36 @@
un-checked-children="校验"
/>
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch
v-model:checked="wechat_enterprise.autoCreteUser"
checked-children="启用"
un-checked-children="停用"
/>
</a-form-item>
<a-form-item label="权限组" name="permissionGroup" v-if="wechat_enterprise.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="wechat_enterprise.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" class="btn" @click="onSubmit('wechat_enterprise')">提交</a-button>
</a-form-item>
@ -156,14 +219,36 @@
<template #help>参考地址{{ `${host}/oauth2-maxkey` }}</template>
<a-input v-model:value="maxkey.redirectUri" type="text" placeholder="请输入回调重定向 url [redirectUri]" />
</a-form-item>
<!-- <a-form-item label="登录url">
<a-input :value="`${this.host}/oauth2-render-maxkey`" type="text" />
</a-form-item> -->
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="maxkey.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="maxkey.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="maxkey.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
<a-form-item label="权限组" name="permissionGroup" v-if="maxkey.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="maxkey.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
@ -186,14 +271,36 @@
<template #help>参考地址{{ `${host}/oauth2-gitee` }}</template>
<a-input v-model:value="gitee.redirectUri" type="text" placeholder="请输入回调重定向 url [redirectUri]" />
</a-form-item>
<!-- <a-form-item label="登录url">
<a-input :value="`${this.host}/oauth2-render-gitee`" type="text" />
</a-form-item> -->
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="gitee.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="gitee.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="gitee.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
<a-form-item label="权限组" name="permissionGroup" v-if="gitee.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="gitee.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
@ -226,11 +333,35 @@
/>
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="mygitlab.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="mygitlab.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="mygitlab.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
<a-form-item label="权限组" name="permissionGroup" v-if="mygitlab.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="mygitlab.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
@ -255,14 +386,36 @@
<template #help>参考地址{{ `${host}/oauth2-github` }}</template>
<a-input v-model:value="github.redirectUri" type="text" placeholder="请输入回调重定向 url [redirectUri]" />
</a-form-item>
<!-- <a-form-item label="登录url">
<a-input :value="`${this.host}/oauth2-render-github`" type="text" />
</a-form-item> -->
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="github.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
</a-form-item>
<a-form-item label="自动创建用户" name="autoCreteUser">
<a-switch v-model:checked="github.autoCreteUser" checked-children="启用" un-checked-children="停用" />
</a-form-item>
<a-form-item label="忽略校验 state" name="ignoreCheckState">
<a-switch v-model:checked="github.ignoreCheckState" checked-children="忽略" un-checked-children="校验" />
<a-form-item label="权限组" name="permissionGroup" v-if="github.autoCreteUser">
<template #help>创建用户后自动关联上对应的权限组</template>
<a-select
v-model:value="github.permissionGroup"
show-search
:filter-option="
(input, option) => {
const children = option.children && option.children()
return (
children &&
children[0].children &&
children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
)
}
"
placeholder="请选择用户的权限组"
mode="multiple"
>
<a-select-option v-for="item in permissionGroup" :key="item.id">
{{ item.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 14, offset: 4 }">
@ -276,7 +429,7 @@
<script>
import { oauthConfigOauth2, oauthConfigOauth2Save } from '@/api/system'
import { getUserPermissionListAll } from '@/api/user/user-permission'
export default {
data() {
return {
@ -289,7 +442,8 @@ export default {
wechat_enterprise: {},
rules: {},
provides: ['gitee', 'maxkey', 'github', 'dingtalk', 'feishu', 'mygitlab', 'wechat_enterprise'],
host: ''
host: '',
permissionGroup: []
}
},
mounted() {
@ -304,14 +458,18 @@ export default {
provide: item
}).then((res) => {
if (res.code === 200) {
this[item] = Object.assign(res.data || {}, { provide: item })
const permissionGroup = res.data?.permissionGroup?.split('@') || []
this[item] = Object.assign(res.data || {}, { provide: item, permissionGroup: permissionGroup })
}
})
})
this.listUserPermissionListAll()
},
// submit
onSubmit(key) {
oauthConfigOauth2Save(this[key]).then((res) => {
let data = this[key]
data = { ...data, permissionGroup: data.permissionGroup.join('@') }
oauthConfigOauth2Save(data).then((res) => {
if (res.code === 200) {
//
$notification.success({
@ -319,6 +477,13 @@ export default {
})
}
})
},
listUserPermissionListAll() {
getUserPermissionListAll().then((res) => {
if (res.code === 200 && res.data) {
this.permissionGroup = res.data
}
})
}
}
}

View File

@ -237,6 +237,7 @@ export default {
editVisible: false,
listQuery: Object.assign({}, PAGE_DEFAULT_LIST_QUERY),
columns: [
{ title: 'id', dataIndex: 'id', ellipsis: true },
{ title: '名称', dataIndex: 'name', ellipsis: true },
{ title: '描述', dataIndex: 'description', ellipsis: true },