修复普通用户访问非自己创建的资产无法打开原生ssh的bug
This commit is contained in:
parent
f8c29b23b9
commit
d33779ac34
@ -213,35 +213,6 @@ func AssetUpdateEndpoint(c echo.Context) error {
|
||||
return Success(c, nil)
|
||||
}
|
||||
|
||||
func AssetGetAttributeEndpoint(c echo.Context) error {
|
||||
|
||||
assetId := c.Param("id")
|
||||
if err := PreCheckAssetPermission(c, assetId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
attributeMap, err := assetRepository.FindAssetAttrMapByAssetId(assetId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, attributeMap)
|
||||
}
|
||||
|
||||
func AssetUpdateAttributeEndpoint(c echo.Context) error {
|
||||
m := echo.Map{}
|
||||
if err := c.Bind(&m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
assetId := c.Param("id")
|
||||
protocol := c.QueryParam("protocol")
|
||||
err := assetRepository.UpdateAttributes(assetId, protocol, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, "")
|
||||
}
|
||||
|
||||
func AssetDeleteEndpoint(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
split := strings.Split(id, ",")
|
||||
|
@ -133,7 +133,6 @@ func SetupRoutes(db *gorm.DB) *echo.Echo {
|
||||
assets.PUT("/:id", AssetUpdateEndpoint)
|
||||
assets.DELETE("/:id", AssetDeleteEndpoint)
|
||||
assets.GET("/:id", AssetGetEndpoint)
|
||||
assets.GET("/:id/attributes", AssetGetAttributeEndpoint)
|
||||
assets.POST("/:id/change-owner", Admin(AssetChangeOwnerEndpoint))
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ type AssetForPage struct {
|
||||
Owner string `json:"owner"`
|
||||
OwnerName string `json:"ownerName"`
|
||||
SharerCount int64 `json:"sharerCount"`
|
||||
SshMode string `json:"sshMode"`
|
||||
}
|
||||
|
||||
func (r *Asset) TableName() string {
|
||||
|
@ -142,6 +142,22 @@ func (r AssetRepository) Find(pageIndex, pageSize int, name, protocol, tags stri
|
||||
|
||||
if o == nil {
|
||||
o = make([]model.AssetForPage, 0)
|
||||
} else {
|
||||
for i := 0; i < len(o); i++ {
|
||||
if o[i].Protocol == "ssh" {
|
||||
attributes, err := r.FindAttrById(o[i].ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for j := range attributes {
|
||||
if attributes[j].Name == constant.SshMode {
|
||||
o[i].SshMode = attributes[j].Value
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -338,19 +338,15 @@ class Asset extends Component {
|
||||
const id = record['id'];
|
||||
const protocol = record['protocol'];
|
||||
const name = record['name'];
|
||||
|
||||
const sshMode = record['sshMode'];
|
||||
alert(sshMode)
|
||||
message.loading({content: '正在检测资产是否在线...', key: id});
|
||||
let result = await request.post(`/assets/${id}/tcping`);
|
||||
if (result.code === 1) {
|
||||
if (result.data === true) {
|
||||
message.success({content: '检测完成,您访问的资产在线,即将打开窗口进行访问。', key: id, duration: 3});
|
||||
if (protocol === 'ssh') {
|
||||
result = await request.get(`/assets/${id}/attributes`);
|
||||
if (result.code === 1 && result['data']['ssh-mode'] === 'naive') {
|
||||
window.open(`#/term?assetId=${id}&assetName=${name}`);
|
||||
} else {
|
||||
window.open(`#/access?assetId=${id}&assetName=${name}&protocol=${protocol}`);
|
||||
}
|
||||
if (protocol === 'ssh' && sshMode === 'naive') {
|
||||
window.open(`#/term?assetId=${id}&assetName=${name}`);
|
||||
} else {
|
||||
window.open(`#/access?assetId=${id}&assetName=${name}&protocol=${protocol}`);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user