Removing old createTeamFromSignup api (#4945)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
3df8f33437
Коммит
a71fc7ff7f
90
api/team.go
90
api/team.go
@@ -25,7 +25,6 @@ func InitTeam() {
|
||||
l4g.Debug(utils.T("api.team.init.debug"))
|
||||
|
||||
BaseRoutes.Teams.Handle("/create", ApiAppHandler(createTeam)).Methods("POST")
|
||||
BaseRoutes.Teams.Handle("/create_from_signup", ApiAppHandler(createTeamFromSignup)).Methods("POST")
|
||||
BaseRoutes.Teams.Handle("/signup", ApiAppHandler(signupTeam)).Methods("POST")
|
||||
BaseRoutes.Teams.Handle("/all", ApiAppHandler(getAll)).Methods("GET")
|
||||
BaseRoutes.Teams.Handle("/all_team_listings", ApiUserRequired(GetAllTeamListings)).Methods("GET")
|
||||
@@ -104,94 +103,6 @@ func signupTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
}
|
||||
|
||||
func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !utils.Cfg.EmailSettings.EnableSignUpWithEmail {
|
||||
c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.email_disabled.app_error", nil, "")
|
||||
c.Err.StatusCode = http.StatusNotImplemented
|
||||
return
|
||||
}
|
||||
|
||||
teamSignup := model.TeamSignupFromJson(r.Body)
|
||||
|
||||
if teamSignup == nil {
|
||||
c.SetInvalidParam("createTeam", "teamSignup")
|
||||
return
|
||||
}
|
||||
|
||||
props := model.MapFromJson(strings.NewReader(teamSignup.Data))
|
||||
teamSignup.Team.Email = props["email"]
|
||||
teamSignup.User.Email = props["email"]
|
||||
|
||||
teamSignup.Team.PreSave()
|
||||
|
||||
if err := teamSignup.Team.IsValid(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
if !isTeamCreationAllowed(c, teamSignup.Team.Email) {
|
||||
return
|
||||
}
|
||||
|
||||
teamSignup.Team.Id = ""
|
||||
|
||||
password := teamSignup.User.Password
|
||||
teamSignup.User.PreSave()
|
||||
if err := teamSignup.User.IsValid(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
teamSignup.User.Id = ""
|
||||
teamSignup.User.Password = password
|
||||
|
||||
if !model.ComparePassword(teamSignup.Hash, fmt.Sprintf("%v:%v", teamSignup.Data, utils.Cfg.EmailSettings.InviteSalt)) {
|
||||
c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.invalid_link.app_error", nil, "")
|
||||
return
|
||||
}
|
||||
|
||||
t, err := strconv.ParseInt(props["time"], 10, 64)
|
||||
if err != nil || model.GetMillis()-t > 1000*60*60 { // one hour
|
||||
c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.expired_link.app_error", nil, "")
|
||||
return
|
||||
}
|
||||
|
||||
found := FindTeamByName(teamSignup.Team.Name)
|
||||
|
||||
if found {
|
||||
c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.unavailable.app_error", nil, "d="+teamSignup.Team.Name)
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Team().Save(&teamSignup.Team); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
rteam := result.Data.(*model.Team)
|
||||
|
||||
if _, err := CreateDefaultChannels(c, rteam.Id); err != nil {
|
||||
c.Err = nil
|
||||
return
|
||||
}
|
||||
|
||||
teamSignup.User.EmailVerified = true
|
||||
|
||||
ruser, err := CreateUser(&teamSignup.User)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
JoinUserToTeam(rteam, ruser)
|
||||
|
||||
InviteMembers(rteam, ruser.GetDisplayName(), teamSignup.Invites)
|
||||
|
||||
teamSignup.Team = *rteam
|
||||
teamSignup.User = *ruser
|
||||
|
||||
w.Write([]byte(teamSignup.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
team := model.TeamFromJson(r.Body)
|
||||
|
||||
@@ -374,6 +285,7 @@ func isTeamCreationAllowed(c *Context, email string) bool {
|
||||
c.Err = model.NewLocAppError("isTeamCreationAllowed", "api.team.is_team_creation_allowed.disabled.app_error", nil, "")
|
||||
return false
|
||||
}
|
||||
c.Err = nil
|
||||
|
||||
if result := <-Srv.Store.User().GetByEmail(email); result.Err == nil {
|
||||
user := result.Data.(*model.User)
|
||||
|
||||
149
api/team_test.go
149
api/team_test.go
@@ -4,8 +4,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
@@ -24,57 +22,6 @@ func TestSignupTeam(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateFromSignupTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th.BasicClient.Logout()
|
||||
Client := th.BasicClient
|
||||
|
||||
props := make(map[string]string)
|
||||
props["email"] = strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com"
|
||||
props["name"] = "Test Company name"
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
user := model.User{Email: props["email"], Nickname: "Corey Hulen", Password: "hello1"}
|
||||
|
||||
ts := model.TeamSignup{Team: team, User: user, Invites: []string{"success+test@simulator.amazonses.com"}, Data: data, Hash: hash}
|
||||
|
||||
rts, err := Client.CreateTeamFromSignup(&ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rts.Data.(*model.TeamSignup).Team.DisplayName != team.DisplayName {
|
||||
t.Fatal("full name didn't match")
|
||||
}
|
||||
|
||||
ruser := rts.Data.(*model.TeamSignup).User
|
||||
rteam := rts.Data.(*model.TeamSignup).Team
|
||||
Client.SetTeamId(rteam.Id)
|
||||
|
||||
if result, err := Client.LoginById(ruser.Id, user.Password); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if result.Data.(*model.User).Email != user.Email {
|
||||
t.Fatal("email's didn't match")
|
||||
}
|
||||
}
|
||||
|
||||
c1 := Client.Must(Client.GetChannels("")).Data.(*model.ChannelList)
|
||||
if len(*c1) != 2 {
|
||||
t.Fatal("default channels not created")
|
||||
}
|
||||
|
||||
ts.Data = "garbage"
|
||||
_, err = Client.CreateTeamFromSignup(&ts)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th.BasicClient.Logout()
|
||||
@@ -120,51 +67,25 @@ func TestCreateTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddUserToTeam(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th.BasicClient.Logout()
|
||||
Client := th.BasicClient
|
||||
|
||||
props := make(map[string]string)
|
||||
props["email"] = strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com"
|
||||
props["name"] = "Test Company name"
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: props["email"], Type: model.TEAM_OPEN}
|
||||
user := model.User{Email: props["email"], Nickname: "Corey Hulen", Password: "hello1"}
|
||||
|
||||
ts := model.TeamSignup{Team: team, User: user, Invites: []string{"success+test@simulator.amazonses.com"}, Data: data, Hash: hash}
|
||||
|
||||
rts, err := Client.CreateTeamFromSignup(&ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rts.Data.(*model.TeamSignup).Team.DisplayName != team.DisplayName {
|
||||
t.Fatal("full name didn't match")
|
||||
}
|
||||
|
||||
ruser := rts.Data.(*model.TeamSignup).User
|
||||
rteam := rts.Data.(*model.TeamSignup).Team
|
||||
Client.SetTeamId(rteam.Id)
|
||||
|
||||
if result, err := Client.LoginById(ruser.Id, user.Password); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if result.Data.(*model.User).Email != user.Email {
|
||||
t.Fatal("email's didn't match")
|
||||
}
|
||||
}
|
||||
th := Setup().InitSystemAdmin().InitBasic()
|
||||
|
||||
user2 := th.CreateUser(th.BasicClient)
|
||||
if result, err := th.BasicClient.AddUserToTeam("", user2.Id); err != nil {
|
||||
|
||||
if _, err := th.BasicClient.AddUserToTeam(th.BasicTeam.Id, user2.Id); err == nil {
|
||||
t.Fatal("Should have failed because of permissions")
|
||||
}
|
||||
|
||||
th.SystemAdminClient.SetTeamId(th.BasicTeam.Id)
|
||||
if _, err := th.SystemAdminClient.UpdateTeamRoles(th.BasicUser.Id, "team_user team_admin"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if result, err := th.BasicClient.AddUserToTeam(th.BasicTeam.Id, user2.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
rm := result.Data.(map[string]string)
|
||||
if rm["user_id"] != user2.Id {
|
||||
t.Fatal("email's didn't match")
|
||||
t.Fatal("ids didn't match")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,52 +125,16 @@ func TestRemoveUserFromTeam(t *testing.T) {
|
||||
|
||||
func TestAddUserToTeamFromInvite(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
th.BasicClient.Logout()
|
||||
Client := th.BasicClient
|
||||
|
||||
props := make(map[string]string)
|
||||
props["email"] = strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com"
|
||||
props["name"] = "Test Company name"
|
||||
props["time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
|
||||
data := model.MapToJson(props)
|
||||
hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.EmailSettings.InviteSalt))
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: props["email"], Type: model.TEAM_OPEN}
|
||||
user := model.User{Email: props["email"], Nickname: "Corey Hulen", Password: "hello1"}
|
||||
|
||||
ts := model.TeamSignup{Team: team, User: user, Invites: []string{"success+test@simulator.amazonses.com"}, Data: data, Hash: hash}
|
||||
|
||||
rts, err := Client.CreateTeamFromSignup(&ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rts.Data.(*model.TeamSignup).Team.DisplayName != team.DisplayName {
|
||||
t.Fatal("full name didn't match")
|
||||
}
|
||||
|
||||
ruser := rts.Data.(*model.TeamSignup).User
|
||||
rteam := rts.Data.(*model.TeamSignup).Team
|
||||
Client.SetTeamId(rteam.Id)
|
||||
|
||||
if result, err := Client.LoginById(ruser.Id, user.Password); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if result.Data.(*model.User).Email != user.Email {
|
||||
t.Fatal("email's didn't match")
|
||||
}
|
||||
}
|
||||
|
||||
user2 := th.CreateUser(th.BasicClient)
|
||||
Client.Must(Client.Logout())
|
||||
Client.Must(Client.Login(user2.Email, user2.Password))
|
||||
th.BasicClient.Must(th.BasicClient.Logout())
|
||||
th.BasicClient.Must(th.BasicClient.Login(user2.Email, user2.Password))
|
||||
|
||||
if result, err := th.BasicClient.AddUserToTeamFromInvite("", "", rteam.InviteId); err != nil {
|
||||
if result, err := th.BasicClient.AddUserToTeamFromInvite("", "", th.BasicTeam.InviteId); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
rtm := result.Data.(*model.Team)
|
||||
if rtm.Id != rteam.Id {
|
||||
if rtm.Id != th.BasicTeam.Id {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user