本文整理汇总了Golang中github.com/containerops/wharf/models.Team.Users方法的典型用法代码示例。如果您正苦于以下问题:Golang Team.Users方法的具体用法?Golang Team.Users怎么用?Golang Team.Users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/containerops/wharf/models.Team
的用法示例。
在下文中一共展示了Team.Users方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostTeam
func (this *TeamWebV1Controller) PostTeam() {
user, exist := this.Ctx.Input.CruSession.Get("user").(models.User)
if exist != true {
this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": "Session load failure", "url": "/auth"})
return
}
var team models.Team
if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &team); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
}
org := new(models.Organization)
if exist, _, err := org.Has(team.Organization); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Organization don't exist", nil)
return
}
team.Id = string(utils.GeneralKey(team.Name))
team.Username = user.Username
team.Users = append(team.Users, user.Username)
if err := team.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "Team save error", nil)
return
}
user.Teams = append(user.Teams, team.Name)
user.JoinTeams = append(user.JoinTeams, team.Name)
if err := user.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "User save error", nil)
return
}
org.Teams = append(org.Teams, team.Name)
if err := org.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "Org save error", nil)
return
}
memo, _ := json.Marshal(this.Ctx.Input.Header)
team.Log(models.ACTION_ADD_TEAM, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo)
user.Log(models.ACTION_ADD_TEAM, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, team.Id, memo)
//Reload User Data In Session
user.Get(user.Username, user.Password)
this.Ctx.Input.CruSession.Set("user", user)
this.JSONOut(http.StatusOK, "Team Create Successfully!", nil)
return
}
示例2: PutTeamAddMember
func (this *TeamWebV1Controller) PutTeamAddMember() {
if _, exist := this.Ctx.Input.CruSession.Get("user").(models.User); exist == false {
this.JSONOut(http.StatusBadRequest, "", map[string]string{"message": "Session load failure", "url": "/auth"})
return
}
org := new(models.Organization)
if err := org.GetByName(this.Ctx.Input.Param(":org")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
}
team := new(models.Team)
if err := team.GetByName(this.Ctx.Input.Param(":org"), this.Ctx.Input.Param(":team")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
}
user := new(models.User)
if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "User not found", nil)
return
}
exist := false
for _, u := range team.Users {
if u == this.Ctx.Input.Param(":username") {
exist = true
}
}
if exist == true {
this.JSONOut(http.StatusBadRequest, "User already in team", nil)
return
} else {
team.Users = append(team.Users, this.Ctx.Input.Param(":username"))
if err := team.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
}
this.JSONOut(http.StatusOK, "", user)
return
}
}
示例3: PutMember
func (this *OrganizationWebV1Controller) PutMember() {
user := new(models.User)
org := new(models.Organization)
team := new(models.Team)
member := new(models.User)
if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "User not exist", nil)
return
}
if exist, _, err := org.Has(this.Ctx.Input.Param(":org")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Organization not exist", nil)
return
}
if exist, _, err := team.Has(this.Ctx.Input.Param(":org"), this.Ctx.Input.Param(":team")); err != nil {
this.JSONOut(http.StatusBadRequest, "Search team error", nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Team not exist", nil)
return
}
if exist, _, err := user.Has(this.Ctx.Input.Param(":member")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "User not exist", nil)
return
}
for i, v := range team.Users {
if v == member.Username {
team.Users = append(team.Users[:i], team.Users[i+1:]...)
team.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := team.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "Team save error", nil)
return
}
}
}
for i, v := range user.JoinTeams {
if v == team.Id {
user.JoinTeams = append(user.JoinTeams[:i], user.JoinTeams[i+1:]...)
user.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := user.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "User save error", nil)
return
}
}
}
for _, v := range org.Teams {
t := new(models.Team)
if exist, _, err := team.Has(strings.Split(v, "-")[0], strings.Split(v, "-")[1]); err != nil {
this.JSONOut(http.StatusBadRequest, "Search team error", nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Team not exist", nil)
return
}
for _, u := range t.Users {
if u == member.Username {
this.JSONOut(http.StatusOK, "User remove successfully.", nil)
return
}
}
}
for i, v := range user.JoinOrganizations {
if v == org.Name {
user.JoinOrganizations = append(user.JoinOrganizations[:i], user.JoinOrganizations[i+1:]...)
user.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := user.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "User save error", nil)
return
}
}
}
this.JSONOut(http.StatusOK, "User remove successfully.", nil)
return
}
示例4: PostMember
func (this *OrganizationWebV1Controller) PostMember() {
user := new(models.User)
org := new(models.Organization)
team := new(models.Team)
member := new(models.User)
if exist, _, err := user.Has(this.Ctx.Input.Param(":username")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "User not exist", nil)
return
}
if exist, _, err := org.Has(this.Ctx.Input.Param(":org")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Organization not exist", nil)
return
}
if exist, _, err := team.Has(this.Ctx.Input.Param(":org"), this.Ctx.Input.Param(":team")); err != nil {
this.JSONOut(http.StatusBadRequest, "Search team error", nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "Team not exist", nil)
return
}
if exist, _, err := user.Has(this.Ctx.Input.Param(":member")); err != nil {
this.JSONOut(http.StatusBadRequest, err.Error(), nil)
return
} else if exist == false {
this.JSONOut(http.StatusBadRequest, "User not exist", nil)
return
}
team.Users = append(team.Users, member.Username)
team.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := team.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "Team save error", nil)
return
}
has := false
for _, k := range member.JoinOrganizations {
if k == org.Name {
has = true
}
}
if has == false {
member.JoinOrganizations = append(member.JoinOrganizations, org.Name)
}
member.JoinTeams = append(member.JoinTeams, team.Id)
member.Updated = time.Now().UnixNano() / int64(time.Millisecond)
if err := member.Save(); err != nil {
this.JSONOut(http.StatusBadRequest, "User save error", nil)
return
}
this.JSONOut(http.StatusOK, "User added to the team", nil)
return
}