mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
feat(inventory): use ownership filtering
This commit is contained in:
parent
dc347442c4
commit
aae2b572f5
@ -130,3 +130,30 @@ func QueryParams(url *url.URL) db.RetrieveQueryParams {
|
||||
SortInverted: url.Query().Get("order") == "desc",
|
||||
}
|
||||
}
|
||||
|
||||
func QueryParamsWithOwner(url *url.URL, props db.ObjectProps) db.RetrieveQueryParams {
|
||||
res := QueryParams(url)
|
||||
|
||||
hasOwnerFilter := false
|
||||
|
||||
for _, ownership := range props.Ownerships {
|
||||
s := url.Query().Get(ownership.ReferringColumnSuffix)
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
res.Ownership.SetOwnerID(*ownership, id)
|
||||
hasOwnerFilter = true
|
||||
}
|
||||
|
||||
if !hasOwnerFilter {
|
||||
res.Ownership.WithoutOwnerOnly = true
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ func GetInventory(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
project := context.Get(r, "project").(db.Project)
|
||||
|
||||
params := helpers.QueryParams(r.URL)
|
||||
params.Ownership.WithoutOwnerOnly = true
|
||||
params := helpers.QueryParamsWithOwner(r.URL, db.InventoryProps)
|
||||
|
||||
inventories, err := helpers.Store(r).GetInventories(project.ID, params)
|
||||
|
||||
if err != nil {
|
||||
|
11
db/Store.go
11
db/Store.go
@ -75,7 +75,7 @@ type IntegrationExtractorChildReferrers struct {
|
||||
Integrations []ObjectReferrer `json:"integrations"`
|
||||
}
|
||||
|
||||
func (f OwnershipFilter) GetOwnerID(ownership ObjectProps) *int {
|
||||
func (f *OwnershipFilter) GetOwnerID(ownership ObjectProps) *int {
|
||||
switch ownership.ReferringColumnSuffix {
|
||||
case "template_id":
|
||||
return f.TemplateID
|
||||
@ -86,6 +86,15 @@ func (f OwnershipFilter) GetOwnerID(ownership ObjectProps) *int {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *OwnershipFilter) SetOwnerID(ownership ObjectProps, ownerID int) {
|
||||
switch ownership.ReferringColumnSuffix {
|
||||
case "template_id":
|
||||
f.TemplateID = &ownerID
|
||||
case "environment_id":
|
||||
f.EnvironmentID = &ownerID
|
||||
}
|
||||
}
|
||||
|
||||
// ObjectProps describe database entities.
|
||||
// It mainly used for NoSQL implementations (currently BoltDB) to preserve same
|
||||
// data structure of different implementations and easy change it if required.
|
||||
|
@ -452,11 +452,19 @@ export default {
|
||||
responseType: 'json',
|
||||
})).data;
|
||||
|
||||
this.inventory = (await axios({
|
||||
this.inventory = [
|
||||
...(await axios({
|
||||
keys: 'get',
|
||||
url: `/api/project/${this.projectId}/inventory`,
|
||||
url: `/api/project/${this.projectId}/inventory?app=${this.app}&template_id=${this.itemId}`,
|
||||
responseType: 'json',
|
||||
})).data;
|
||||
})).data,
|
||||
|
||||
...(await axios({
|
||||
keys: 'get',
|
||||
url: `/api/project/${this.projectId}/inventory?app=${this.app}`,
|
||||
responseType: 'json',
|
||||
})).data,
|
||||
];
|
||||
|
||||
this.environment = (await axios({
|
||||
keys: 'get',
|
||||
|
Loading…
Reference in New Issue
Block a user