-
Notifications
You must be signed in to change notification settings - Fork 124
/
rest_project.go
44 lines (39 loc) · 1.18 KB
/
rest_project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package service
import (
"fmt"
"net/http"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/gimlet"
)
// Returns a JSON response of an array with the ref information for the requested project_id.
func (restapi restAPI) getProjectRef(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveRESTContext(r)
ref := projCtx.ProjectRef
if ref == nil {
gimlet.WriteJSONResponse(w, http.StatusNotFound, responseError{Message: "error finding project"})
return
}
gimlet.WriteJSON(w, ref)
}
// getProjectsIds returns a JSON response of an array of active project Ids.
// Users must use credentials to see private projects.
func (restapi restAPI) getProjectIds(w http.ResponseWriter, r *http.Request) {
refs, err := model.FindAllMergedProjectRefs()
if err != nil {
gimlet.WriteJSONResponse(w, http.StatusNotFound, responseError{
Message: fmt.Sprintf("error finding projects: %v", err),
})
return
}
ctx := r.Context()
u := gimlet.GetUser(ctx)
projects := []string{}
for _, r := range refs {
if r.Enabled && (!r.IsPrivate() || u != nil) {
projects = append(projects, r.Id)
}
}
gimlet.WriteJSON(w, struct {
Projects []string `json:"projects"`
}{projects})
}