修改创建人为所有者
This commit is contained in:
parent
4fe33eaa41
commit
a27657e92e
@ -126,7 +126,17 @@ func CredentialDeleteEndpoint(c echo.Context) error {
|
||||
|
||||
func CredentialGetEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
item, _ := model.FindCredentialById(id)
|
||||
item, err := model.FindCredentialById(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Success(c, item)
|
||||
}
|
||||
|
||||
func CredentialChangeOwnerEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
owner := c.QueryParam("owner")
|
||||
model.UpdateCredentialById(&model.Credential{Owner: owner}, id)
|
||||
return Success(c, "")
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ func SetupRoutes() *echo.Echo {
|
||||
credentials.PUT("/:id", CredentialUpdateEndpoint)
|
||||
credentials.DELETE("/:id", CredentialDeleteEndpoint)
|
||||
credentials.GET("/:id", CredentialGetEndpoint)
|
||||
credentials.POST("/:id/change-owner", CredentialChangeOwnerEndpoint)
|
||||
}
|
||||
|
||||
sessions := e.Group("/sessions")
|
||||
|
@ -22,7 +22,20 @@ type Asset struct {
|
||||
Active bool `json:"active"`
|
||||
Created utils.JsonTime `json:"created"`
|
||||
Tags string `json:"tags"`
|
||||
Creator string `json:"creator"`
|
||||
Owner string `json:"owner"`
|
||||
}
|
||||
|
||||
type AssetVo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
Protocol string `json:"protocol"`
|
||||
Port int `json:"port"`
|
||||
Active bool `json:"active"`
|
||||
Created utils.JsonTime `json:"created"`
|
||||
Tags string `json:"tags"`
|
||||
Owner string `json:"owner"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
}
|
||||
|
||||
func (r *Asset) TableName() string {
|
||||
@ -44,27 +57,28 @@ func FindAssetByConditions(protocol string) (o []Asset, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string) (o []Asset, total int64, err error) {
|
||||
func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string) (o []AssetVo, total int64, err error) {
|
||||
db := global.DB
|
||||
db = db.Table("assets").Select("assets.id,assets.name,assets.ip,assets.port,assets.protocol,assets.active,assets.owner,assets.created, users.nickname as creator_name").Joins("left join users on assets.owner = users.id")
|
||||
if len(name) > 0 {
|
||||
db = db.Where("name like ?", "%"+name+"%")
|
||||
db = db.Where("assets.name like ?", "%"+name+"%")
|
||||
}
|
||||
|
||||
if len(protocol) > 0 {
|
||||
db = db.Where("protocol = ?", protocol)
|
||||
db = db.Where("assets.protocol = ?", protocol)
|
||||
}
|
||||
|
||||
if len(tags) > 0 {
|
||||
tagArr := strings.Split(tags, ",")
|
||||
for i := range tagArr {
|
||||
db = db.Where("find_in_set(?, tags)", tagArr[i])
|
||||
db = db.Where("find_in_set(?, assets.tags)", tagArr[i])
|
||||
}
|
||||
}
|
||||
|
||||
err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
|
||||
err = db.Order("assets.created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Count(&total).Error
|
||||
|
||||
if o == nil {
|
||||
o = make([]Asset, 0)
|
||||
o = make([]AssetVo, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func FindPageCommand(pageIndex, pageSize int, name, content string) (o []Command
|
||||
db = db.Where("content like ?", "%"+content+"%")
|
||||
}
|
||||
|
||||
err = db.Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
|
||||
err = db.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Find(&o).Error
|
||||
if o == nil {
|
||||
o = make([]Command, 0)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ type Credential struct {
|
||||
PrivateKey string `json:"privateKey"`
|
||||
Passphrase string `json:"passphrase"`
|
||||
Created utils.JsonTime `json:"created"`
|
||||
Creator string `json:"creator"`
|
||||
Owner string `json:"owner"`
|
||||
}
|
||||
|
||||
func (r *Credential) TableName() string {
|
||||
@ -28,13 +28,13 @@ func (r *Credential) TableName() string {
|
||||
}
|
||||
|
||||
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"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Username string `json:"username"`
|
||||
Created utils.JsonTime `json:"created"`
|
||||
Owner string `json:"owner"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
}
|
||||
|
||||
func FindAllCredential() (o []Credential, err error) {
|
||||
@ -42,17 +42,17 @@ func FindAllCredential() (o []Credential, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func FindPageCredential(pageIndex, pageSize int, name, creator string) (o []CredentialVo, total int64, err error) {
|
||||
func FindPageCredential(pageIndex, pageSize int, name, owner 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")
|
||||
db = db.Table("credentials").Select("credentials.id,credentials.name,credentials.type,credentials.username,credentials.owner,credentials.created,users.nickname as owner_name").Joins("left join users on credentials.owner = users.id")
|
||||
if len(name) > 0 {
|
||||
db = db.Where("credentials.name like ?", "%"+name+"%")
|
||||
}
|
||||
if len(creator) > 0 {
|
||||
db = db.Where("credentials.creator = ?", creator)
|
||||
if len(owner) > 0 {
|
||||
db = db.Where("credentials.owner = ?", owner)
|
||||
}
|
||||
|
||||
err = db.Order("credentials.created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
|
||||
err = db.Order("credentials.created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Count(&total).Error
|
||||
if o == nil {
|
||||
o = make([]CredentialVo, 0)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import qs from "qs";
|
||||
import AssetModal from "./AssetModal";
|
||||
import request from "../../common/request";
|
||||
import {message} from "antd/es";
|
||||
import {isEmpty, itemRender} from "../../utils/utils";
|
||||
import {itemRender} from "../../utils/utils";
|
||||
|
||||
|
||||
import {
|
||||
@ -383,22 +383,9 @@ class Asset extends Component {
|
||||
}
|
||||
}
|
||||
}, {
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
render: tags => {
|
||||
if (!isEmpty(tags)) {
|
||||
let tagDocuments = []
|
||||
let tagArr = tags.split(',');
|
||||
for (let i = 0; i < tagArr.length; i++) {
|
||||
if (tags[i] === '-') {
|
||||
continue;
|
||||
}
|
||||
tagDocuments.push(<Tag>{tagArr[i]}</Tag>)
|
||||
}
|
||||
return tagDocuments;
|
||||
}
|
||||
}
|
||||
title: '所有者',
|
||||
dataIndex: 'ownerName',
|
||||
key: 'ownerName'
|
||||
}, {
|
||||
title: '创建日期',
|
||||
dataIndex: 'created',
|
||||
@ -473,10 +460,10 @@ class Asset extends Component {
|
||||
<Content key='page-content' className="site-layout-background page-content">
|
||||
<div style={{marginBottom: 20}}>
|
||||
<Row justify="space-around" align="middle" gutter={24}>
|
||||
<Col span={12} key={1}>
|
||||
<Col span={8} key={1}>
|
||||
<Title level={3}>资产列表</Title>
|
||||
</Col>
|
||||
<Col span={12} key={2} style={{textAlign: 'right'}}>
|
||||
<Col span={16} key={2} style={{textAlign: 'right'}}>
|
||||
<Space>
|
||||
|
||||
<Search
|
||||
|
@ -4,8 +4,11 @@ import {
|
||||
Button,
|
||||
Col,
|
||||
Divider,
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
Layout,
|
||||
Menu,
|
||||
Modal,
|
||||
PageHeader,
|
||||
Row,
|
||||
@ -19,7 +22,15 @@ import qs from "qs";
|
||||
import CredentialModal from "./CredentialModal";
|
||||
import request from "../../common/request";
|
||||
import {message} from "antd/es";
|
||||
import {DeleteOutlined, ExclamationCircleOutlined, PlusOutlined, SyncOutlined, UndoOutlined} from '@ant-design/icons';
|
||||
import {
|
||||
DeleteOutlined,
|
||||
DownOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
OneToOneOutlined,
|
||||
PlusOutlined,
|
||||
SyncOutlined,
|
||||
UndoOutlined
|
||||
} from '@ant-design/icons';
|
||||
import {itemRender} from "../../utils/utils";
|
||||
import Logout from "../user/Logout";
|
||||
|
||||
@ -41,6 +52,7 @@ const routes = [
|
||||
class Credential extends Component {
|
||||
|
||||
inputRefOfName = React.createRef();
|
||||
changeOwnerFormRef = React.createRef();
|
||||
|
||||
state = {
|
||||
items: [],
|
||||
@ -56,6 +68,8 @@ class Credential extends Component {
|
||||
model: null,
|
||||
selectedRowKeys: [],
|
||||
delBtnLoading: false,
|
||||
changeOwnerModalVisible: false,
|
||||
changeOwnerConfirmLoading: false,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
@ -148,11 +162,30 @@ class Credential extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
showModal(title, idcard = null) {
|
||||
showModal = async (title, id = null, index) => {
|
||||
|
||||
let items = this.state.items;
|
||||
items[index].updateBtnLoading = true;
|
||||
this.setState({
|
||||
items: items
|
||||
});
|
||||
|
||||
let result = await request.get('/credentials/' + id);
|
||||
if (result['code'] !== 1) {
|
||||
message.error(result['message']);
|
||||
items[index].updateBtnLoading = false;
|
||||
this.setState({
|
||||
items: items
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
items[index].updateBtnLoading = false;
|
||||
this.setState({
|
||||
modalTitle: title,
|
||||
modalVisible: true,
|
||||
model: idcard
|
||||
model: result['data'],
|
||||
items: items
|
||||
});
|
||||
};
|
||||
|
||||
@ -270,9 +303,9 @@ class Credential extends Component {
|
||||
dataIndex: 'username',
|
||||
key: 'username',
|
||||
}, {
|
||||
title: '创建人',
|
||||
dataIndex: 'creatorName',
|
||||
key: 'creatorName',
|
||||
title: '所有者',
|
||||
dataIndex: 'ownerName',
|
||||
key: 'ownerName',
|
||||
}, {
|
||||
title: '创建时间',
|
||||
dataIndex: 'created',
|
||||
@ -281,14 +314,41 @@ class Credential extends Component {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (text, record) => {
|
||||
render: (text, record, index) => {
|
||||
|
||||
const menu = (
|
||||
<Menu>
|
||||
<Menu.Item key="1">
|
||||
<Button type="text" size='small'
|
||||
onClick={() => {
|
||||
this.setState({
|
||||
changeOwnerModalVisible: true
|
||||
})
|
||||
}}>更换所有者</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'
|
||||
onClick={() => this.showModal('更新凭证', record)}>编辑</Button>
|
||||
<Button type="link" size='small'
|
||||
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
|
||||
<Button type="link" size='small' loading={this.state.items[index].updateBtnLoading}
|
||||
onClick={() => this.showModal('更新凭证', record.id, index)}>编辑</Button>
|
||||
<Dropdown overlay={menu}>
|
||||
<Button type="link" size='small'>
|
||||
更多 <DownOutlined/>
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
@ -427,6 +487,28 @@ class Credential extends Component {
|
||||
: null
|
||||
}
|
||||
|
||||
<Modal title="更换所有者" visible={this.state.changeOwnerModalVisible}
|
||||
confirmLoading={this.state.changeOwnerConfirmLoading}
|
||||
onOk={() => {
|
||||
this.changeOwnerFormRef.current
|
||||
.validateFields()
|
||||
.then(values => {
|
||||
this.changeOwnerFormRef.current.resetFields();
|
||||
|
||||
})
|
||||
.catch(info => {
|
||||
|
||||
});
|
||||
}}
|
||||
onCancel={this.handleCancel}>
|
||||
|
||||
<Form ref={this.changeOwnerFormRef}>
|
||||
<Form.Item name='totp' rules={[{required: true, message: '请选择所有者'}]}>
|
||||
<Input prefix={<OneToOneOutlined/>} placeholder="请选择所有者"/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
</Content>
|
||||
</>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user