Ejemplo n.º 1
0
func (c AdminApplication) ShowStudentGrades(studentIdString string, mpNumString string) revel.Result {

	studentId, err := strconv.Atoi(studentIdString)
	if err != nil {
		c.Flash.Error("Invalid user Id")
		return c.Render(routes.PublicApplication.Index())
	}
	mpNum, err := strconv.Atoi(mpNumString)
	if err != nil {
		c.Flash.Error("Invalid mp Id")
		return c.Render(routes.PublicApplication.Index())
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		c.Flash.Error("No admin privilages")
		return c.Render(routes.PublicApplication.Index())
	}

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		c.Flash.Error("Cannot find user")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)
	grades, _ := models.FindGradesByMachineProblem(mp)

	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp"] = mp
	c.RenderArgs["student"] = student
	c.RenderArgs["grades"] = grades

	return c.Render()
}
Ejemplo n.º 2
0
func (c AdminApplication) ShowStudentGrade(studentIdString string, mpNumString string, gradeIdString string) revel.Result {

	studentId, err := strconv.Atoi(studentIdString)
	if err != nil {
		c.Flash.Error("Invalid user Id")
		return c.Render(routes.PublicApplication.Index())
	}
	mpNum, err := strconv.Atoi(mpNumString)
	if err != nil {
		c.Flash.Error("Invalid mp Id")
		return c.Render(routes.PublicApplication.Index())
	}
	gradeId, err := strconv.Atoi(gradeIdString)
	if err != nil {
		c.Flash.Error("Invalid grade Id")
		return c.Render(routes.PublicApplication.Index())
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		c.Flash.Error("No admin privilages")
		return c.Render(routes.PublicApplication.Index())
	}

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		c.Flash.Error("Cannot find user")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)
	grade, _ := models.FindGrade(int64(gradeId))
	attempt, _ := models.FindAttempt(grade.AttemptInstanceId)
	program, _ := models.FindProgram(attempt.ProgramInstanceId)
	qs, _ := models.FindQuestionsByMachineProblem(mp)
	qis, _ := models.FindQuestionItems(mp, qs)

	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp"] = mp
	c.RenderArgs["student"] = student
	c.RenderArgs["grade"] = grade
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = program
	c.RenderArgs["questions"] = qis
	bg, err := getBigCodeSuggestion(mpNum, program)
	if err != nil {
		revel.INFO.Println("Failed to get big code suggestion  :::  ", err)
	} else {
		revel.INFO.Println("Got bigcode suggestions")
		c.RenderArgs["bigcode"] = bg
		c.RenderArgs["bigcode_min"] = bg[0]
		c.RenderArgs["bigcode_max"] = bg[1]
		c.RenderArgs["bigcode_random"] = bg[2]
	}

	return c.Render()
}
Ejemplo n.º 3
0
func (c AdminApplication) ShowStudentAttempt(studentIdString string, mpNumString string, attemptIdString string) revel.Result {

	studentId, err := strconv.Atoi(studentIdString)
	if err != nil {
		c.Flash.Error("Invalid user Id")
		return c.Render(routes.PublicApplication.Index())
	}
	mpNum, err := strconv.Atoi(mpNumString)
	if err != nil {
		c.Flash.Error("Invalid mp Id")
		return c.Render(routes.PublicApplication.Index())
	}
	attemptId, err := strconv.Atoi(attemptIdString)
	if err != nil {
		c.Flash.Error("Invalid attempt Id")
		return c.Render(routes.PublicApplication.Index())
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		c.Flash.Error("No admin privilages")
		return c.Render(routes.PublicApplication.Index())
	}

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		c.Flash.Error("Cannot find user")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)
	attempt, _ := models.FindAttempt(int64(attemptId))
	program, _ := models.FindProgram(attempt.ProgramInstanceId)
	qs, _ := models.FindQuestionsByMachineProblem(mp)
	qis, _ := models.FindQuestionItems(mp, qs)

	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp"] = mp
	c.RenderArgs["student"] = student
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = program
	c.RenderArgs["questions"] = qis

	return c.Render()
}
Ejemplo n.º 4
0
func (c PublicApplication) UpdatePassword(userIdString string, secret string) revel.Result {

	var pass, passConfirm string

	c.Params.Bind(&pass, "password")
	c.Params.Bind(&passConfirm, "password_confirm")

	revel.TRACE.Println(pass)
	revel.TRACE.Println(passConfirm)

	redirect := c.Redirect(routes.PublicApplication.UpdatePasswordForm(userIdString, secret))

	if pass != passConfirm {
		c.Flash.Error("The two passwords provided did not match.")
		return redirect
	}
	if pass == "" {
		c.Flash.Error("The two password provided is blank.")
		return redirect
	}

	userId, err := strconv.Atoi(userIdString)
	if err != nil {
		c.Flash.Error("Invalid reset password link.")
		return redirect
	}
	user, err := models.FindUser(int64(userId))
	if err != nil {
		c.Flash.Error("User not found.")
		return redirect
	}
	if !validPasswordResetLink(user, secret) {
		c.Flash.Error("Password reset link is not valid.")
		return redirect
	}

	if err := models.ResetUserPassword(user, pass); err != nil {
		c.Flash.Error("Was not able to rest password.")
		return redirect
	}
	c.Flash.Success("Password has been reset successfully. Please login with your new password.")
	return c.Redirect(routes.PublicApplication.Login())
}
Ejemplo n.º 5
0
func (c PublicApplication) UpdatePasswordForm(userIdString, secret string) revel.Result {
	userId, err := strconv.Atoi(userIdString)
	if err != nil {
		c.Flash.Error("Invalid reset password link.")
		return c.Redirect(routes.PublicApplication.Index())
	}
	user, err := models.FindUser(int64(userId))
	if err != nil {
		c.Flash.Error("User not found.")
		return c.Redirect(routes.PublicApplication.Index())
	}
	if validPasswordResetLink(user, secret) {
		c.RenderArgs["user_id"] = userIdString
		c.RenderArgs["secret"] = secret
		return c.Render()
	}
	c.Flash.Error("Password reset link is not valid.")
	return c.Redirect(routes.PublicApplication.Index())
}
Ejemplo n.º 6
0
func (c AdminApplication) UpdateStudentMachineProblem(studentIdString string, mpNumString string) revel.Result {
	type gradeInformation struct {
		CodeScore           int64  `json:"code_score"`
		CodeInspectionScore int64  `json:"code_inspection_score"`
		CodeComment         string `json:"code_comment"`
		QuestionsScore      int64  `json:"questions_score"`
		QuestionsComment    string `json:"questions_comment"`
		TaCodeText          string `json:"ta_code_text"`
	}
	var gradeUpdate gradeInformation
	var gradeString string

	studentId, err := strconv.Atoi(studentIdString)
	if err != nil {
		c.Flash.Error("Invalid user Id")
		return c.Render(routes.PublicApplication.Index())
	}
	mpNum, err := strconv.Atoi(mpNumString)
	if err != nil {
		c.Flash.Error("Invalid mp Id")
		return c.Render(routes.PublicApplication.Index())
	}

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "No user found",
			"data":   "Cannot find user.",
			"error":  err,
		})
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "No admin privilages",
			"data":   "Cannot perform request because of lack of admin privilages.",
			"error":  "",
		})
	}

	c.Params.Bind(&gradeString, "grade")
	if err := json.Unmarshal([]byte(gradeString), &gradeUpdate); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot parse grade update request.",
			"data":   "The system was not able to parse your grade update request.",
			"error":  err,
		})
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)

	if _, err := models.UpdateGradeTA(mp, gradeUpdate.CodeScore, gradeUpdate.CodeInspectionScore,
		gradeUpdate.QuestionsScore, gradeUpdate.CodeComment, gradeUpdate.QuestionsComment,
		gradeUpdate.TaCodeText); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Not able to update the database",
			"data":   "Cannot update the grades database.",
			"error":  err,
		})
	}
	//sendEmailToStudent(student)
	link := "/admin/student/" + strconv.Itoa(int(student.Id)) + "/mp/" + strconv.Itoa(int(mp.Number))
	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"title":  "Grade has been updated",
		"link":   link,
	})
}
Ejemplo n.º 7
0
func (c AdminApplication) ShowStudentMachineProblem(studentIdString string, mpNumString string) revel.Result {

	studentId, err := strconv.Atoi(studentIdString)
	if err != nil {
		c.Flash.Error("Invalid user Id")
		return c.Render(routes.PublicApplication.Index())
	}
	mpNum, err := strconv.Atoi(mpNumString)
	if err != nil {
		c.Flash.Error("Invalid mp Id")
		return c.Render(routes.PublicApplication.Index())
	}

	admin := c.connected()
	if !models.IsAdmin(admin) {
		c.Flash.Error("No admin privilages")
		return c.Render(routes.PublicApplication.Index())
	}

	conf, _ := ReadMachineProblemConfig(mpNum)

	student, err := models.FindUser(int64(studentId))
	if err != nil {
		c.Flash.Error("Cannot find user")
		return c.Render(routes.PublicApplication.Index())
	}

	mp, _ := models.FindMachineProblemByUser(student, mpNum)
	grade, _ := models.FindGradeByMachineProblem(mp)
	attempt, _ := models.FindAttempt(grade.AttemptInstanceId)
	program, _ := models.FindProgram(attempt.ProgramInstanceId)
	qs, _ := models.FindQuestionsByMachineProblem(mp)
	qis, _ := models.FindQuestionItems(mp, qs)

	c.RenderArgs["admin"] = admin
	c.RenderArgs["mp_num"] = mpNum
	c.RenderArgs["mp_config"] = conf
	c.RenderArgs["student"] = student
	c.RenderArgs["mp"] = mp
	c.RenderArgs["attempt"] = attempt
	c.RenderArgs["program"] = program
	c.RenderArgs["questions"] = qis
	c.RenderArgs["grade"] = grade
	bg, err := getBigCodeSuggestion(mpNum, program)
	if err != nil {
		revel.INFO.Println("Failed to get big code suggestion  :::  ", err)
	} else if len(bg) != 3 {
		revel.INFO.Println("The number of suggestions recieved was  :::  ", len(bg), " was expecting 3")
	} else {
		//revel.INFO.Println("Got bigcode suggestions")
		//revel.INFO.Println("min  = ", bg[0])

		c.RenderArgs["bigcode"] = bg
		c.RenderArgs["bigcode_min"] = bg[0]
		c.RenderArgs["bigcode_max"] = bg[1]
		c.RenderArgs["bigcode_random"] = bg[2]

		randomSelection := rand.Intn(3)
		switch randomSelection {
		case 0:
			c.RenderArgs["bigcode_min_active"] = "active"
			c.RenderArgs["bigcode_max_active"] = ""
			c.RenderArgs["bigcode_random_active"] = ""
		case 1:
			c.RenderArgs["bigcode_min_active"] = ""
			c.RenderArgs["bigcode_max_active"] = "active"
			c.RenderArgs["bigcode_random_active"] = ""
		case 2:
			c.RenderArgs["bigcode_min_active"] = ""
			c.RenderArgs["bigcode_max_active"] = ""
			c.RenderArgs["bigcode_random_active"] = "active"
		}
	}

	return c.Render()
}
Ejemplo n.º 8
0
func (c CourseraApplication) PostGrade(gradeIdString string, toPostString string, forceString string) revel.Result {

	gradeId, err := strconv.Atoi(gradeIdString)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Invalid grade Id.",
		})
	}

	user := c.connected()

	grade, err := models.FindGrade(int64(gradeId))
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Cannot find grade record.",
		})
	}

	mp, err := models.FindMachineProblem(grade.MachineProblemId)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "Cannot find machine problem record.",
		})
	}

	mpUser, err := models.FindUser(mp.UserInstanceId)
	if err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "User not found.",
		})
	}

	if mpUser.Id != user.Id {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Cannot Submit Grade to Coursera.",
			"data":   "User did not match.",
		})
	}

	forceQ := forceString == "true"

	if forceQ == false && grade.PeerReviewScore > 0 && grade.PeerReviewScore < grade.CourseraPeerReviewGrade {
		s := fmt.Sprint("Trying to post a code grade of ", grade.PeerReviewScore,
			" to Coursera, while Coursera has a higher score of ", grade.CourseraPeerReviewGrade)
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: PeerReview Grade lower than what has been previously posted to Coursera",
			"data":   s,
		})
	}
	if forceQ == false && grade.CodeScore > 0 && grade.CodeScore < grade.CourseraCodingGrade {
		s := fmt.Sprint("Trying to post a code grade of ", grade.CodeScore,
			" to Coursera, while Coursera has a higher score of ", grade.CourseraCodingGrade)
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"title":  "Error: Code Grade lower than what has been previously posted to Coursera",
			"data":   s,
		})
	}

	if err = doPostCourseraGrade(user, mp, grade, toPostString, forceQ); err != nil {
		return c.RenderJson(map[string]interface{}{
			"status": "error",
			"data":   "Was not able to post coursera grade. Make sure you are connected to coursera first.",
		})
	}

	c.Flash.Success("Grade has been posted to Coursera.")

	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"title":  "Grade has been posted to Coursera.",
		"data":   "Grade has been posted to Coursera.",
	})
}