Exemple #1
0
func projectHandler(w http.ResponseWriter, r *http.Request, s *sessions.Session) error {
	vars := mux.Vars(r)
	pid := vars["pid"]
	userid := s.Values["userid"].(string)

	p, err := project.Fetch(pid)
	if err != nil {
		return &gapp.HandlerError{Err: err, Message: "Not Found", Code: http.StatusNotFound}
	}

	data := map[string]interface{}{
		"BUILD":           gapp.BuildId,
		"project":         p,
		"userid":          userid,
		"projectPage":     map[string]bool{"detail": true},
		"title":           p.Name,
		"keywords":        "project detail",
		"myProjectsCount": project.ListCount(userid),
		"jobsCount":       project.JobsCount(userid),
	}

	err = gapp.Templates.ExecuteTemplate(w, "project.html", data)
	if err != nil {
		return err
	}

	return nil
}
Exemple #2
0
func deleteProjectHandler(w http.ResponseWriter, r *http.Request, s *sessions.Session) error {
	vars := mux.Vars(r)
	pid := vars["pid"]
	userid := s.Values["userid"].(string)

	p, err := project.Fetch(pid)
	if err != nil {
		return &gapp.HandlerError{Err: err, Message: "Not Found", Code: http.StatusNotFound}
	}

	if p.Mine(userid) {
		return p.Delete()
	}

	return &gapp.HandlerError{Err: errors.New("Permission Denied"), Message: "Permission Denied", Code: http.StatusForbidden}
}