Example #1
0
// Display a specific Team.
func TeamShow(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.IsMember(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}
	// list of repositories owned by Team
	repos, err := database.ListReposTeam(team.ID)
	if err != nil {
		return err
	}
	// list all user teams
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	// list of recent commits
	commits, err := database.ListCommitsTeam(team.ID)
	if err != nil {
		return err
	}
	data := struct {
		User    *User
		Team    *Team
		Teams   []*Team
		Repos   []*Repo
		Commits []*RepoCommit
	}{u, team, teams, repos, commits}
	return RenderTemplate(w, "team_dashboard.html", &data)
}
Example #2
0
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	user, err := readUser(r)
	if err != nil {
		redirectLogin(w, r)
		return
	}

	// repository name from the URL parameters
	hostParam := r.FormValue(":host")
	userParam := r.FormValue(":owner")
	nameParam := r.FormValue(":name")
	repoName := fmt.Sprintf("%s/%s/%s", hostParam, userParam, nameParam)

	repo, err := database.GetRepoSlug(repoName)
	if err != nil {
		RenderNotFound(w)
		return
	}

	// The User must own the repository OR be a member
	// of the Team that owns the repository.
	if user.ID != repo.UserID {
		if member, _ := database.IsMember(user.ID, repo.TeamID); !member {
			RenderNotFound(w)
			return
		}
	}

	if err = h(w, r, user, repo); err != nil {
		log.Print(err)
		RenderError(w, err, http.StatusBadRequest)
	}
}
Example #3
0
func TestIsMember(t *testing.T) {
	Setup()
	defer Teardown()

	ok, err := database.IsMember(1, 1)
	if err != nil {
		t.Error(err)
	}

	if !ok {
		t.Errorf("Expected IsMember to return true, returned false")
	}
}
Example #4
0
// Wall display for the team
func TeamWall(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.IsMember(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}

	data := struct {
		Token string
	}{channel.CreateStream(fmt.Sprintf("%s",
		channel.WallDisplay))}

	return RenderTemplate(w, "watcher.html", &data)
}
Example #5
0
func (h RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

	// repository name from the URL parameters
	hostParam := r.FormValue(":host")
	userParam := r.FormValue(":owner")
	nameParam := r.FormValue(":name")
	repoName := fmt.Sprintf("%s/%s/%s", hostParam, userParam, nameParam)

	repo, err := database.GetRepoSlug(repoName)
	if err != nil || repo == nil {
		RenderNotFound(w)
		return
	}

	// retrieve the user from the database
	user, err := readUser(r)

	// if the user is not found, we can still
	// serve the page assuming the repository
	// is public.
	switch {
	case err != nil && repo.Private == true:
		redirectLogin(w, r)
		return
	case err != nil && repo.Private == false:
		h(w, r, nil, repo)
		return
	}

	// The User must own the repository OR be a member
	// of the Team that owns the repository OR the repo
	// must not be private.
	if repo.Private && user.ID != repo.UserID {
		if member, _ := database.IsMember(user.ID, repo.TeamID); !member {
			RenderNotFound(w)
			return
		}
	}

	if err = h(w, r, user, repo); err != nil {
		log.Print(err)
		RenderError(w, err, http.StatusBadRequest)
	}
}
Example #6
0
// API endpoint for fetching the initial wall display data via AJAX
func TeamWallData(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.IsMember(u.ID, team.ID); !member {
		return fmt.Errorf("Forbidden")
	}

	// list of recent commits
	commits, err := database.ListCommitsTeamWall(team.ID)
	if err != nil {
		return err
	}

	w.WriteHeader(http.StatusOK)
	return json.NewEncoder(w).Encode(commits)
}