Skip to content

Commit

Permalink
RHINENG-10237: show template name and id in systems endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Jun 18, 2024
1 parent 6a88bab commit 543c19c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions base/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,9 @@ func InventoryHostsJoin(tx *gorm.DB, groups map[string]string) *gorm.DB {
}
return tx.Where(db)
}

// LEFT JOIN templates to sp (system_platform)
func JoinTemplates(tx *gorm.DB) *gorm.DB {
return tx.Joins("LEFT JOIN baseline bl ON sp.baseline_id = bl.id AND sp.rh_account_id = bl.rh_account_id").
Joins("LEFT JOIN template t ON sp.template_id = t.id AND sp.rh_account_id = t.rh_account_id")
}
36 changes: 36 additions & 0 deletions docs/v3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7118,6 +7118,12 @@
"items": {
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -7191,6 +7197,12 @@
"items": {
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -7913,6 +7925,12 @@
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
},
"updatable": {
"type": "boolean"
},
Expand Down Expand Up @@ -8191,6 +8209,12 @@
"items": {
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -8328,6 +8352,12 @@
"items": {
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -8451,6 +8481,12 @@
"$ref": "#/components/schemas/controllers.SystemTag"
}
},
"template_id": {
"type": "integer"
},
"template_name": {
"type": "string"
},
"third_party": {
"type": "boolean"
}
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/advisory_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AdvisorySystemItemAttributes struct {
SystemGroups
BaselineIDAttr
BaselineNameAttr
TemplateAttibutes
SystemAdvisoryStatus
SystemSatelliteManaged
SystemBuiltPkgcache
Expand Down Expand Up @@ -271,11 +272,10 @@ func AdvisorySystemsListIDsHandler(c *gin.Context) {

func buildAdvisorySystemsQuery(db *gorm.DB, account int, groups map[string]string, advisoryName string) *gorm.DB {
selectQuery := AdvisorySystemsSelect
query := database.SystemAdvisories(db, account, groups).
query := database.SystemAdvisories(db, account, groups, database.JoinTemplates).
Select(selectQuery).
Joins("JOIN advisory_metadata am ON am.id = sa.advisory_id").
Joins("LEFT JOIN status st ON sa.status_id = st.id").
Joins("LEFT JOIN baseline bl ON sp.baseline_id = bl.id AND sp.rh_account_id = bl.rh_account_id").
Where("am.name = ?", advisoryName).
Where("sp.stale = false")

Expand Down
5 changes: 5 additions & 0 deletions manager/controllers/common_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type BaselineIDAttr struct {
BaselineID int64 `json:"baseline_id" csv:"baseline_id" query:"bl.id" gorm:"column:baseline_id"`
}

type TemplateAttibutes struct {
TemplateName string `json:"template_name" csv:"template_name" query:"t.name" gorm:"column:template_name"`
TemplateID int64 `json:"template_id" csv:"template_id" query:"t.id" gorm:"column:template_id"`
}

type SystemDisplayName struct {
DisplayName string `json:"display_name" csv:"display_name" query:"sp.display_name" gorm:"column:display_name"`
}
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/package_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PackageSystemItem struct {
Updatable bool `json:"updatable" csv:"updatable" query:"(spkg.installable_id IS NOT NULL)" gorm:"column:updatable"`
SystemTags
BaselineAttributes
TemplateAttibutes
// helper to get AvailableEVRA (latest_evra)
InstallableEVRA string `json:"-" csv:"-" query:"pi.evra" gorm:"column:installable_evra"`
ApplicableEVRA string `json:"-" csv:"-" query:"pa.evra" gorm:"column:applicable_evra"`
Expand Down Expand Up @@ -61,11 +62,10 @@ func packagesByNameQuery(db *gorm.DB, pkgName string) *gorm.DB {

func packageSystemsQuery(db *gorm.DB, acc int, groups map[string]string, packageName string, packageIDs []int,
) *gorm.DB {
query := database.SystemPackages(db, acc, groups).
query := database.SystemPackages(db, acc, groups, database.JoinTemplates).
Select(PackageSystemsSelect).
Joins("LEFT JOIN package pi ON pi.id = spkg.installable_id").
Joins("LEFT JOIN package pa ON pa.id = spkg.applicable_id").
Joins("LEFT JOIN baseline bl ON sp.baseline_id = bl.id AND sp.rh_account_id = bl.rh_account_id").
Where("sp.stale = false").
Where("pn.name = ?", packageName).
Where("spkg.package_id in (?)", packageIDs)
Expand Down
3 changes: 1 addition & 2 deletions manager/controllers/system_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ func SystemDetailHandler(c *gin.Context) {

var systemDetail SystemDetailLookup
db := middlewares.DBFromContext(c)
query := database.Systems(db, account, groups).
query := database.Systems(db, account, groups, database.JoinTemplates).
Select(database.MustGetSelect(&systemDetail)).
Joins("LEFT JOIN baseline bl ON sp.baseline_id = bl.id AND sp.rh_account_id = bl.rh_account_id").
Where("sp.inventory_id = ?::uuid", inventoryID)

err := query.Take(&systemDetail).Error
Expand Down
5 changes: 2 additions & 3 deletions manager/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type SystemItemAttributes struct {
ApplicableRheaCount int `json:"applicable_rhea_count" csv:"applicable_rhea_count" query:"sp.applicable_advisory_enh_count_cache" gorm:"column:applicable_rhea_count"`
ApplicableOtherCount int `json:"applicable_other_count" csv:"applicable_other_count" query:"(sp.applicable_advisory_count_cache - sp.installable_advisory_sec_count_cache - sp.installable_advisory_bug_count_cache - sp.installable_advisory_enh_count_cache)" gorm:"column:applicable_other_count"`
BaselineIDAttr
TemplateAttibutes
SystemGroups
}

Expand Down Expand Up @@ -345,7 +346,5 @@ func SystemsListIDsHandler(c *gin.Context) {
}

func querySystems(db *gorm.DB, account int, groups map[string]string) *gorm.DB {
q := database.Systems(db, account, groups).
Joins("LEFT JOIN baseline bl ON sp.baseline_id = bl.id AND sp.rh_account_id = bl.rh_account_id")
return q.Select(SystemsSelect)
return database.Systems(db, account, groups, database.JoinTemplates).Select(SystemsSelect)
}

0 comments on commit 543c19c

Please sign in to comment.