Skip to content

Commit c44eed4

Browse files
committed
Add getPendingVersion admin endpoint
1 parent da95121 commit c44eed4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

web/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func Router() *echo.Echo {
379379
g.HEAD("/pending", getPendingVersions, jsonEndpoint, middleware.Gzip())
380380
g.GET("/pending", getPendingVersions, jsonEndpoint, middleware.Gzip())
381381
g.PUT("/pending/:app/:version/approval", approvePendingVersion, middleware.Gzip())
382+
g.GET("/pending/:app/:version", getPendingVersion, jsonEndpoint, middleware.Gzip())
382383
g.DELETE("/pending/:app/:version", deletePendingVersion, middleware.Gzip())
383384

384385
g.GET("/maintenance", getMaintenanceApps, jsonEndpoint, middleware.Gzip())

web/versions.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ func getPendingVersions(c echo.Context) (err error) {
138138
return c.JSON(http.StatusOK, filteredVersions)
139139
}
140140

141-
func approvePendingVersion(c echo.Context) (err error) {
141+
func lookForPendingVersion(c echo.Context) (app *registry.App, version *registry.Version, err error) {
142142
if err = checkAuthorized(c); err != nil {
143-
return err
143+
return nil, nil, err
144144
}
145145

146146
// Only allow approving versions from editor cozy
@@ -149,23 +149,32 @@ func approvePendingVersion(c echo.Context) (err error) {
149149
editorName := "cozy"
150150
_, err = checkPermissions(c, editorName, "", true /* = master */)
151151
if err != nil {
152-
return errshttp.NewError(http.StatusUnauthorized, err.Error())
152+
return nil, nil, errshttp.NewError(http.StatusUnauthorized, err.Error())
153153
}
154154

155155
appSlug := c.Param("app")
156156
if appSlug == "" {
157-
return errshttp.NewError(http.StatusNotFound, "App is missing in the URL")
157+
return nil, nil, errshttp.NewError(http.StatusNotFound, "App is missing in the URL")
158158
}
159-
app, err := registry.FindApp(nil, getSpace(c), appSlug, registry.Stable)
159+
app, err = registry.FindApp(nil, getSpace(c), appSlug, registry.Stable)
160160
if err != nil {
161-
return err
161+
return nil, nil, err
162162
}
163163

164164
ver := stripVersion(c.Param("version"))
165165
if ver == "" {
166-
return errshttp.NewError(http.StatusNotFound, "Version is missing in the URL")
166+
return nil, nil, errshttp.NewError(http.StatusNotFound, "Version is missing in the URL")
167167
}
168-
version, err := registry.FindPendingVersion(getSpace(c), appSlug, ver)
168+
version, err = registry.FindPendingVersion(getSpace(c), appSlug, ver)
169+
if err != nil {
170+
return nil, nil, err
171+
}
172+
173+
return app, version, nil
174+
}
175+
176+
func approvePendingVersion(c echo.Context) (err error) {
177+
app, version, err := lookForPendingVersion(c)
169178
if err != nil {
170179
return err
171180
}
@@ -179,6 +188,17 @@ func approvePendingVersion(c echo.Context) (err error) {
179188
return c.JSON(http.StatusCreated, version)
180189
}
181190

191+
func getPendingVersion(c echo.Context) (err error) {
192+
_, version, err := lookForPendingVersion(c)
193+
if err != nil {
194+
return err
195+
}
196+
197+
cleanVersion(version)
198+
199+
return c.JSON(http.StatusOK, version)
200+
}
201+
182202
func deletePendingVersion(c echo.Context) (err error) {
183203
if err = checkAuthorized(c); err != nil {
184204
return err

0 commit comments

Comments
 (0)