完成授权凭证隔离
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"))
|
||||
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{
|
||||
"total": total,
|
||||
|
@ -27,20 +27,34 @@ func (r *Credential) TableName() string {
|
||||
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) {
|
||||
err = global.DB.Find(&o).Error
|
||||
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 = 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 {
|
||||
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 {
|
||||
o = make([]Credential, 0)
|
||||
o = make([]CredentialVo, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -6,6 +6,11 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
RoleUser = "user"
|
||||
RoleAdmin = "admin"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID string `gorm:"primary_key" json:"id"`
|
||||
Username string `json:"username"`
|
||||
@ -60,6 +65,11 @@ func FindUserById(id string) (o User, err error) {
|
||||
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) {
|
||||
err = global.DB.Where("username = ?", username).First(&o).Error
|
||||
return
|
||||
|
@ -5,8 +5,10 @@ import {
|
||||
Button,
|
||||
Col,
|
||||
Divider,
|
||||
Dropdown,
|
||||
Input,
|
||||
Layout,
|
||||
Menu,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Row,
|
||||
@ -25,11 +27,8 @@ import {isEmpty, itemRender} from "../../utils/utils";
|
||||
|
||||
|
||||
import {
|
||||
CodeTwoTone,
|
||||
CopyTwoTone,
|
||||
DeleteOutlined,
|
||||
DeleteTwoTone,
|
||||
EditTwoTone,
|
||||
DownOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
PlusOutlined,
|
||||
SyncOutlined,
|
||||
@ -409,16 +408,37 @@ class Asset extends Component {
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
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 (
|
||||
<div>
|
||||
<Button type="link" size='small' icon={<CodeTwoTone/>}
|
||||
<Button type="link" size='small'
|
||||
onClick={() => this.access(record.id, record.protocol)}>接入</Button>
|
||||
<Button type="link" size='small' icon={<EditTwoTone/>}
|
||||
onClick={() => this.update(record.id)}>编辑</Button>
|
||||
<Button type="link" size='small' icon={<CopyTwoTone/>}
|
||||
onClick={() => this.copy(record.id)}>复制</Button>
|
||||
<Button type="link" size='small' icon={<DeleteTwoTone/>}
|
||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||
|
||||
<Dropdown overlay={menu}>
|
||||
<Button type="link" size='small'>
|
||||
更多 <DownOutlined/>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
|
@ -1,20 +1,25 @@
|
||||
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 CredentialModal from "./CredentialModal";
|
||||
import request from "../../common/request";
|
||||
import {message} from "antd/es";
|
||||
import {
|
||||
DeleteOutlined,
|
||||
DeleteTwoTone,
|
||||
EditTwoTone,
|
||||
ExclamationCircleOutlined,
|
||||
EyeTwoTone,
|
||||
PlusOutlined,
|
||||
SyncOutlined,
|
||||
UndoOutlined
|
||||
} from '@ant-design/icons';
|
||||
import {DeleteOutlined, ExclamationCircleOutlined, PlusOutlined, SyncOutlined, UndoOutlined} from '@ant-design/icons';
|
||||
import {itemRender} from "../../utils/utils";
|
||||
import Logout from "../user/Logout";
|
||||
|
||||
@ -251,11 +256,11 @@ class Credential extends Component {
|
||||
|
||||
if (type === 'private-key') {
|
||||
return (
|
||||
<Text strong type="success">密钥</Text>
|
||||
<Tag color="green">密钥</Tag>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Text strong type="warning">密码</Text>
|
||||
<Tag color="red">密码</Tag>
|
||||
);
|
||||
}
|
||||
|
||||
@ -264,6 +269,14 @@ class Credential extends Component {
|
||||
title: '授权账户',
|
||||
dataIndex: 'username',
|
||||
key: 'username',
|
||||
}, {
|
||||
title: '创建人',
|
||||
dataIndex: 'creatorName',
|
||||
key: 'creatorName',
|
||||
}, {
|
||||
title: '创建时间',
|
||||
dataIndex: 'created',
|
||||
key: 'created',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
@ -272,11 +285,9 @@ class Credential extends Component {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button type="link" size='small' icon={<EyeTwoTone/>}
|
||||
onClick={() => this.showModal('查看凭证', record)}>查看</Button>
|
||||
<Button type="link" size='small' icon={<EditTwoTone/>}
|
||||
<Button type="link" size='small'
|
||||
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>
|
||||
</div>
|
||||
)
|
||||
|
@ -5,7 +5,8 @@ import {
|
||||
Badge,
|
||||
Button,
|
||||
Col,
|
||||
Divider, Dropdown,
|
||||
Divider,
|
||||
Dropdown,
|
||||
Input,
|
||||
Layout,
|
||||
Menu,
|
||||
@ -14,6 +15,7 @@ import {
|
||||
Row,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "antd";
|
||||
@ -22,9 +24,11 @@ import UserModal from "./UserModal";
|
||||
import request from "../../common/request";
|
||||
import {message} from "antd/es";
|
||||
import {
|
||||
DeleteOutlined, DownOutlined,
|
||||
ExclamationCircleOutlined, IssuesCloseOutlined,
|
||||
PlusOutlined, SmileOutlined,
|
||||
DeleteOutlined,
|
||||
DownOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
IssuesCloseOutlined,
|
||||
PlusOutlined,
|
||||
StopOutlined,
|
||||
SyncOutlined,
|
||||
UndoOutlined
|
||||
@ -261,6 +265,25 @@ class User extends Component {
|
||||
title: '用户昵称',
|
||||
dataIndex: '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: '在线状态',
|
||||
dataIndex: 'online',
|
||||
@ -282,33 +305,13 @@ class User extends Component {
|
||||
key: 'action',
|
||||
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 (
|
||||
<div>
|
||||
<Button type="link" size='small'
|
||||
onClick={() => this.showModal('更新用户', record)}>编辑</Button>
|
||||
<Dropdown overlay={menu}>
|
||||
<Button type="link" size='small'>
|
||||
更多 <DownOutlined />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
<Button type="link" size='small'
|
||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@ -391,51 +394,52 @@ class User extends Component {
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip title="批量启用">
|
||||
<Button type="dashed" danger disabled={!hasSelected} icon={<IssuesCloseOutlined />}
|
||||
loading={this.state.delBtnLoading}
|
||||
onClick={() => {
|
||||
const content = <div>
|
||||
您确定要启用选中的<Text style={{color: '#1890FF'}}
|
||||
strong>{this.state.selectedRowKeys.length}</Text>条记录吗?
|
||||
</div>;
|
||||
confirm({
|
||||
icon: <ExclamationCircleOutlined/>,
|
||||
content: content,
|
||||
onOk: () => {
|
||||
{/*<Tooltip title="批量启用">*/}
|
||||
{/* <Button type="dashed" danger disabled={!hasSelected}*/}
|
||||
{/* icon={<IssuesCloseOutlined/>}*/}
|
||||
{/* loading={this.state.delBtnLoading}*/}
|
||||
{/* onClick={() => {*/}
|
||||
{/* const content = <div>*/}
|
||||
{/* 您确定要启用选中的<Text style={{color: '#1890FF'}}*/}
|
||||
{/* strong>{this.state.selectedRowKeys.length}</Text>条记录吗?*/}
|
||||
{/* </div>;*/}
|
||||
{/* confirm({*/}
|
||||
{/* icon: <ExclamationCircleOutlined/>,*/}
|
||||
{/* content: content,*/}
|
||||
{/* onOk: () => {*/}
|
||||
|
||||
},
|
||||
onCancel() {
|
||||
{/* },*/}
|
||||
{/* onCancel() {*/}
|
||||
|
||||
},
|
||||
});
|
||||
}}>
|
||||
{/* },*/}
|
||||
{/* });*/}
|
||||
{/* }}>*/}
|
||||
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{/* </Button>*/}
|
||||
{/*</Tooltip>*/}
|
||||
|
||||
<Tooltip title="批量禁用">
|
||||
<Button type="default" danger disabled={!hasSelected} icon={<StopOutlined/>}
|
||||
loading={this.state.delBtnLoading}
|
||||
onClick={() => {
|
||||
const content = <div>
|
||||
您确定要禁用选中的<Text style={{color: '#1890FF'}}
|
||||
strong>{this.state.selectedRowKeys.length}</Text>条记录吗?
|
||||
</div>;
|
||||
confirm({
|
||||
icon: <ExclamationCircleOutlined/>,
|
||||
content: content,
|
||||
onOk: () => {
|
||||
{/*<Tooltip title="批量禁用">*/}
|
||||
{/* <Button type="default" danger disabled={!hasSelected} icon={<StopOutlined/>}*/}
|
||||
{/* loading={this.state.delBtnLoading}*/}
|
||||
{/* onClick={() => {*/}
|
||||
{/* const content = <div>*/}
|
||||
{/* 您确定要禁用选中的<Text style={{color: '#1890FF'}}*/}
|
||||
{/* strong>{this.state.selectedRowKeys.length}</Text>条记录吗?*/}
|
||||
{/* </div>;*/}
|
||||
{/* confirm({*/}
|
||||
{/* icon: <ExclamationCircleOutlined/>,*/}
|
||||
{/* content: content,*/}
|
||||
{/* onOk: () => {*/}
|
||||
|
||||
},
|
||||
onCancel() {
|
||||
{/* },*/}
|
||||
{/* onCancel() {*/}
|
||||
|
||||
},
|
||||
});
|
||||
}}>
|
||||
{/* },*/}
|
||||
{/* });*/}
|
||||
{/* }}>*/}
|
||||
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{/* </Button>*/}
|
||||
{/*</Tooltip>*/}
|
||||
|
||||
<Tooltip title="批量删除">
|
||||
<Button type="primary" danger disabled={!hasSelected} icon={<DeleteOutlined/>}
|
||||
|
@ -1,5 +1,5 @@
|
||||
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}) => {
|
||||
|
||||
@ -22,7 +22,8 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
|
||||
form.resetFields();
|
||||
handleOk(values);
|
||||
})
|
||||
.catch(info => {});
|
||||
.catch(info => {
|
||||
});
|
||||
}}
|
||||
onCancel={handleCancel}
|
||||
confirmLoading={confirmLoading}
|
||||
@ -43,6 +44,13 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
|
||||
<Input placeholder="请输入用户昵称"/>
|
||||
</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 ?
|
||||
(<Form.Item label="登录密码" name='password' rules={[{required: true, message: '请输入登录密码'}]}>
|
||||
|
Loading…
Reference in New Issue
Block a user