完成授权凭证隔离
This commit is contained in:
parent
499dd3ab85
commit
4fe33eaa41
@ -58,7 +58,17 @@ func CredentialPagingEndpoint(c echo.Context) error {
|
|||||||
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
|
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
|
||||||
name := c.QueryParam("name")
|
name := c.QueryParam("name")
|
||||||
|
|
||||||
items, total, _ := model.FindPageCredential(pageIndex, pageSize, name)
|
var (
|
||||||
|
total int64
|
||||||
|
items []model.CredentialVo
|
||||||
|
)
|
||||||
|
|
||||||
|
account, _ := GetCurrentAccount(c)
|
||||||
|
if account.Role == model.RoleUser {
|
||||||
|
items, total, _ = model.FindPageCredential(pageIndex, pageSize, name, account.ID)
|
||||||
|
} else {
|
||||||
|
items, total, _ = model.FindPageCredential(pageIndex, pageSize, name, "")
|
||||||
|
}
|
||||||
|
|
||||||
return Success(c, H{
|
return Success(c, H{
|
||||||
"total": total,
|
"total": total,
|
||||||
|
@ -27,20 +27,34 @@ func (r *Credential) TableName() string {
|
|||||||
return "credentials"
|
return "credentials"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CredentialVo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
Created utils.JsonTime `json:"created"`
|
||||||
|
Creator string `json:"creator"`
|
||||||
|
CreatorName string `json:"creatorName"`
|
||||||
|
}
|
||||||
|
|
||||||
func FindAllCredential() (o []Credential, err error) {
|
func FindAllCredential() (o []Credential, err error) {
|
||||||
err = global.DB.Find(&o).Error
|
err = global.DB.Find(&o).Error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindPageCredential(pageIndex, pageSize int, name string) (o []Credential, total int64, err error) {
|
func FindPageCredential(pageIndex, pageSize int, name, creator string) (o []CredentialVo, total int64, err error) {
|
||||||
db := global.DB
|
db := global.DB
|
||||||
|
db = db.Table("credentials").Select("credentials.id,credentials.name,credentials.type,credentials.username,credentials.creator,credentials.created,users.nickname as creator_name").Joins("left join users on credentials.creator = users.id")
|
||||||
if len(name) > 0 {
|
if len(name) > 0 {
|
||||||
db = db.Where("name like ?", "%"+name+"%")
|
db = db.Where("credentials.name like ?", "%"+name+"%")
|
||||||
|
}
|
||||||
|
if len(creator) > 0 {
|
||||||
|
db = db.Where("credentials.creator = ?", creator)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
|
err = db.Order("credentials.created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
|
||||||
if o == nil {
|
if o == nil {
|
||||||
o = make([]Credential, 0)
|
o = make([]CredentialVo, 0)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,11 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RoleUser = "user"
|
||||||
|
RoleAdmin = "admin"
|
||||||
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `gorm:"primary_key" json:"id"`
|
ID string `gorm:"primary_key" json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
@ -60,6 +65,11 @@ func FindUserById(id string) (o User, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindUserByIdIn(ids []string) (o []User, err error) {
|
||||||
|
err = global.DB.Where("id in ?", ids).First(&o).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func FindUserByUsername(username string) (o User, err error) {
|
func FindUserByUsername(username string) (o User, err error) {
|
||||||
err = global.DB.Where("username = ?", username).First(&o).Error
|
err = global.DB.Where("username = ?", username).First(&o).Error
|
||||||
return
|
return
|
||||||
|
@ -5,8 +5,10 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Col,
|
Col,
|
||||||
Divider,
|
Divider,
|
||||||
|
Dropdown,
|
||||||
Input,
|
Input,
|
||||||
Layout,
|
Layout,
|
||||||
|
Menu,
|
||||||
Modal,
|
Modal,
|
||||||
PageHeader,
|
PageHeader,
|
||||||
Row,
|
Row,
|
||||||
@ -25,11 +27,8 @@ import {isEmpty, itemRender} from "../../utils/utils";
|
|||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CodeTwoTone,
|
|
||||||
CopyTwoTone,
|
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
DeleteTwoTone,
|
DownOutlined,
|
||||||
EditTwoTone,
|
|
||||||
ExclamationCircleOutlined,
|
ExclamationCircleOutlined,
|
||||||
PlusOutlined,
|
PlusOutlined,
|
||||||
SyncOutlined,
|
SyncOutlined,
|
||||||
@ -409,16 +408,37 @@ class Asset extends Component {
|
|||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
render: (text, record) => {
|
render: (text, record) => {
|
||||||
|
|
||||||
|
const menu = (
|
||||||
|
<Menu>
|
||||||
|
<Menu.Item key="1">
|
||||||
|
<Button type="text" size='small'
|
||||||
|
onClick={() => this.update(record.id)}>编辑</Button>
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
|
<Menu.Item key="2">
|
||||||
|
<Button type="text" size='small'
|
||||||
|
onClick={() => this.copy(record.id)}>复制</Button>
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
|
<Menu.Divider/>
|
||||||
|
<Menu.Item key="3">
|
||||||
|
<Button type="text" size='small' danger
|
||||||
|
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||||
|
</Menu.Item>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button type="link" size='small' icon={<CodeTwoTone/>}
|
<Button type="link" size='small'
|
||||||
onClick={() => this.access(record.id, record.protocol)}>接入</Button>
|
onClick={() => this.access(record.id, record.protocol)}>接入</Button>
|
||||||
<Button type="link" size='small' icon={<EditTwoTone/>}
|
|
||||||
onClick={() => this.update(record.id)}>编辑</Button>
|
<Dropdown overlay={menu}>
|
||||||
<Button type="link" size='small' icon={<CopyTwoTone/>}
|
<Button type="link" size='small'>
|
||||||
onClick={() => this.copy(record.id)}>复制</Button>
|
更多 <DownOutlined/>
|
||||||
<Button type="link" size='small' icon={<DeleteTwoTone/>}
|
</Button>
|
||||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -1,20 +1,25 @@
|
|||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
|
|
||||||
import {Button, Col, Divider, Input, Layout, Modal, PageHeader, Row, Space, Table, Tooltip, Typography} from "antd";
|
import {
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Divider,
|
||||||
|
Input,
|
||||||
|
Layout,
|
||||||
|
Modal,
|
||||||
|
PageHeader,
|
||||||
|
Row,
|
||||||
|
Space,
|
||||||
|
Table,
|
||||||
|
Tag,
|
||||||
|
Tooltip,
|
||||||
|
Typography
|
||||||
|
} from "antd";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import CredentialModal from "./CredentialModal";
|
import CredentialModal from "./CredentialModal";
|
||||||
import request from "../../common/request";
|
import request from "../../common/request";
|
||||||
import {message} from "antd/es";
|
import {message} from "antd/es";
|
||||||
import {
|
import {DeleteOutlined, ExclamationCircleOutlined, PlusOutlined, SyncOutlined, UndoOutlined} from '@ant-design/icons';
|
||||||
DeleteOutlined,
|
|
||||||
DeleteTwoTone,
|
|
||||||
EditTwoTone,
|
|
||||||
ExclamationCircleOutlined,
|
|
||||||
EyeTwoTone,
|
|
||||||
PlusOutlined,
|
|
||||||
SyncOutlined,
|
|
||||||
UndoOutlined
|
|
||||||
} from '@ant-design/icons';
|
|
||||||
import {itemRender} from "../../utils/utils";
|
import {itemRender} from "../../utils/utils";
|
||||||
import Logout from "../user/Logout";
|
import Logout from "../user/Logout";
|
||||||
|
|
||||||
@ -251,11 +256,11 @@ class Credential extends Component {
|
|||||||
|
|
||||||
if (type === 'private-key') {
|
if (type === 'private-key') {
|
||||||
return (
|
return (
|
||||||
<Text strong type="success">密钥</Text>
|
<Tag color="green">密钥</Tag>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Text strong type="warning">密码</Text>
|
<Tag color="red">密码</Tag>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,6 +269,14 @@ class Credential extends Component {
|
|||||||
title: '授权账户',
|
title: '授权账户',
|
||||||
dataIndex: 'username',
|
dataIndex: 'username',
|
||||||
key: 'username',
|
key: 'username',
|
||||||
|
}, {
|
||||||
|
title: '创建人',
|
||||||
|
dataIndex: 'creatorName',
|
||||||
|
key: 'creatorName',
|
||||||
|
}, {
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'created',
|
||||||
|
key: 'created',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
@ -272,11 +285,9 @@ class Credential extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button type="link" size='small' icon={<EyeTwoTone/>}
|
<Button type="link" size='small'
|
||||||
onClick={() => this.showModal('查看凭证', record)}>查看</Button>
|
|
||||||
<Button type="link" size='small' icon={<EditTwoTone/>}
|
|
||||||
onClick={() => this.showModal('更新凭证', record)}>编辑</Button>
|
onClick={() => this.showModal('更新凭证', record)}>编辑</Button>
|
||||||
<Button type="link" size='small' icon={<DeleteTwoTone/>}
|
<Button type="link" size='small'
|
||||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,8 @@ import {
|
|||||||
Badge,
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
Col,
|
Col,
|
||||||
Divider, Dropdown,
|
Divider,
|
||||||
|
Dropdown,
|
||||||
Input,
|
Input,
|
||||||
Layout,
|
Layout,
|
||||||
Menu,
|
Menu,
|
||||||
@ -14,6 +15,7 @@ import {
|
|||||||
Row,
|
Row,
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
|
Tag,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Typography,
|
Typography,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
@ -22,9 +24,11 @@ import UserModal from "./UserModal";
|
|||||||
import request from "../../common/request";
|
import request from "../../common/request";
|
||||||
import {message} from "antd/es";
|
import {message} from "antd/es";
|
||||||
import {
|
import {
|
||||||
DeleteOutlined, DownOutlined,
|
DeleteOutlined,
|
||||||
ExclamationCircleOutlined, IssuesCloseOutlined,
|
DownOutlined,
|
||||||
PlusOutlined, SmileOutlined,
|
ExclamationCircleOutlined,
|
||||||
|
IssuesCloseOutlined,
|
||||||
|
PlusOutlined,
|
||||||
StopOutlined,
|
StopOutlined,
|
||||||
SyncOutlined,
|
SyncOutlined,
|
||||||
UndoOutlined
|
UndoOutlined
|
||||||
@ -261,6 +265,25 @@ class User extends Component {
|
|||||||
title: '用户昵称',
|
title: '用户昵称',
|
||||||
dataIndex: 'nickname',
|
dataIndex: 'nickname',
|
||||||
key: 'nickname',
|
key: 'nickname',
|
||||||
|
}, {
|
||||||
|
title: '用户角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
key: 'role',
|
||||||
|
render: (role, record) => {
|
||||||
|
|
||||||
|
if (role === 'normal') {
|
||||||
|
return (
|
||||||
|
<Tag>普通用户</Tag>
|
||||||
|
);
|
||||||
|
} else if (role === 'admin') {
|
||||||
|
return (
|
||||||
|
<Tag color="blue">管理用户</Tag>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
title: '在线状态',
|
title: '在线状态',
|
||||||
dataIndex: 'online',
|
dataIndex: 'online',
|
||||||
@ -282,33 +305,13 @@ class User extends Component {
|
|||||||
key: 'action',
|
key: 'action',
|
||||||
render: (text, record) => {
|
render: (text, record) => {
|
||||||
|
|
||||||
const menu = (
|
|
||||||
<Menu>
|
|
||||||
<Menu.Item key="1">
|
|
||||||
<Button type="text" size='small'
|
|
||||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>禁用</Button>
|
|
||||||
</Menu.Item>
|
|
||||||
<Menu.Item key="2">
|
|
||||||
<Button type="text" size='small'
|
|
||||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>启用</Button>
|
|
||||||
</Menu.Item>
|
|
||||||
<Menu.Divider />
|
|
||||||
<Menu.Item key="3">
|
|
||||||
<Button type="text" size='small'
|
|
||||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
|
||||||
</Menu.Item>
|
|
||||||
</Menu>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button type="link" size='small'
|
<Button type="link" size='small'
|
||||||
onClick={() => this.showModal('更新用户', record)}>编辑</Button>
|
onClick={() => this.showModal('更新用户', record)}>编辑</Button>
|
||||||
<Dropdown overlay={menu}>
|
<Button type="link" size='small'
|
||||||
<Button type="link" size='small'>
|
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||||
更多 <DownOutlined />
|
|
||||||
</Button>
|
|
||||||
</Dropdown>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -391,51 +394,52 @@ class User extends Component {
|
|||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip title="批量启用">
|
{/*<Tooltip title="批量启用">*/}
|
||||||
<Button type="dashed" danger disabled={!hasSelected} icon={<IssuesCloseOutlined />}
|
{/* <Button type="dashed" danger disabled={!hasSelected}*/}
|
||||||
loading={this.state.delBtnLoading}
|
{/* icon={<IssuesCloseOutlined/>}*/}
|
||||||
onClick={() => {
|
{/* loading={this.state.delBtnLoading}*/}
|
||||||
const content = <div>
|
{/* onClick={() => {*/}
|
||||||
您确定要启用选中的<Text style={{color: '#1890FF'}}
|
{/* const content = <div>*/}
|
||||||
strong>{this.state.selectedRowKeys.length}</Text>条记录吗?
|
{/* 您确定要启用选中的<Text style={{color: '#1890FF'}}*/}
|
||||||
</div>;
|
{/* strong>{this.state.selectedRowKeys.length}</Text>条记录吗?*/}
|
||||||
confirm({
|
{/* </div>;*/}
|
||||||
icon: <ExclamationCircleOutlined/>,
|
{/* confirm({*/}
|
||||||
content: content,
|
{/* icon: <ExclamationCircleOutlined/>,*/}
|
||||||
onOk: () => {
|
{/* content: content,*/}
|
||||||
|
{/* onOk: () => {*/}
|
||||||
|
|
||||||
},
|
{/* },*/}
|
||||||
onCancel() {
|
{/* onCancel() {*/}
|
||||||
|
|
||||||
},
|
{/* },*/}
|
||||||
});
|
{/* });*/}
|
||||||
}}>
|
{/* }}>*/}
|
||||||
|
|
||||||
</Button>
|
{/* </Button>*/}
|
||||||
</Tooltip>
|
{/*</Tooltip>*/}
|
||||||
|
|
||||||
<Tooltip title="批量禁用">
|
{/*<Tooltip title="批量禁用">*/}
|
||||||
<Button type="default" danger disabled={!hasSelected} icon={<StopOutlined/>}
|
{/* <Button type="default" danger disabled={!hasSelected} icon={<StopOutlined/>}*/}
|
||||||
loading={this.state.delBtnLoading}
|
{/* loading={this.state.delBtnLoading}*/}
|
||||||
onClick={() => {
|
{/* onClick={() => {*/}
|
||||||
const content = <div>
|
{/* const content = <div>*/}
|
||||||
您确定要禁用选中的<Text style={{color: '#1890FF'}}
|
{/* 您确定要禁用选中的<Text style={{color: '#1890FF'}}*/}
|
||||||
strong>{this.state.selectedRowKeys.length}</Text>条记录吗?
|
{/* strong>{this.state.selectedRowKeys.length}</Text>条记录吗?*/}
|
||||||
</div>;
|
{/* </div>;*/}
|
||||||
confirm({
|
{/* confirm({*/}
|
||||||
icon: <ExclamationCircleOutlined/>,
|
{/* icon: <ExclamationCircleOutlined/>,*/}
|
||||||
content: content,
|
{/* content: content,*/}
|
||||||
onOk: () => {
|
{/* onOk: () => {*/}
|
||||||
|
|
||||||
},
|
{/* },*/}
|
||||||
onCancel() {
|
{/* onCancel() {*/}
|
||||||
|
|
||||||
},
|
{/* },*/}
|
||||||
});
|
{/* });*/}
|
||||||
}}>
|
{/* }}>*/}
|
||||||
|
|
||||||
</Button>
|
{/* </Button>*/}
|
||||||
</Tooltip>
|
{/*</Tooltip>*/}
|
||||||
|
|
||||||
<Tooltip title="批量删除">
|
<Tooltip title="批量删除">
|
||||||
<Button type="primary" danger disabled={!hasSelected} icon={<DeleteOutlined/>}
|
<Button type="primary" danger disabled={!hasSelected} icon={<DeleteOutlined/>}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {Form, Input, Modal} from "antd/lib/index";
|
import {Form, Input, Modal, Radio} from "antd/lib/index";
|
||||||
|
|
||||||
const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, model}) => {
|
const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, model}) => {
|
||||||
|
|
||||||
@ -22,7 +22,8 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
|
|||||||
form.resetFields();
|
form.resetFields();
|
||||||
handleOk(values);
|
handleOk(values);
|
||||||
})
|
})
|
||||||
.catch(info => {});
|
.catch(info => {
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
confirmLoading={confirmLoading}
|
confirmLoading={confirmLoading}
|
||||||
@ -43,6 +44,13 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
|
|||||||
<Input placeholder="请输入用户昵称"/>
|
<Input placeholder="请输入用户昵称"/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item label="用户角色" name='role' rules={[{required: true, message: '请选择用户角色'}]}>
|
||||||
|
<Radio.Group >
|
||||||
|
<Radio value={'user'}>普通用户</Radio>
|
||||||
|
<Radio value={'admin'}>管理用户</Radio>
|
||||||
|
</Radio.Group>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
{
|
{
|
||||||
title.indexOf('新增') > -1 ?
|
title.indexOf('新增') > -1 ?
|
||||||
(<Form.Item label="登录密码" name='password' rules={[{required: true, message: '请输入登录密码'}]}>
|
(<Form.Item label="登录密码" name='password' rules={[{required: true, message: '请输入登录密码'}]}>
|
||||||
|
Loading…
Reference in New Issue
Block a user