fix: 修复权限组用户看不到实例的bug — AccessibleInstances第二次Pluck覆盖第一次结果,改为单条OR查询
This commit is contained in:
1 parent
ed43f6f398
commit
c6ef67adba
1 file changed
+2
-11
@@ -34,19 +34,10 @@ func AccessibleInstances(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
var instanceIDs []int
|
||||
// Query for the requested access_type OR readwrite (readwrite grants both)
|
||||
model.DB.Model(&model.InstanceGroupMember{}).
|
||||
Where("group_id IN ? AND access_type = ?", groupIDs, accessType).
|
||||
Where("group_id IN ? AND (access_type = ? OR access_type = ?)", groupIDs, accessType, "readwrite").
|
||||
Pluck("instance_id", &instanceIDs)
|
||||
// also include readwrite
|
||||
if accessType == "readonly" {
|
||||
model.DB.Model(&model.InstanceGroupMember{}).
|
||||
Where("group_id IN ? AND access_type = ?", groupIDs, "readwrite").
|
||||
Pluck("instance_id", &instanceIDs)
|
||||
} else if accessType == "write" {
|
||||
model.DB.Model(&model.InstanceGroupMember{}).
|
||||
Where("group_id IN ? AND access_type = ?", groupIDs, "readwrite").
|
||||
Pluck("instance_id", &instanceIDs)
|
||||
}
|
||||
if len(instanceIDs) == 0 {
|
||||
c.JSON(http.StatusOK, []model.Instance{})
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user