diff --git a/backend/internal/handler/instance_extra.go b/backend/internal/handler/instance_extra.go index f529cbc..d2000be 100644 --- a/backend/internal/handler/instance_extra.go +++ b/backend/internal/handler/instance_extra.go @@ -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