Пример #1
0
func setHighlightHandler(v string, w http.ResponseWriter, r *http.Request) {
	// TODO: use and enforce PUT
	var arg FetchCommentsEnv
	err := util.StringToJSON(v, &arg)
	if err != nil {
		panic(err)
	}
	var req struct {
		ReaderId string `json:"readerId"`
	}
	err = util.ReaderToJSON(r.Body, int(r.ContentLength), &req)
	if err != nil {
		panic(err)
	}
	now := time.Now().Unix()
	hl := &model.Highlight{
		arg.AppId,
		model.ReviewerId(req.ReaderId),
		arg.ReviewerId,
		arg.ReviewerName,
		float64(now),
	}
	err = dept.SetHighlight(hl)
	if err != nil {
		panic(err)
	}
	w.WriteHeader(200)
}
Пример #2
0
func fetchCommentsHandler(key string, w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		panic("expected GET")
	}

	query, err := url.ParseQuery(r.URL.RawQuery)
	if err != nil {
		panic(err)
	}
	appId := query.Get("appId")

	comments, err := dept.LoadComments(appId)
	if err != nil {
		panic(err)
	}

	rev, err := dept.GetReviewerById(model.ReviewerId(key))
	if err != nil {
		panic(err)
	}

	env, err := util.JSONToString(&FetchCommentsEnv{rev.Name, rev.Id, appId})
	if err != nil {
		panic(err)
	}

	highlightedBy, err := dept.HighlightsByApp(appId)
	if err != nil {
		panic(err)
	}

	_ = util.JSONResponse(w, map[string]interface{}{
		"appId":          appId,
		"comments":       comments,
		"post":           capServer.Grant(postCommentKey, env),
		"setScoreCap":    capServer.Grant(setScoreKey, env),
		"highlightCap":   capServer.Grant(setHighlightKey, env),
		"unhighlightCap": capServer.Grant(delHighlightKey, env),
		"highlightedBy":  highlightedBy,
	})

	log.Printf("%v fetched comments for %v", key, appId)
}
Пример #3
0
// Authenticates a login request and returns capabilities to initial data.
func loginHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "POST" {
		log.Printf("Invalid request: %v", r)
		return
	}
	var cred struct {
		Username string `json:"username"`
		Password string `json:"password"`
	}
	err := util.JSONBody(r, &cred)
	if err != nil {
		panic(fmt.Sprintf("invalid request: %v", err))
	}

	log.Printf("%v attempt to login", cred.Username)
	rev, err := dept.AuthReviewer(model.ReviewerId(cred.Username), cred.Password)
	if err != nil {
		util.JSONResponse(w,
			map[string]interface{}{"msg": "invalid username or password"})
		return
	}

	reviewers, err := dept.GetReviewerIdMap()
	if err != nil {
		panic(err)
	}

	matsCap := capServer.Grant(materialKey, cred.Username)

	err = util.JSONResponse(w, map[string]interface{}{
		"revId":            cred.Username,
		"friendlyName":     rev.Name,
		"appsCap":          capServer.Grant(dataKey, cred.Username),
		"materialsCap":     matsCap,
		"fetchCommentsCap": capServer.Grant(fetchCommentsKey, cred.Username),
		"reviewers":        reviewers,
	})
	if err != nil {
		panic("serializing response")
	}
	return
}
Пример #4
0
		if err != nil {
			panic(err)
		}
	},
	Short: "create a new, empty department",
}

var cmdNewReviewer = &Command{
	Short: "create a new reviewer account",
	Usage: `USERNAME PASSWORD "Full Name"`,
	Run: func(args []string) {
		dept, err := model.LoadDept(dbconn.Host, dbconn.Port)
		if err != nil {
			panic(err)
		}
		dept.NewReviewer(model.ReviewerId(args[0]), args[2], args[1])
		if err != nil {
			panic(err)
		}
	},
}

var cmdLoadApps = &Command{
	Short: "load applicant information",
	Usage: `DEPT_PATH`,
	Run: func(args []string) {
		src, err := ioutil.ReadFile(args[0])
		if err != nil {
			panic(err)
		}
		var applications []model.Application