本文整理匯總了Golang中github.com/hfurubotten/autograder/entities.NewOrganization函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewOrganization函數的具體用法?Golang NewOrganization怎麽用?Golang NewOrganization使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewOrganization函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HomeHandler
// HomeHandler is a http handler for the home page for logged in users.
func HomeHandler(w http.ResponseWriter, r *http.Request) {
member, err := checkMemberApproval(w, r, true)
if err != nil {
return
}
view := HomeView{
StdTemplate: StdTemplate{
Member: member,
},
Teaching: make(map[string]*git.Organization),
Assisting: make(map[string]*git.Organization),
Courses: make(map[string]*git.Organization),
}
for key := range member.Teaching {
view.Teaching[key], _ = git.NewOrganization(key, true)
}
for key := range member.AssistantCourses {
view.Assisting[key], _ = git.NewOrganization(key, true)
}
for key := range member.Courses {
view.Courses[key], _ = git.NewOrganization(key, true)
}
if !member.IsComplete() {
http.Redirect(w, r, pages.REGISTER_REDIRECT, 307)
return
}
execTemplate("home.html", w, view)
}
示例2: RequestRandomGroupHandler
// RequestRandomGroupHandler is a http handler used by a student to request a random group assignment.
func RequestRandomGroupHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
orgname := r.FormValue("course")
if !git.HasOrganization(orgname) {
http.Error(w, "Does not have organization.", 404)
}
org, err := git.NewOrganization(orgname, false)
if err != nil {
http.Error(w, "Does not have organization.", 404)
}
defer func() {
err := org.Save()
if err != nil {
org.Unlock()
log.Println(err)
}
}()
org.PendingRandomGroup[member.Username] = nil
}
示例3: SlipdaysHandler
// SlipdaysHandler is used to get used slipdays for a user in a course.
func SlipdaysHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
orgname := r.FormValue("Course")
org, err := git.NewOrganization(orgname, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500)
return
}
view := SlipdaysView{
Course: orgname,
MaxSlipdays: org.SlipdaysMax,
}
if org.IsTeacher(member) {
username := r.FormValue("Username")
user, err := git.NewMemberFromUsername(username, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
if !org.IsMember(member) {
http.Error(w, "Unknown member of course.", 404)
return
}
courseopt := user.Courses[org.Name]
view.UsedSlipdays = courseopt.UsedSlipDays
view.Username = user.Username
} else if org.IsMember(member) {
courseopt := member.Courses[org.Name]
view.UsedSlipdays = courseopt.UsedSlipDays
view.Username = member.Username
} else {
http.Error(w, "Unknown member of course.", 404)
return
}
enc := json.NewEncoder(w)
err = enc.Encode(view)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
}
示例4: RemoveUserHandler
// RemoveUserHandler is http handler used to remove users from the list of students on a course.
func RemoveUserHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkTeacherApproval(w, r, true)
if err != nil {
http.Redirect(w, r, "/", 307)
log.Println(err)
return
}
username := r.FormValue("user")
course := r.FormValue("course")
if !git.HasOrganization(course) {
http.Error(w, "Unknown course.", 404)
return
}
org, err := git.NewOrganization(course, false)
if err != nil {
http.Error(w, "Not valid organization.", 404)
return
}
defer func() {
err := org.Save()
if err != nil {
org.Unlock()
log.Println(err)
}
}()
if !org.IsTeacher(member) {
http.Error(w, "Is not a teacher or assistant for this course.", 404)
return
}
user, err := git.NewMemberFromUsername(username, false)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
defer func() {
err := user.Save()
if err != nil {
user.Unlock()
log.Println(err)
}
}()
if org.IsMember(user) {
org.RemoveMembership(user)
user.RemoveOrganization(org)
} else {
http.Error(w, "Couldn't find this user in this course. ", 404)
return
}
}
示例5: AddAssistantHandler
// AddAssistantHandler is a http handler used to add users as assistants on a course.
func AddAssistantHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkTeacherApproval(w, r, false)
if err != nil {
log.Println(err)
return
}
username := r.FormValue("assistant")
course := r.FormValue("course")
if !git.HasOrganization(course) {
http.Error(w, "Unknown course.", 404)
return
}
if username == member.Username {
return
}
assistant, err := git.NewMemberFromUsername(username, false)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
defer func() {
if err := assistant.Save(); err != nil {
assistant.Unlock()
log.Println(err)
}
}()
org, err := git.NewOrganization(course, false)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
defer func() {
if err := org.Save(); err != nil {
org.Unlock()
log.Println(err)
}
}()
if !org.IsTeacher(member) {
http.Error(w, "User is not the teacher for this course.", 404)
return
}
assistant.AddAssistingOrganization(org)
org.AddTeacher(assistant)
if _, ok := org.PendingUser[username]; ok {
delete(org.PendingUser, username)
}
}
示例6: RegisterCourseMemberHandler
// RegisterCourseMemberHandler is a http handler which register new students
// signing up for a course. After registering the student, this handler
// gives back a informal page about how to accept the invitation to the
// organization on github.
func RegisterCourseMemberHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, true)
if err != nil {
log.Println(err)
return
}
// Gets the org and check if valid
orgname := ""
if path := strings.Split(r.URL.Path, "/"); len(path) == 4 {
if !git.HasOrganization(path[3]) {
http.Redirect(w, r, "/course/register", 307)
return
}
orgname = path[3]
} else {
http.Redirect(w, r, "/course/register", 307)
return
}
org, err := git.NewOrganization(orgname, false)
if err != nil {
http.Redirect(w, r, "/course/register", 307)
return
}
defer func() {
err = org.Save()
if err != nil {
org.Unlock()
log.Println(err)
}
}()
if _, ok := org.Members[member.Username]; ok {
http.Redirect(w, r, "/course/"+orgname, 307)
return
}
err = org.AddMembership(member)
if err != nil {
log.Println("Error adding the student to course. Error msg:", err)
}
view := NewMemberView{
StdTemplate: StdTemplate{
Member: member,
},
Org: orgname,
}
execTemplate("course-registeredmemberinfo.html", w, view)
}
示例7: ListReviewsHandler
// ListReviewsHandler will write back a list of all the code reviews
// in a course, as json data.
//
// Expected input keys: course
func ListReviewsHandler(w http.ResponseWriter, r *http.Request) {
view := ListReviewsView{
Error: true,
}
enc := json.NewEncoder(w)
// Checks if the user is signed in.
member, err := checkMemberApproval(w, r, true)
if err != nil {
log.Println(err)
return
}
if r.FormValue("course") == "" {
view.Errormsg = "Missing required course field."
enc.Encode(view)
return
}
if !git.HasOrganization(r.FormValue("course")) {
view.Errormsg = "Unknown course."
enc.Encode(view)
return
}
org, err := git.NewOrganization(r.FormValue("course"), true)
if err != nil {
view.Errormsg = "Unknown course."
enc.Encode(view)
return
}
if !org.IsMember(member) {
view.Errormsg = "Not a member of this course."
enc.Encode(view)
return
}
crlist := []*git.CodeReview{}
for _, crid := range org.CodeReviewlist {
if cr, err := git.GetCodeReview(crid); err == nil {
crlist = append(crlist, cr)
}
}
view.Error = false
view.Reviews = crlist
enc.Encode(view)
}
示例8: RemovePendingUserHandler
// RemovePendingUserHandler is http handler used to remove users from the list of pending students on a course.
func RemovePendingUserHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkTeacherApproval(w, r, true)
if err != nil {
http.Redirect(w, r, "/", 307)
log.Println(err)
return
}
username := r.FormValue("user")
course := r.FormValue("course")
if !git.HasOrganization(course) {
http.Error(w, "Unknown course.", 404)
return
}
org, err := git.NewOrganization(course, false)
if err != nil {
http.Error(w, "Not valid organization.", 404)
return
}
defer func() {
err := org.Save()
if err != nil {
org.Unlock()
log.Println(err)
}
}()
org.Lock()
defer org.Unlock()
if !org.IsTeacher(member) {
http.Error(w, "Is not a teacher or assistant for this course.", 404)
return
}
if _, ok := org.PendingUser[username]; ok {
delete(org.PendingUser, username)
}
}
示例9: ScoreboardHandler
// ScoreboardHandler is a http handler to give the user a page
// showing the scoreboard for a course
func ScoreboardHandler(w http.ResponseWriter, r *http.Request) {
member, err := checkMemberApproval(w, r, true)
if err != nil {
return
}
// Gets the org and check if valid
orgname := ""
if path := strings.Split(r.URL.Path, "/"); len(path) == 3 {
if !git.HasOrganization(path[2]) {
http.Redirect(w, r, HomeURL, 307)
return
}
orgname = path[2]
} else {
http.Redirect(w, r, HomeURL, 307)
return
}
org, err := git.NewOrganization(orgname, true)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
if !org.IsMember(member) {
http.Redirect(w, r, HomeURL, 307)
return
}
view := ScoreboardView{
StdTemplate: StdTemplate{
Member: member,
},
Org: org,
}
execTemplate("scoreboard.html", w, view)
}
示例10: CIResultSummaryHandler
// CIResultSummaryHandler is a http handler used to get a build summary
// of the build for a user or group. This handler writes back the summary
// as JSON data.
func CIResultSummaryHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
teacher, err := checkTeacherApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
orgname := r.FormValue("Course")
username := r.FormValue("Username")
if orgname == "" || username == "" {
http.Error(w, "Empty request.", 404)
return
}
org, err := git.NewOrganization(orgname, true)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
if !org.IsTeacher(teacher) {
http.Error(w, "Not a teacher for this course.", 404)
return
}
res := make(map[string]*ci.BuildResult)
notes := make(map[string]string)
//credit := make(map[string]score.Score)
//if group ...
if strings.HasPrefix(username, git.GroupRepoPrefix) {
groupid, err := strconv.Atoi(username[len(git.GroupRepoPrefix):])
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500)
return
}
group, err := git.NewGroup(orgname, groupid, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500)
return
}
for labnum, lab := range group.Assignments {
labname := org.GroupLabFolders[labnum]
buildid := group.GetLastBuildID(labnum)
if buildid < 0 {
continue
}
build, err := ci.GetBuildResult(buildid)
if err != nil {
log.Println(err)
continue
}
res[labname] = build
notes[labname] = lab.Notes
//credit[labname] = lab.ExtraCredit
}
} else {
user, err := git.NewMemberFromUsername(username, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 500)
return
}
courseopt, ok := user.Courses[orgname]
if ok {
for labnum, lab := range courseopt.Assignments {
labname := org.IndividualLabFolders[labnum]
buildid := user.GetLastBuildID(orgname, labnum)
if buildid < 0 {
continue
}
build, err := ci.GetBuildResult(buildid)
if err != nil {
log.Println(err)
continue
}
res[labname] = build
notes[labname] = lab.Notes
//credit[labname] = lab.ExtraCredit
}
}
}
view := SummaryView{
Course: orgname,
User: username,
Summary: res,
Notes: notes,
//.........這裏部分代碼省略.........
示例11: ManualCITriggerHandler
// ManualCITriggerHandler is a http handler for manually triggering test builds.
func ManualCITriggerHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
course := r.FormValue("course")
user := r.FormValue("user")
lab := r.FormValue("lab")
if !git.HasOrganization(course) {
http.Error(w, "Unknown organization", 404)
return
}
org, err := git.NewOrganization(course, true)
if err != nil {
http.Error(w, "Organization Error", 404)
return
}
// Defaults back to username or group name for the user if not a teacher.
if !org.IsTeacher(member) {
if org.IsMember(member) {
if strings.Contains(user, "group") {
if member.Courses[org.Name].IsGroupMember {
user = "group" + strconv.Itoa(member.Courses[org.Name].GroupNum)
} else {
http.Error(w, "Not a group member", 404)
return
}
} else {
user = member.Username
}
} else {
http.Error(w, "Not a member of the course", 404)
return
}
}
groupid := -1
labnum := -1
if strings.Contains(user, "group") {
groupid, err = strconv.Atoi(user[len("group"):])
if err != nil {
http.Error(w, err.Error(), 500)
return
}
for i, name := range org.GroupLabFolders {
if name == lab {
labnum = i
break
}
}
} else {
for i, name := range org.IndividualLabFolders {
if name == lab {
labnum = i
break
}
}
}
var repo string
var destfolder string
if _, ok := org.Members[user]; ok {
repo = user + "-" + git.StandardRepoName
destfolder = git.StandardRepoName
} else if _, ok := org.Groups[user]; ok {
repo = user
destfolder = git.GroupsRepoName
} else {
http.Error(w, "Unknown user", 404)
return
}
opt := ci.DaemonOptions{
Org: org.Name,
User: user,
Group: groupid,
Repo: repo,
BaseFolder: org.CI.Basepath,
LabFolder: lab,
LabNumber: labnum,
AdminToken: org.AdminToken,
DestFolder: destfolder,
Secret: org.CI.Secret,
IsPush: false,
}
log.Println(opt)
ci.StartTesterDaemon(opt)
}
示例12: CIResultHandler
// CIResultHandler is a http handeler for getting results from
// a build. This handler writes back the results as JSON data.
func CIResultHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
// TODO: add more security
orgname := r.FormValue("Course")
username := r.FormValue("Username")
labname := r.FormValue("Labname")
org, err := git.NewOrganization(orgname, true)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
if !org.IsMember(member) {
http.Error(w, "Not a member for this course.", 404)
return
}
var res *ci.BuildResult
if strings.HasPrefix(username, git.GroupRepoPrefix) {
labnum := -1
for i, name := range org.GroupLabFolders {
if name == labname {
labnum = i
break
}
}
if labnum < 0 {
http.Error(w, "No lab with that name found.", 404)
return
}
groupid, err := strconv.Atoi(username[len(git.GroupRepoPrefix):])
if err != nil {
http.Error(w, "Could not convert the group ID.", 404)
return
}
group, err := git.NewGroup(orgname, groupid, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
buildid := group.GetLastBuildID(labnum)
if buildid < 0 {
http.Error(w, "Could not find the build.", 404)
return
}
res, err = ci.GetBuildResult(buildid)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
} else {
labnum := -1
for i, name := range org.IndividualLabFolders {
if name == labname {
labnum = i
break
}
}
if labnum < 0 {
http.Error(w, "No lab with that name found.", 404)
return
}
user, err := git.NewMemberFromUsername(username, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
buildid := user.GetLastBuildID(orgname, labnum)
if buildid < 0 {
http.Error(w, "Could not find the build.", 404)
return
}
res, err = ci.GetBuildResult(buildid)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
//.........這裏部分代碼省略.........
示例13: AddGroupMemberHandler
// AddGroupMemberHandler is a http handler adding an additional member to a active group.
func AddGroupMemberHandler(w http.ResponseWriter, r *http.Request) {
view := AddGroupMemberView{}
view.Error = true
enc := json.NewEncoder(w)
// Checks if the user is signed in and a teacher.
member, err := checkTeacherApproval(w, r, true)
if err != nil {
err = enc.Encode(ErrSignIn)
return
}
orgname := r.FormValue("course")
if orgname == "" || !git.HasOrganization(orgname) {
err = enc.Encode(ErrUnknownCourse)
return
}
groupid, err := strconv.Atoi(r.FormValue("groupid"))
if err != nil {
view.ErrorMsg = err.Error()
err = enc.Encode(view)
return
}
if !git.HasGroup(groupid) {
err = enc.Encode(ErrUnknownGroup)
return
}
org, err := git.NewOrganization(orgname, false)
if err != nil {
view.ErrorMsg = err.Error()
err = enc.Encode(view)
return
}
defer func() {
err := org.Save()
if err != nil {
org.Unlock()
log.Println(err)
}
}()
if !org.IsTeacher(member) {
err = enc.Encode(ErrNotTeacher)
return
}
group, err := git.NewGroup(orgname, groupid, false)
if err != nil {
view.ErrorMsg = err.Error()
err = enc.Encode(view)
return
}
defer func() {
err := group.Save()
if err != nil {
group.Unlock()
log.Println(err)
}
}()
if group.TeamID == 0 {
teams, err := org.ListTeams()
if err != nil {
view.ErrorMsg = err.Error()
err = enc.Encode(view)
return
}
if team, ok := teams[git.GroupRepoPrefix+strconv.Itoa(groupid)]; ok {
group.TeamID = team.ID
} else {
view.ErrorMsg = "Error finding team on GitHub."
err = enc.Encode(view)
return
}
}
r.ParseForm()
members := r.PostForm["member"]
for _, username := range members {
if username == "" || !git.HasMember(username) {
continue
}
group.AddMember(username)
org.AddMemberToTeam(group.TeamID, username)
delete(org.PendingRandomGroup, username)
}
group.Activate()
view.Added = true
//.........這裏部分代碼省略.........
示例14: TeachersPanelHandler
// TeachersPanelHandler is a http handler serving the Teacher panel.
// This page shows a summary of all the students and groups.
func TeachersPanelHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkTeacherApproval(w, r, true)
if err != nil {
log.Println(err)
http.Redirect(w, r, pages.HOMEPAGE, 307)
return
}
// Gets the org and check if valid
orgname := ""
if path := strings.Split(r.URL.Path, "/"); len(path) == 4 {
if !git.HasOrganization(path[3]) {
http.Redirect(w, r, pages.HOMEPAGE, 307)
return
}
orgname = path[3]
} else {
http.Redirect(w, r, pages.HOMEPAGE, 307)
return
}
org, err := git.NewOrganization(orgname, true)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
if !org.IsTeacher(member) {
log.Println("User is not a teacher for this course.")
http.Redirect(w, r, pages.HOMEPAGE, 307)
return
}
// gets pending users
users := org.PendingUser
var status string
for username := range users {
// check status up against Github
users[username], err = git.NewMemberFromUsername(username, true)
if err != nil {
continue
}
status, err = org.GetMembership(users[username].(*git.Member))
if err != nil {
log.Println(err)
continue
}
if status == "active" {
continue
// TODO: what about group assignments?
} else if status == "pending" {
delete(users, username)
} else {
delete(users, username)
log.Println("Got a unexpected status back from Github regarding Membership")
}
}
// gets teachers
for username := range org.Teachers {
org.Teachers[username], _ = git.NewMemberFromUsername(username, true)
}
// gets users
for username := range org.Members {
org.Members[username], _ = git.NewMemberFromUsername(username, true)
}
// get pending groups
pendinggroups := make(map[int]*git.Group)
for groupID := range org.PendingGroup {
group, err := git.NewGroup(org.Name, groupID, true)
if err != nil {
log.Println(err)
}
if group.Course != org.Name {
org.Lock()
delete(org.PendingGroup, groupID)
err := org.Save()
if err != nil {
log.Println(err)
org.Unlock()
}
continue
}
for key := range group.Members {
groupmember, _ := git.NewMemberFromUsername(key, true)
group.Members[key] = groupmember
}
pendinggroups[groupID] = group
}
//.........這裏部分代碼省略.........
示例15: ApUserResultsHandler
// ApUserResultsHandler is a http handeler for getting all results for a user
// from the latest anti-plagiarism test. This handler writes back the results as JSON data.
func ApUserResultsHandler(w http.ResponseWriter, r *http.Request) {
// Checks if the user is signed in and a teacher.
member, err := checkMemberApproval(w, r, false)
if err != nil {
http.Error(w, err.Error(), 404)
log.Println(err)
return
}
// TODO: add more security
orgname := r.FormValue("Course")
username := r.FormValue("Username")
org, err := git.NewOrganization(orgname, true)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
if !org.IsMember(member) {
http.Error(w, "Not a member for this course.", 404)
return
}
results := make(map[string]git.AntiPlagiarismResults)
if strings.HasPrefix(username, git.GroupRepoPrefix) {
// Get the group ID from the group name
groupid, err := strconv.Atoi(username[len(git.GroupRepoPrefix):])
if err != nil {
http.Error(w, "Could not convert the group ID.", 404)
return
}
// Get the group from the database
group, err := git.NewGroup(orgname, groupid, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
// For each lab
for i, name := range org.GroupLabFolders {
// Get the results for the lab
temp := group.GetAntiPlagiarismResults(org.Name, i)
if temp != nil {
results[name] = *temp
}
}
} else {
// Get user from the database
user, err := git.NewMemberFromUsername(username, true)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), 404)
return
}
// For each lab
for i, name := range org.IndividualLabFolders {
// Get the results for the lab
temp := user.GetAntiPlagiarismResults(org.Name, i)
if temp != nil {
results[name] = *temp
}
}
}
enc := json.NewEncoder(w)
// Encode the results in JSON
err = enc.Encode(results)
if err != nil {
http.Error(w, err.Error(), 404)
}
}