mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +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",
|
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)
|
project := context.Get(r, "project").(db.Project)
|
||||||
|
|
||||||
params := helpers.QueryParams(r.URL)
|
params := helpers.QueryParamsWithOwner(r.URL, db.InventoryProps)
|
||||||
params.Ownership.WithoutOwnerOnly = true
|
|
||||||
inventories, err := helpers.Store(r).GetInventories(project.ID, params)
|
inventories, err := helpers.Store(r).GetInventories(project.ID, params)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
11
db/Store.go
11
db/Store.go
@ -75,7 +75,7 @@ type IntegrationExtractorChildReferrers struct {
|
|||||||
Integrations []ObjectReferrer `json:"integrations"`
|
Integrations []ObjectReferrer `json:"integrations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f OwnershipFilter) GetOwnerID(ownership ObjectProps) *int {
|
func (f *OwnershipFilter) GetOwnerID(ownership ObjectProps) *int {
|
||||||
switch ownership.ReferringColumnSuffix {
|
switch ownership.ReferringColumnSuffix {
|
||||||
case "template_id":
|
case "template_id":
|
||||||
return f.TemplateID
|
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.
|
// ObjectProps describe database entities.
|
||||||
// It mainly used for NoSQL implementations (currently BoltDB) to preserve same
|
// It mainly used for NoSQL implementations (currently BoltDB) to preserve same
|
||||||
// data structure of different implementations and easy change it if required.
|
// data structure of different implementations and easy change it if required.
|
||||||
|
@ -452,11 +452,19 @@ export default {
|
|||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
})).data;
|
})).data;
|
||||||
|
|
||||||
this.inventory = (await axios({
|
this.inventory = [
|
||||||
|
...(await axios({
|
||||||
keys: 'get',
|
keys: 'get',
|
||||||
url: `/api/project/${this.projectId}/inventory`,
|
url: `/api/project/${this.projectId}/inventory?app=${this.app}&template_id=${this.itemId}`,
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
})).data;
|
})).data,
|
||||||
|
|
||||||
|
...(await axios({
|
||||||
|
keys: 'get',
|
||||||
|
url: `/api/project/${this.projectId}/inventory?app=${this.app}`,
|
||||||
|
responseType: 'json',
|
||||||
|
})).data,
|
||||||
|
];
|
||||||
|
|
||||||
this.environment = (await axios({
|
this.environment = (await axios({
|
||||||
keys: 'get',
|
keys: 'get',
|
||||||
|
Loading…
Reference in New Issue
Block a user