Skip to content

Commit

Permalink
修复普通用户访问非自己创建的资产无法打开原生ssh的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dushixiang authored and dushixiang committed May 16, 2021
1 parent c6a1310 commit 7b525ec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 38 deletions.
29 changes: 0 additions & 29 deletions server/api/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ",")
Expand Down
1 change: 0 additions & 1 deletion server/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
1 change: 1 addition & 0 deletions server/model/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions server/repository/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 4 additions & 8 deletions web/src/components/asset/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down

0 comments on commit 7b525ec

Please sign in to comment.