本文整理匯總了Golang中github.com/drone/drone/pkg/database.GetTeamSlug函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetTeamSlug函數的具體用法?Golang GetTeamSlug怎麽用?Golang GetTeamSlug使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetTeamSlug函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TeamMemberUpdate
// Update a specific Team Member.
func TeamMemberUpdate(w http.ResponseWriter, r *http.Request, u *User) error {
roleParam := r.FormValue("Role")
teamParam := r.FormValue(":team")
// get the team from the database
team, err := database.GetTeamSlug(teamParam)
if err != nil {
return RenderError(w, err, http.StatusNotFound)
}
// verify the user is a admin member of the team
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 RenderError(w, err, http.StatusNotFound)
}
// add the user to the team
if err := database.SaveMember(user.ID, team.ID, roleParam); err != nil {
return RenderError(w, err, http.StatusInternalServerError)
}
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
示例2: Create
func (g *GitlabHandler) Create(w http.ResponseWriter, r *http.Request, u *User) error {
teamName := r.FormValue("team")
owner := r.FormValue("owner")
name := r.FormValue("name")
repo, err := g.newGitlabRepo(u, owner, name)
if err != nil {
return err
}
if len(teamName) > 0 {
team, err := database.GetTeamSlug(teamName)
if err != nil {
return fmt.Errorf("Unable to find Team %s.", teamName)
}
// user must be an admin member of the team
if ok, _ := database.IsMemberAdmin(u.ID, team.ID); !ok {
return fmt.Errorf("Invalid permission to access Team %s.", teamName)
}
repo.TeamID = team.ID
}
// Save to the database
if err := database.SaveRepo(repo); err != nil {
return fmt.Errorf("Error saving repository to the database. %s", err)
}
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
示例3: TeamMemberEdit
// 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)
}
示例4: TestGetTeamSlug
// TestGetTeamName tests the ability to retrieve a Team
// from the database by Unique Team Name (aka Slug).
func TestGetTeamSlug(t *testing.T) {
Setup()
defer Teardown()
team, err := database.GetTeamSlug("drone")
if err != nil {
t.Error(err)
}
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 != "[email protected]" {
t.Errorf("Exepected Email %s, got %s", "[email protected]", team.Email)
}
if team.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" {
t.Errorf("Exepected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", team.Gravatar)
}
}
示例5: TeamShow
// 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)
}
示例6: TeamEdit
// Return an HTML form for editing a Team.
func TeamEdit(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")
}
data := struct {
User *User
Team *Team
}{u, team}
return RenderTemplate(w, "team_profile.html", &data)
}
示例7: TeamWall
// 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)
}
示例8: RepoUpdate
// Updates an existing repository.
func RepoUpdate(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
switch r.FormValue("action") {
case "params":
repo.Params = map[string]string{}
if err := goyaml.Unmarshal([]byte(r.FormValue("params")), &repo.Params); err != nil {
return err
}
default:
repo.URL = r.FormValue("URL")
repo.Disabled = len(r.FormValue("Disabled")) == 0
repo.DisabledPullRequest = len(r.FormValue("DisabledPullRequest")) == 0
repo.Private = len(r.FormValue("Private")) > 0
repo.Privileged = u.Admin && len(r.FormValue("Privileged")) > 0
// value of "" indicates the currently authenticated user
// should be set as the administrator.
if len(r.FormValue("Owner")) == 0 {
repo.UserID = u.ID
repo.TeamID = 0
} else {
// else the user has chosen a team
team, err := database.GetTeamSlug(r.FormValue("Owner"))
if err != nil {
return err
}
// verify the user is a member of the team
if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
return fmt.Errorf("Forbidden")
}
// set the team ID
repo.TeamID = team.ID
}
}
// save the page
if err := database.SaveRepo(repo); err != nil {
return err
}
http.Redirect(w, r, r.URL.Path, http.StatusSeeOther)
return nil
}
示例9: TeamWallData
// 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)
}
示例10: TeamDelete
// Delete a specific Team.
func TeamDelete(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")
}
// the user must confirm their password before deleting
password := r.FormValue("password")
if err := u.ComparePassword(password); err != nil {
return RenderError(w, err, http.StatusBadRequest)
}
database.DeleteTeam(team.ID)
http.Redirect(w, r, "/account/user/teams", http.StatusSeeOther)
return nil
}
示例11: TeamMembers
// 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)
}
示例12: TeamUpdate
// Update a specific Team.
func TeamUpdate(w http.ResponseWriter, r *http.Request, u *User) error {
// get team from the database
teamName := r.FormValue(":team")
team, err := database.GetTeamSlug(teamName)
if err != nil {
return fmt.Errorf("Forbidden")
}
if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
return fmt.Errorf("Forbidden")
}
team.Name = r.FormValue("name")
team.SetEmail(r.FormValue("email"))
if err := team.Validate(); err != nil {
return RenderError(w, err, http.StatusBadRequest)
}
if err := database.SaveTeam(team); err != nil {
return RenderError(w, err, http.StatusBadRequest)
}
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
示例13: TeamMemberInvite
// Invite a new Team Member.
func TeamMemberInvite(w http.ResponseWriter, r *http.Request, u *User) error {
teamParam := r.FormValue(":team")
mailParam := r.FormValue("email")
team, err := database.GetTeamSlug(teamParam)
if err != nil {
return RenderError(w, err, http.StatusNotFound)
}
if member, _ := database.IsMemberAdmin(u.ID, team.ID); !member {
return fmt.Errorf("Forbidden")
}
// generate a token that is valid for 3 days to join the team
token := authcookie.New(strconv.Itoa(int(team.ID)), time.Now().Add(72*time.Hour), secret)
// hostname from settings
hostname := database.SettingsMust().URL().String()
emailEnabled := database.SettingsMust().SmtpServer != ""
if !emailEnabled {
// Email is not enabled, so must let the user know the signup link
link := fmt.Sprintf("%v/accept?token=%v", hostname, token)
return RenderText(w, link, http.StatusOK)
}
// send the invitation
data := struct {
User *User
Team *Team
Token string
Host string
}{u, team, token, hostname}
// send email async
go mail.SendInvitation(team.Name, mailParam, &data)
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}
示例14: TeamMemberDelete
// 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
}
示例15: RepoCreateGithub
func RepoCreateGithub(w http.ResponseWriter, r *http.Request, u *User) error {
teamName := r.FormValue("team")
owner := r.FormValue("owner")
name := r.FormValue("name")
// get the github settings from the database
settings := database.SettingsMust()
// create the GitHub client
client := github.New(u.GithubToken)
githubRepo, err := client.Repos.Find(owner, name)
if err != nil {
return err
}
repo, err := NewGitHubRepo(owner, name, githubRepo.Private)
if err != nil {
return err
}
repo.UserID = u.ID
repo.Private = githubRepo.Private
// if the user chose to assign to a team account
// we need to retrieve the team, verify the user
// has access, and then set the team id.
if len(teamName) > 0 {
team, err := database.GetTeamSlug(teamName)
if err != nil {
log.Printf("error retrieving team %s", teamName)
return err
}
// user must be an admin member of the team
if ok, _ := database.IsMemberAdmin(u.ID, team.ID); !ok {
return fmt.Errorf("Forbidden")
}
repo.TeamID = team.ID
}
// if the repository is private we'll need
// to upload a github key to the repository
if repo.Private {
// name the key
keyName := fmt.Sprintf("%[email protected]%s", repo.Owner, settings.Domain)
// create the github key, or update if one already exists
_, err := client.RepoKeys.CreateUpdate(owner, name, repo.PublicKey, keyName)
if err != nil {
return fmt.Errorf("Unable to add Private Key to your GitHub repository")
}
} else {
}
// create a hook so that we get notified when code
// is pushed to the repository and can execute a build.
link := fmt.Sprintf("%s://%s/hook/github.com?id=%s", settings.Scheme, settings.Domain, repo.Slug)
// add the hook
if _, err := client.Hooks.CreateUpdate(owner, name, link); err != nil {
return fmt.Errorf("Unable to add Hook to your GitHub repository. %s", err.Error())
}
// Save to the database
if err := database.SaveRepo(repo); err != nil {
log.Print("error saving new repository to the database")
return err
}
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
}