コード例 #1
0
ファイル: members.go プロジェクト: Jyggafey/drone
// Return an HTML form for editing a Team Member.
func TeamMemberEdit(w http.ResponseWriter, r *http.Request, u *User) error {
	teamParam := r.FormValue(":team")
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return err
	}
	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
	}

	user, err := database.GetUser(int64(id))
	if err != nil {
		return err
	}
	member, err := database.GetMember(user.ID, team.ID)
	if err != nil {
		return err
	}
	data := struct {
		User   *User
		Team   *Team
		Member *Member
	}{u, team, member}
	return RenderTemplate(w, "members_edit.html", &data)
}
コード例 #2
0
ファイル: members_test.go プロジェクト: rnorth/drone
// TestGetMember tests the ability to retrieve a Team
// Member from the database by Unique ID.
func TestGetMember(t *testing.T) {
	Setup()
	defer Teardown()

	// get member by user_id and team_id
	member, err := database.GetMember(1, 1)
	if err != nil {
		t.Error(err)
	}

	if member.ID != 1 {
		t.Errorf("Exepected ID %d, got %d", 1, member.ID)
	}

	if member.Name != "Brad Rydzewski" {
		t.Errorf("Exepected Name %s, got %s", "Brad Rydzewski", member.Name)
	}

	if member.Email != "*****@*****.**" {
		t.Errorf("Exepected Email %s, got %s", "*****@*****.**", member.Email)
	}

	if member.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" {
		t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", member.Gravatar)
	}

	if member.Role != model.RoleOwner {
		t.Errorf("Exepected Role %s, got %s", model.RoleOwner, member.Role)
	}
}
コード例 #3
0
ファイル: members_test.go プロジェクト: rnorth/drone
func TestDeleteMember(t *testing.T) {
	Setup()
	defer Teardown()

	// delete member by user_id and team_id
	if err := database.DeleteMember(1, 1); err != nil {
		t.Error(err)
	}

	// get member by user_id and team_id
	if _, err := database.GetMember(1, 1); err == nil {
		t.Error(err)
	}

}