예제 #1
0
파일: repos.go 프로젝트: ninholic/drone
// Repository Settings
func RepoSettingsForm(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {

	// get the list of teams
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}

	data := struct {
		Repo  *Repo
		User  *User
		Teams []*Team
		Owner *User
		Team  *Team
	}{Repo: repo, User: u, Teams: teams}

	// get the repo owner
	if repo.TeamID > 0 {
		data.Team, err = database.GetTeam(repo.TeamID)
		if err != nil {
			return err
		}
	}

	// get the team owner
	data.Owner, err = database.GetUser(repo.UserID)
	if err != nil {
		return err
	}

	return RenderTemplate(w, "repo_settings.html", &data)
}
예제 #2
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)
}
예제 #3
0
파일: users.go 프로젝트: Jyggafey/drone
// Display the dashboard for a specific user
func UserShow(w http.ResponseWriter, r *http.Request, u *User) error {
	// list of repositories owned by User
	repos, err := database.ListRepos(u.ID)
	if err != nil {
		return err
	}
	// list of user team accounts
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	// list of recent commits
	commits, err := database.ListCommitsUser(u.ID)
	if err != nil {
		return err
	}

	data := struct {
		User    *User
		Repos   []*Repo
		Teams   []*Team
		Commits []*RepoCommit
	}{u, repos, teams, commits}
	return RenderTemplate(w, "user_dashboard.html", &data)
}
예제 #4
0
파일: users.go 프로젝트: Jyggafey/drone
// Display a list of all Teams for the currently authenticated User.
func UserTeams(w http.ResponseWriter, r *http.Request, u *User) error {
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	data := struct {
		User  *User
		Teams []*Team
	}{u, teams}
	return RenderTemplate(w, "user_teams.html", &data)
}
예제 #5
0
파일: repos.go 프로젝트: ConsultingMD/drone
func RepoAddGithubLimited(w http.ResponseWriter, r *http.Request, u *User) error {
	settings := database.SettingsMust()
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	data := struct {
		User     *User
		Teams    []*Team
		Settings *Settings
	}{u, teams, settings}

	// display the template for adding
	// a new GitHub repository with read only access.
	return RenderTemplate(w, "github_limited_add.html", &data)
}
예제 #6
0
파일: repos.go 프로젝트: ninholic/drone
func RepoAdd(w http.ResponseWriter, r *http.Request, u *User) error {
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	data := struct {
		User  *User
		Teams []*Team
	}{u, teams}
	// if the user hasn't linked their GitHub account
	// render a different template
	if len(u.GithubToken) == 0 {
		return RenderTemplate(w, "github_link.html", &data)
	}
	// otherwise display the template for adding
	// a new GitHub repository.
	return RenderTemplate(w, "github_add.html", &data)
}
예제 #7
0
파일: gitlab.go 프로젝트: Jyggafey/drone
func (g *GitlabHandler) Add(w http.ResponseWriter, r *http.Request, u *User) error {
	settings := database.SettingsMust()
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	data := struct {
		User     *User
		Teams    []*Team
		Settings *Settings
	}{u, teams, settings}
	// if the user hasn't linked their GitLab account
	// render a different template
	if len(u.GitlabToken) == 0 {
		return RenderTemplate(w, "gitlab_link.html", &data)
	}
	// otherwise display the template for adding
	// a new GitLab repository.
	return RenderTemplate(w, "gitlab_add.html", &data)
}
예제 #8
0
파일: repos.go 프로젝트: ConsultingMD/drone
func RepoAddBitbucket(w http.ResponseWriter, r *http.Request, u *User) error {
	settings := database.SettingsMust()
	teams, err := database.ListTeams(u.ID)
	if err != nil {
		return err
	}
	data := struct {
		User     *User
		Teams    []*Team
		Settings *Settings
	}{u, teams, settings}
	// if the user hasn't linked their Bitbucket account
	// render a different template
	if len(u.BitbucketToken) == 0 {
		return RenderTemplate(w, "bitbucket_link.html", &data)
	}
	// otherwise display the template for adding
	// a new Bitbucket repository.
	return RenderTemplate(w, "bitbucket_add.html", &data)
}
예제 #9
0
// Test the ability to get a list of Teams
// to which a User belongs.
func TestListTeam(t *testing.T) {
	Setup()
	defer Teardown()

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

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

	// get the first user in the list and verify
	// fields are being populated correctly
	team := teams[0]

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

	if team.Name != "Drone" {
		t.Errorf("Exepected Name %s, got %s", "Drone", team.Name)
	}

	if team.Slug != "drone" {
		t.Errorf("Exepected Slug %s, got %s", "drone", team.Slug)
	}

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

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