Merge pull request #2 from mattermost/mm-1239

fixes mm-1239 adds config setting to turn off valet feature
Этот коммит содержится в:
Corey Hulen
2015-06-15 10:01:37 -08:00
родитель c068d40c17 e774a67e33
Коммит 61eac918b7
7 изменённых файлов: 75 добавлений и 49 удалений

Просмотреть файл

@@ -19,12 +19,16 @@ var commands = []commandHandler{
logoutCommand, logoutCommand,
joinCommand, joinCommand,
loadTestCommand, loadTestCommand,
echoCommand,
} }
func InitCommand(r *mux.Router) { func InitCommand(r *mux.Router) {
l4g.Debug("Initializing command api routes") l4g.Debug("Initializing command api routes")
r.Handle("/command", ApiUserRequired(command)).Methods("POST") r.Handle("/command", ApiUserRequired(command)).Methods("POST")
if utils.Cfg.TeamSettings.AllowValet {
commands = append(commands, echoCommand)
}
hub.Start() hub.Start()
} }

Просмотреть файл

@@ -58,6 +58,12 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) { func createValetPost(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.TeamSettings.AllowValet {
c.Err = model.NewAppError("createValetPost", "The valet feature is currently turned off. Please contact your system administrator for details.", "")
c.Err.StatusCode = http.StatusNotImplemented
return
}
post := model.PostFromJson(r.Body) post := model.PostFromJson(r.Body)
if post == nil { if post == nil {
c.SetInvalidParam("createValetPost", "post") c.SetInvalidParam("createValetPost", "post")

Просмотреть файл

@@ -147,62 +147,70 @@ func TestCreateValetPost(t *testing.T) {
channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel2 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel) channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"} if utils.Cfg.TeamSettings.AllowValet {
rpost1, err := Client.CreateValetPost(post1) post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
if err != nil { rpost1, err := Client.CreateValetPost(post1)
t.Fatal(err) if err != nil {
} t.Fatal(err)
}
if rpost1.Data.(*model.Post).Message != post1.Message { if rpost1.Data.(*model.Post).Message != post1.Message {
t.Fatal("message didn't match") t.Fatal("message didn't match")
} }
if rpost1.Data.(*model.Post).Hashtags != "#hashtag" { if rpost1.Data.(*model.Post).Hashtags != "#hashtag" {
t.Fatal("hashtag didn't match") t.Fatal("hashtag didn't match")
} }
post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id} post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
rpost2, err := Client.CreateValetPost(post2) rpost2, err := Client.CreateValetPost(post2)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id, ParentId: rpost2.Data.(*model.Post).Id} post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id, ParentId: rpost2.Data.(*model.Post).Id}
_, err = Client.CreateValetPost(post3) _, err = Client.CreateValetPost(post3)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
post4 := &model.Post{ChannelId: "junk", Message: "a" + model.NewId() + "a"} post4 := &model.Post{ChannelId: "junk", Message: "a" + model.NewId() + "a"}
_, err = Client.CreateValetPost(post4) _, err = Client.CreateValetPost(post4)
if err.StatusCode != http.StatusForbidden { if err.StatusCode != http.StatusForbidden {
t.Fatal("Should have been forbidden") t.Fatal("Should have been forbidden")
} }
Client.LoginByEmail(team.Domain, user2.Email, "pwd") Client.LoginByEmail(team.Domain, user2.Email, "pwd")
post5 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post5 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
_, err = Client.CreateValetPost(post5) _, err = Client.CreateValetPost(post5)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
user3 := &model.User{TeamId: team2.Id, Email: model.NewId() + "corey@test.com", FullName: "Corey Hulen", Password: "pwd"} user3 := &model.User{TeamId: team2.Id, Email: model.NewId() + "corey@test.com", FullName: "Corey Hulen", Password: "pwd"}
user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User) user3 = Client.Must(Client.CreateUser(user3, "")).Data.(*model.User)
Srv.Store.User().VerifyEmail(user3.Id) Srv.Store.User().VerifyEmail(user3.Id)
Client.LoginByEmail(team2.Domain, user3.Email, "pwd") Client.LoginByEmail(team2.Domain, user3.Email, "pwd")
channel3 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team2.Id} channel3 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team2.Id}
channel3 = Client.Must(Client.CreateChannel(channel3)).Data.(*model.Channel) channel3 = Client.Must(Client.CreateChannel(channel3)).Data.(*model.Channel)
post6 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post6 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
_, err = Client.CreateValetPost(post6) _, err = Client.CreateValetPost(post6)
if err.StatusCode != http.StatusForbidden { if err.StatusCode != http.StatusForbidden {
t.Fatal("Should have been forbidden") t.Fatal("Should have been forbidden")
} }
if _, err = Client.DoPost("/channels/"+channel3.Id+"/create", "garbage"); err == nil { if _, err = Client.DoPost("/channels/"+channel3.Id+"/create", "garbage"); err == nil {
t.Fatal("should have been an error") t.Fatal("should have been an error")
}
} else {
post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
_, err := Client.CreateValetPost(post1)
if err.StatusCode != http.StatusNotImplemented {
t.Fatal("Should have failed with 501 - Not Implemented")
}
} }
} }

Просмотреть файл

@@ -157,9 +157,11 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
return return
} }
CreateValet(c, rteam) if utils.Cfg.TeamSettings.AllowValet {
if c.Err != nil { CreateValet(c, rteam)
return if c.Err != nil {
return
}
} }
InviteMembers(rteam, ruser, teamSignup.Invites) InviteMembers(rteam, ruser, teamSignup.Invites)

Просмотреть файл

@@ -145,6 +145,10 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func CreateValet(c *Context, team *model.Team) *model.User { func CreateValet(c *Context, team *model.Team) *model.User {
if !utils.Cfg.TeamSettings.AllowValet {
return &model.User{}
}
valet := &model.User{} valet := &model.User{}
valet.TeamId = team.Id valet.TeamId = team.Id
valet.Email = utils.Cfg.EmailSettings.FeedbackEmail valet.Email = utils.Cfg.EmailSettings.FeedbackEmail

Просмотреть файл

@@ -72,6 +72,7 @@
"TeamSettings": { "TeamSettings": {
"MaxUsersPerTeam": 150, "MaxUsersPerTeam": 150,
"AllowPublicLink": true, "AllowPublicLink": true,
"AllowValet": false,
"TermsLink": "/static/help/configure_links.html", "TermsLink": "/static/help/configure_links.html",
"PrivacyLink": "/static/help/configure_links.html", "PrivacyLink": "/static/help/configure_links.html",
"AboutLink": "/static/help/configure_links.html", "AboutLink": "/static/help/configure_links.html",

Просмотреть файл

@@ -96,6 +96,7 @@ type PrivacySettings struct {
type TeamSettings struct { type TeamSettings struct {
MaxUsersPerTeam int MaxUsersPerTeam int
AllowPublicLink bool AllowPublicLink bool
AllowValet bool
TermsLink string TermsLink string
PrivacyLink string PrivacyLink string
AboutLink string AboutLink string