예제 #1
0
파일: teams.go 프로젝트: Jyggafey/drone
// 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)
}
예제 #2
0
파일: handler.go 프로젝트: rnorth/drone
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)
	}
}
예제 #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")
	}
}
예제 #4
0
파일: teams.go 프로젝트: Tathanen/drone
// 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)
}
예제 #5
0
파일: handler.go 프로젝트: jro7/drone
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)
	}
}
예제 #6
0
파일: teams.go 프로젝트: Tathanen/drone
// 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)
}