Skip to content

Commit 8cf7fb7

Browse files
committed
Merge pull request grafana#3712 from schen59/master-schen
add get org by name api (issue grafana#3600)
2 parents a87b5f7 + dc427d5 commit 8cf7fb7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/api/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func Register(r *macaron.Macaron) {
147147
r.Put("/quotas/:target", bind(m.UpdateOrgQuotaCmd{}), wrap(UpdateOrgQuota))
148148
}, reqGrafanaAdmin)
149149

150+
// orgs (admin routes)
151+
r.Group("/orgs/name/:name", func() {
152+
r.Get("/", wrap(GetOrgByName))
153+
}, reqGrafanaAdmin)
154+
150155
// auth api keys
151156
r.Group("/auth/keys", func() {
152157
r.Get("/", wrap(GetApiKeys))

pkg/api/org.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ func GetOrgById(c *middleware.Context) Response {
2020
return getOrgHelper(c.ParamsInt64(":orgId"))
2121
}
2222

23+
// Get /api/orgs/:name
24+
func GetOrgByName(c *middleware.Context) Response {
25+
query := m.GetOrgByNameQuery{Name: c.Params(":name")}
26+
if err := bus.Dispatch(&query); err != nil {
27+
if err == m.ErrOrgNotFound {
28+
return ApiError(404, "Organization not found", err)
29+
}
30+
31+
return ApiError(500, "Failed to get organization", err)
32+
}
33+
org := query.Result
34+
result := m.OrgDetailsDTO{
35+
Id: org.Id,
36+
Name: org.Name,
37+
Address: m.Address{
38+
Address1: org.Address1,
39+
Address2: org.Address2,
40+
City: org.City,
41+
ZipCode: org.ZipCode,
42+
State: org.State,
43+
Country: org.Country,
44+
},
45+
}
46+
47+
return Json(200, &result)
48+
}
49+
2350
func getOrgHelper(orgId int64) Response {
2451
query := m.GetOrgByIdQuery{Id: orgId}
2552

0 commit comments

Comments
 (0)