github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/service/rest_project.go (about) 1 package service 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "github.com/evergreen-ci/evergreen/model" 8 ) 9 10 // Returns a JSON response of an array with the ref information for the requested project_id. 11 func (restapi restAPI) getProject(w http.ResponseWriter, r *http.Request) { 12 projCtx := MustHaveRESTContext(r) 13 ref := projCtx.ProjectRef 14 if ref == nil { 15 restapi.WriteJSON(w, http.StatusNotFound, responseError{Message: "error finding project"}) 16 return 17 } 18 // unset alerts so we don't expose emails through the API 19 ref.Alerts = nil 20 restapi.WriteJSON(w, http.StatusOK, ref) 21 return 22 } 23 24 // getProjectsIds returns a JSON response of an array of active project Ids. 25 // Users must use credentials to see private projects. 26 func (restapi restAPI) getProjectIds(w http.ResponseWriter, r *http.Request) { 27 u := GetUser(r) 28 refs, err := model.FindAllProjectRefs() 29 if err != nil { 30 restapi.WriteJSON(w, http.StatusNotFound, responseError{ 31 Message: fmt.Sprintf("error finding projects: %v", err), 32 }) 33 return 34 } 35 projects := []string{} 36 for _, r := range refs { 37 if r.Enabled && (!r.Private || u != nil) { 38 projects = append(projects, r.Identifier) 39 } 40 } 41 restapi.WriteJSON(w, http.StatusOK, struct { 42 Projects []string `json:"projects"` 43 }{projects}) 44 return 45 }