Exemplo n.º 1
0
// Display a list of Team Members.
func TeamMembers(w http.ResponseWriter, r *http.Request, u *User) error {
	teamParam := r.FormValue(":team")
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return err
	}
	// user must be a team member admin
	if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}
	members, err := database.ListMembers(team.ID)
	if err != nil {
		return err
	}
	data := struct {
		User    *User
		Team    *Team
		Members []*Member
	}{u, team, members}
	return RenderTemplate(w, "team_members.html", &data)
}
Exemplo n.º 2
0
func TestListMembers(t *testing.T) {
	Setup()
	defer Teardown()

	// list members by team_id
	members, err := database.ListMembers(1)
	if err != nil {
		t.Error(err)
	}

	// verify team count
	if len(members) != 3 {
		t.Errorf("Exepected %d Team Members in database, got %d", 3, len(members))
		return
	}

	// get the first member in the list and verify
	// fields are being populated correctly
	member := members[0]

	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)
	}
}
Exemplo n.º 3
0
// Delete a specific Team Member.
func TeamMemberDelete(w http.ResponseWriter, r *http.Request, u *User) error {
	// get the team from the database
	teamParam := r.FormValue(":team")
	team, err := database.GetTeamSlug(teamParam)
	if err != nil {
		return RenderNotFound(w)
	}

	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 RenderNotFound(w)
	}
	// must be at least 1 member
	members, err := database.ListMembers(team.ID)
	if err != nil {
		return err
	} else if len(members) == 1 {
		return fmt.Errorf("There must be at least 1 member per team")
	}
	// delete the member
	database.DeleteMember(user.ID, team.ID)
	http.Redirect(w, r, fmt.Sprintf("/account/team/%s/members", team.Name), http.StatusSeeOther)
	return nil
}