Skip to content

Commit 2645bbb

Browse files
authored
Merge pull request #471 from cycloidio/fhacloid-tfpro-55-cli-nav-order
feat(middleware): add per-org sidebar nav ordering (GetOrgNav/UpdateOrgNav)
2 parents 48560c1 + b3edc85 commit 2645bbb

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

cmd/cycloid/middleware/middleware.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ type Middleware interface {
9898
GetOIDCIntegration(org string) (*OIDCIntegration, *http.Response, error)
9999
UpdateOIDCIntegration(org string, config map[string]interface{}) (*OIDCIntegration, *http.Response, error)
100100

101+
// organization_nav — per-org sidebar nav ordering
102+
GetOrgNav(org string) (*NavConfig, *http.Response, error)
103+
UpdateOrgNav(org string, items []*NavItem) (*NavConfig, *http.Response, error)
104+
101105
// organizations
102106
CreateOrganization(name string) (*models.Organization, *http.Response, error)
103107
UpdateOrganization(org, name string) (*models.Organization, *http.Response, error)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package middleware
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
)
7+
8+
// NavItem is a single sidebar entry with an explicit position.
9+
//
10+
// This type lives in the middleware package (not client/models) following the
11+
// same convention as OIDCOrganizationSettings: the endpoint is simple enough
12+
// (two fields, a GET/PUT pair) that a hand-defined type plus GenericRequest is
13+
// more direct than swagger-driven codegen for it.
14+
type NavItem struct {
15+
// Type is either "native" (a built-in section, identified by name, e.g.
16+
// "dashboard") or "plugin_widget" (identified by the widget's plugin ID as
17+
// a string).
18+
Type string `json:"type"`
19+
Key string `json:"key"`
20+
// Position is 1-indexed; positions must be unique within a NavConfig.
21+
Position uint32 `json:"position"`
22+
}
23+
24+
// NavConfig is the per-organization sidebar nav ordering configuration.
25+
// Items is empty when no ordering has been saved — the console falls back to
26+
// its default ordering in that case.
27+
type NavConfig struct {
28+
Items []*NavItem `json:"items"`
29+
}
30+
31+
// GetOrgNav returns the org's sidebar nav ordering config.
32+
func (m *middleware) GetOrgNav(org string) (*NavConfig, *http.Response, error) {
33+
var result *NavConfig
34+
resp, err := m.GenericRequest(Request{
35+
Method: "GET",
36+
Organization: &org,
37+
Route: []string{"organizations", org, "nav"},
38+
}, &result)
39+
if err != nil {
40+
return nil, resp, fmt.Errorf("failed to get organization nav ordering: %w", err)
41+
}
42+
return result, resp, nil
43+
}
44+
45+
// UpdateOrgNav creates or replaces the org's sidebar nav ordering config.
46+
// Passing an empty (or nil) items slice resets the ordering to defaults.
47+
func (m *middleware) UpdateOrgNav(org string, items []*NavItem) (*NavConfig, *http.Response, error) {
48+
body := &NavConfig{Items: items}
49+
if body.Items == nil {
50+
body.Items = []*NavItem{}
51+
}
52+
53+
var result *NavConfig
54+
resp, err := m.GenericRequest(Request{
55+
Method: "PUT",
56+
Organization: &org,
57+
Route: []string{"organizations", org, "nav"},
58+
Body: body,
59+
}, &result)
60+
if err != nil {
61+
return nil, resp, fmt.Errorf("failed to update organization nav ordering: %w", err)
62+
}
63+
return result, resp, nil
64+
}

0 commit comments

Comments
 (0)