Exemple #1
0
func (this *OrganizationWebV1Controller) GetOrgTeams() {
	org := new(models.Organization)
	teams := make([]models.Team, 0)

	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
	}

	for _, v := range org.Teams {
		team := new(models.Team)

		if exist, _, err := team.Has(strings.Split(v, "-")[0], strings.Split(v, "-")[1]); err != nil {
			this.JSONOut(http.StatusBadRequest, "Team invalid", nil)
			return
		} else if exist == false {
			this.JSONOut(http.StatusBadRequest, "Team invalid", nil)
			return
		}

		teams = append(teams, *team)
	}

	this.JSONOut(http.StatusOK, "", teams)
	return
}
Exemple #2
0
func (this *OrganizationWebV1Controller) GetJoinOrgs() {
	user := new(models.User)
	orgs := make([]models.Organization, 0)

	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
	}

	for _, name := range user.JoinOrganizations {
		org := new(models.Organization)
		if err := org.GetByName(name); err != nil {
			this.JSONOut(http.StatusBadRequest, "Get organizations error", nil)
			return
		}

		orgs = append(orgs, *org)
	}

	this.JSONOut(http.StatusOK, "", orgs)
	return
}
Exemple #3
0
func (this *OrganizationWebV1Controller) GetPrivateRepos() {
	org := new(models.Organization)
	repos := make([]models.Repository, 0)

	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
	}

	for _, v := range org.Repositories {
		repo := new(models.Repository)

		if err := repo.Get(v); err != nil {
			this.JSONOut(http.StatusBadRequest, "Repository invalid", nil)
			return
		}

		if repo.Privated == true {
			repos = append(repos, *repo)
		}
	}

	this.JSONOut(http.StatusOK, "", repos)
	return
}
Exemple #4
0
func (this *OrganizationWebV1Controller) GetTeam() {
	user := new(models.User)
	org := new(models.Organization)
	team := new(models.Team)

	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
	}

	this.JSONOut(http.StatusOK, "", team)
	return
}
Exemple #5
0
func (this *TeamWebV1Controller) GetTeams() {
	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
	}

	teams := make([]models.Team, 0)

	org := new(models.Organization)
	if err := org.GetByName(this.Ctx.Input.Param(":org")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	for _, name := range org.Teams {
		team := new(models.Team)
		if err := team.GetByName(org.Name, name); err != nil {
			this.JSONOut(http.StatusBadRequest, err.Error(), nil)
			return
		}

		teams = append(teams, *team)
	}

	this.JSONOut(http.StatusOK, "", teams)
	return
}
Exemple #6
0
func (this *OrganizationWebV1Controller) GetOrg() {
	org := new(models.Organization)

	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
	}

	this.JSONOut(http.StatusOK, "", org)
	return
}
Exemple #7
0
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
	}
}
Exemple #8
0
func (this *OrganizationWebV1Controller) PutTeam() {
	user := new(models.User)
	org := new(models.Organization)
	team := new(models.Team)

	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 err := json.Unmarshal(this.Ctx.Input.CopyBody(), &team); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	team.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := team.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "Team save error", nil)
		return
	}

	this.JSONOut(http.StatusOK, "Team update successfully", nil)
	return
}
Exemple #9
0
func checkOrgRepositoryPermission(user *models.User, namespace, repository string, permission int) bool {
	owner := false

	//Check Org exists
	org := new(models.Organization)
	if has, _, _ := org.Has(namespace); has == false {
		return false
	}

	//Check Owner, don't care Join team
	for _, k := range user.Organizations {
		if org.Id == k {
			owner = true
		}
	}

	//Check Repository
	repo := new(models.Repository)
	if has, _, _ := repo.Has(namespace, repository); has == false {
		if owner == true {
			return true
		} else {
			return false
		}
	}

	if repo.Privated == false && permission == PERMISSION_READ {
		return true
	}

	//Loop Team
	for _, k := range user.JoinTeams {
		team := new(models.Team)

		if err := team.GetById(k); err != nil {
			return false
		}

		//TODO Check Team Perimssion

	}

	return false
}
Exemple #10
0
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
}
Exemple #11
0
func (this *UserWebAPIV1Controller) Signup() {
	user := new(models.User)
	org := new(models.Organization)

	if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &user); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	} else {
		if exist, _, err := org.Has(user.Username); err != nil {
			this.JSONOut(http.StatusBadRequest, err.Error(), nil)
			return
		} else if exist == true {
			this.JSONOut(http.StatusBadRequest, "Namespace is occupation already by organization.", nil)
			return
		}

		if exist, _, err := user.Has(user.Username); err != nil {
			this.JSONOut(http.StatusBadRequest, err.Error(), nil)
			return
		} else if exist == true {
			this.JSONOut(http.StatusBadRequest, "User already exist.", nil)
			return
		} else {
			user.Id = string(utils.GeneralKey(user.Username))
			user.Created = time.Now().UnixNano() / int64(time.Millisecond)
			user.Gravatar = "/static/images/default-user-icon-profile.png"

			if err := user.Save(); err != nil {
				this.JSONOut(http.StatusBadRequest, err.Error(), nil)
				return
			}

			memo, _ := json.Marshal(this.Ctx.Input.Header)
			user.Log(models.ACTION_SIGNUP, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo)

			this.JSONOut(http.StatusOK, "User singup successfully!", nil)
			return
		}
	}
}
Exemple #12
0
func (this *RepoAPIV1Controller) PutRepositoryImages() {
	namespace := this.Ctx.Input.Param(":namespace")
	repository := this.Ctx.Input.Param(":repo_name")

	repo := new(models.Repository)

	if err := repo.PutImages(namespace, repository); err != nil {
		this.JSONOut(http.StatusBadRequest, "Update Uploaded flag error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	repo.Log(models.ACTION_PUT_REPO_IMAGES, models.LEVELINFORMATIONAL, models.TYPE_APIV1, repo.Id, memo)

	org := new(models.Organization)
	isOrg, _, err := org.Has(namespace)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, "Search Organization Error", nil)
		return
	}

	user := new(models.User)
	authUsername, _, _ := utils.DecodeBasicAuth(this.Ctx.Input.Header("Authorization"))
	isUser, _, err := user.Has(authUsername)
	if err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	if !isUser && !isOrg {
		this.JSONOut(http.StatusBadRequest, "Search Namespace Error", nil)
		return
	}

	if isUser {
		user.Repositories = append(user.Repositories, repo.Id)
		user.Save()
	}
	if isOrg {
		org.Repositories = append(org.Repositories, repo.Id)
		org.Save()
	}

	this.Ctx.Output.Context.Output.SetStatus(http.StatusNoContent)
	this.Ctx.Output.Context.Output.Body([]byte(""))

	this.ServeJson()
	return
}
Exemple #13
0
func (this *OrganizationWebV1Controller) PutOrg() {
	user := new(models.User)
	org := new(models.Organization)

	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 err := json.Unmarshal(this.Ctx.Input.CopyBody(), &org); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	org.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := org.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "Organization save error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	user.Log(models.ACTION_UPDATE_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, org.Id, memo)
	org.Log(models.ACTION_UPDATE_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo)

	this.JSONOut(http.StatusOK, "Update organization successfully", nil)
	return
}
Exemple #14
0
func (this *OrganizationWebV1Controller) PostTeam() {
	user := new(models.User)
	org := new(models.Organization)
	team := new(models.Team)

	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 == true {
		this.JSONOut(http.StatusBadRequest, "Team already exist", nil)
		return
	}

	if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &team); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	team.Id = fmt.Sprintf("%s-%s", this.Ctx.Input.Param(":org"), this.Ctx.Input.Param(":team"))
	team.Username = this.Ctx.Input.Param(":username")
	team.Users, team.Repositories = []string{this.Ctx.Input.Param(":username")}, []string{}
	team.Created = time.Now().UnixNano() / int64(time.Millisecond)
	team.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := team.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "Team save error", nil)
		return
	}

	org.Teams = append(org.Teams, team.Id)
	org.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := org.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "Organization save error", nil)
		return
	}

	user.Teams = append(user.Teams, team.Id)
	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, "Team create successfully", nil)
	return
}
Exemple #15
0
func (this *OrganizationWebV1Controller) PostOrg() {
	user := new(models.User)
	org := new(models.Organization)

	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 := user.Has(this.Ctx.Input.Param(":org")); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	} else if exist == true {
		this.JSONOut(http.StatusBadRequest, "Namespace is occupation already by another user", 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 == true {
		this.JSONOut(http.StatusBadRequest, "Namespace is occupation already by another organization", nil)
		return
	}

	if err := json.Unmarshal(this.Ctx.Input.CopyBody(), &org); err != nil {
		this.JSONOut(http.StatusBadRequest, err.Error(), nil)
		return
	}

	org.Id = string(utils.GeneralKey(org.Name))
	org.Username = user.Username
	org.Created = time.Now().UnixNano() / int64(time.Millisecond)
	org.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := org.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "Organization save error", nil)
		return
	}

	user.Organizations = append(user.Organizations, org.Name)
	user.Updated = time.Now().UnixNano() / int64(time.Millisecond)

	if err := user.Save(); err != nil {
		this.JSONOut(http.StatusBadRequest, "User save error", nil)
		return
	}

	memo, _ := json.Marshal(this.Ctx.Input.Header)
	user.Log(models.ACTION_ADD_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, org.Id, memo)
	org.Log(models.ACTION_ADD_ORG, models.LEVELINFORMATIONAL, models.TYPE_WEBV1, user.Id, memo)

	this.JSONOut(http.StatusOK, "Create organization successfully.", nil)
	return
}
Exemple #16
0
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
}
Exemple #17
0
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
}