Exemplo n.º 1
0
// Update a specific Team Member.
func TeamMemberUpdate(w http.ResponseWriter, r *http.Request, u *User) error {
	roleParam := r.FormValue("Role")
	teamParam := r.FormValue(":team")

	// get the team from the database
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return RenderError(w, err, http.StatusNotFound)
	}
	// verify the user is a admin member of the team
	if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}

	// get the ID from the URL parameter
	idstr := r.FormValue("id")
	id, err := strconv.Atoi(idstr)
	if err != nil {
		return err
	}

	// get the user from the database
	user, err := database.GetUser(int64(id))
	if err != nil {
		return RenderError(w, err, http.StatusNotFound)
	}

	// add the user to the team
	if err := database.SaveMember(user.ID, team.ID, roleParam); err != nil {
		return RenderError(w, err, http.StatusInternalServerError)
	}

	return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
Exemplo n.º 2
0
func TeamMemberAccept(w http.ResponseWriter, r *http.Request, u *User) error {
	// get the team name from the token
	token := r.FormValue("token")
	teamToken := authcookie.Login(token, secret)
	teamId, err := strconv.Atoi(teamToken)
	if err != nil || teamId == 0 {
		return ErrInvalidTeamName
	}

	// get the team from the database
	team, err := database.GetTeam(int64(teamId))
	if err != nil {
		return RenderError(w, err, http.StatusNotFound)
	}

	// add the user to the team.
	// by default the user has write access to the team, which means
	// they can add and manage new repositories.
	if err := database.SaveMember(u.ID, team.ID, RoleWrite); err != nil {
		return RenderError(w, err, http.StatusInternalServerError)
	}

	// send the user to the dashboard
	http.Redirect(w, r, "/dashboard/team/"+team.Slug, http.StatusSeeOther)
	return nil
}
Exemplo n.º 3
0
// Create a new Team.
func TeamCreate(w http.ResponseWriter, r *http.Request, u *User) error {
	// set the name and email from the form data
	team := Team{}
	team.SetName(r.FormValue("name"))
	team.SetEmail(r.FormValue("email"))

	if err := team.Validate(); err != nil {
		return RenderError(w, err, http.StatusBadRequest)
	}
	if err := database.SaveTeam(&team); err != nil {
		return RenderError(w, err, http.StatusBadRequest)
	}

	// add default member to the team (me)
	if err := database.SaveMember(u.ID, team.ID, RoleOwner); err != nil {
		return RenderError(w, err, http.StatusInternalServerError)
	}

	return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
Exemplo n.º 4
0
func Setup() {
	// create an in-memory database
	database.Init("sqlite3", ":memory:")

	// create dummy user data
	user1 := User{
		Password: "******",
		Name:     "Brad Rydzewski",
		Email:    "*****@*****.**",
		Gravatar: "8c58a0be77ee441bb8f8595b7f1b4e87",
		Token:    "123",
		Admin:    true}
	user2 := User{
		Password: "******",
		Name:     "Thomas Burke",
		Email:    "*****@*****.**",
		Gravatar: "c62f7126273f7fa786274274a5dec8ce",
		Token:    "456",
		Admin:    false}
	user3 := User{
		Password: "******",
		Name:     "Carlos Morales",
		Email:    "*****@*****.**",
		Gravatar: "c2180a539620d90d68eaeb848364f1c2",
		Token:    "789",
		Admin:    false}

	database.SaveUser(&user1)
	database.SaveUser(&user2)
	database.SaveUser(&user3)

	// create dummy team data
	team1 := Team{
		Slug:     "drone",
		Name:     "Drone",
		Email:    "*****@*****.**",
		Gravatar: "8c58a0be77ee441bb8f8595b7f1b4e87"}
	team2 := Team{
		Slug:     "github",
		Name:     "Github",
		Email:    "*****@*****.**",
		Gravatar: "61024896f291303615bcd4f7a0dcfb74"}
	team3 := Team{
		Slug:     "golang",
		Name:     "Golang",
		Email:    "*****@*****.**",
		Gravatar: "991695cc770c6b8354b68cd18c280b95"}

	database.SaveTeam(&team1)
	database.SaveTeam(&team2)
	database.SaveTeam(&team3)

	// create team membership data
	database.SaveMember(user1.ID, team1.ID, RoleOwner)
	database.SaveMember(user2.ID, team1.ID, RoleAdmin)
	database.SaveMember(user3.ID, team1.ID, RoleWrite)
	database.SaveMember(user1.ID, team2.ID, RoleOwner)
	database.SaveMember(user2.ID, team2.ID, RoleAdmin)
	database.SaveMember(user3.ID, team2.ID, RoleWrite)
	database.SaveMember(user1.ID, team3.ID, RoleRead)

	// create dummy repo data
	repo1 := Repo{
		Slug:       "github.com/drone/drone",
		Host:       "github.com",
		Owner:      "drone",
		Name:       "drone",
		Private:    true,
		Disabled:   false,
		SCM:        "git",
		URL:        "[email protected]:drone/drone.git",
		Username:   "******",
		Password:   "******",
		PublicKey:  "public key",
		PrivateKey: "private key",
		UserID:     user1.ID,
		TeamID:     team1.ID,
	}
	repo2 := Repo{
		Slug:       "bitbucket.org/drone/test",
		Host:       "bitbucket.org",
		Owner:      "drone",
		Name:       "test",
		Private:    false,
		Disabled:   false,
		SCM:        "hg",
		URL:        "https://bitbucket.org/drone/test",
		Username:   "******",
		Password:   "******",
		PublicKey:  "public key",
		PrivateKey: "private key",
		UserID:     user1.ID,
		TeamID:     team1.ID,
	}
	repo3 := Repo{
		Slug:       "bitbucket.org/brydzewski/test",
		Host:       "bitbucket.org",
		Owner:      "brydzewski",
		Name:       "test",
		Private:    false,
		Disabled:   false,
		SCM:        "hg",
		URL:        "https://bitbucket.org/brydzewski/test",
		Username:   "******",
		Password:   "******",
		PublicKey:  "public key",
		PrivateKey: "private key",
		UserID:     user2.ID,
	}

	database.SaveRepo(&repo1)
	database.SaveRepo(&repo2)
	database.SaveRepo(&repo3)

	commit1 := Commit{
		RepoID:   repo1.ID,
		Status:   "Success",
		Hash:     "4f4c4594be6d6ddbc1c0dd521334f7ecba92b608",
		Branch:   "master",
		Author:   user1.Email,
		Gravatar: user1.Gravatar,
		Message:  "commit message",
	}
	commit2 := Commit{
		RepoID:   repo1.ID,
		Status:   "Failure",
		Hash:     "0eb2fa13e9f4139e803b6ad37831708d4786c74a",
		Branch:   "master",
		Author:   user1.Email,
		Gravatar: user1.Gravatar,
		Message:  "commit message",
	}
	commit3 := Commit{
		RepoID:   repo1.ID,
		Status:   "Failure",
		Hash:     "60a7fe87ccf01d0152e53242528399e05acaf047",
		Branch:   "dev",
		Author:   user1.Email,
		Gravatar: user1.Gravatar,
		Message:  "commit message",
	}
	commit4 := Commit{
		RepoID:   repo2.ID,
		Status:   "Success",
		Hash:     "a4078d1e9a0842cdd214adbf0512578799a4f2ba",
		Branch:   "master",
		Author:   user1.Email,
		Gravatar: user1.Gravatar,
		Message:  "commit message",
	}

	// create dummy commit data
	database.SaveCommit(&commit1)
	database.SaveCommit(&commit2)
	database.SaveCommit(&commit3)
	database.SaveCommit(&commit4)

	// create dummy build data
	database.SaveBuild(&Build{CommitID: commit1.ID, Slug: "node_0.10", Status: "Success", Duration: 60})
	database.SaveBuild(&Build{CommitID: commit1.ID, Slug: "node_0.09", Status: "Success", Duration: 70})
	database.SaveBuild(&Build{CommitID: commit2.ID, Slug: "node_0.10", Status: "Success", Duration: 10})
	database.SaveBuild(&Build{CommitID: commit2.ID, Slug: "node_0.09", Status: "Failure", Duration: 65})
	database.SaveBuild(&Build{CommitID: commit3.ID, Slug: "node_0.10", Status: "Failure", Duration: 50})
	database.SaveBuild(&Build{CommitID: commit3.ID, Slug: "node_0.09", Status: "Failure", Duration: 55})
}