summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorReed Garmsen <rgarmsen2295@gmail.com>2015-06-15 11:22:53 -0700
committerReed Garmsen <rgarmsen2295@gmail.com>2015-06-15 11:22:53 -0700
commit6883f691ef3b33ceee6bc525830675245aaf508a (patch)
tree4693838432e0c544944b137ab246fbcc4583d848 /api
parentc94883e0dfc0c7cbcf86a78f9134d1e3283a07cd (diff)
parent08e02c3dad4d2fa765b11ae58313b3f3e375e447 (diff)
downloadchat-6883f691ef3b33ceee6bc525830675245aaf508a.tar.gz
chat-6883f691ef3b33ceee6bc525830675245aaf508a.tar.bz2
chat-6883f691ef3b33ceee6bc525830675245aaf508a.zip
Merge pull request #1 from mattermost/master
to me
Diffstat (limited to 'api')
-rw-r--r--api/command.go6
-rw-r--r--api/file.go2
-rw-r--r--api/post.go6
-rw-r--r--api/post_test.go98
-rw-r--r--api/team.go8
-rw-r--r--api/user.go4
6 files changed, 74 insertions, 50 deletions
diff --git a/api/command.go b/api/command.go
index 9efc79b49..449483bbf 100644
--- a/api/command.go
+++ b/api/command.go
@@ -19,12 +19,16 @@ var commands = []commandHandler{
logoutCommand,
joinCommand,
loadTestCommand,
- echoCommand,
}
func InitCommand(r *mux.Router) {
l4g.Debug("Initializing command api routes")
r.Handle("/command", ApiUserRequired(command)).Methods("POST")
+
+ if utils.Cfg.TeamSettings.AllowValet {
+ commands = append(commands, echoCommand)
+ }
+
hub.Start()
}
diff --git a/api/file.go b/api/file.go
index c7c3b7b3e..10167c6ff 100644
--- a/api/file.go
+++ b/api/file.go
@@ -114,7 +114,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- fileUrl := c.TeamUrl + "/api/v1/files/get/" + channelId + "/" + c.Session.UserId + "/" + uid + "/" + files[i].Filename
+ fileUrl := c.TeamUrl + "/api/v1/files/get/" + channelId + "/" + c.Session.UserId + "/" + uid + "/" + url.QueryEscape(files[i].Filename)
resStruct.Filenames = append(resStruct.Filenames, fileUrl)
}
diff --git a/api/post.go b/api/post.go
index 25a68304d..36607c231 100644
--- a/api/post.go
+++ b/api/post.go
@@ -58,6 +58,12 @@ func createPost(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)
if post == nil {
c.SetInvalidParam("createValetPost", "post")
diff --git a/api/post_test.go b/api/post_test.go
index 4b40bc06a..b322a5017 100644
--- a/api/post_test.go
+++ b/api/post_test.go
@@ -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 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
- post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
- rpost1, err := Client.CreateValetPost(post1)
- if err != nil {
- t.Fatal(err)
- }
+ if utils.Cfg.TeamSettings.AllowValet {
+ post1 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag a" + model.NewId() + "a"}
+ rpost1, err := Client.CreateValetPost(post1)
+ if err != nil {
+ t.Fatal(err)
+ }
- if rpost1.Data.(*model.Post).Message != post1.Message {
- t.Fatal("message didn't match")
- }
+ if rpost1.Data.(*model.Post).Message != post1.Message {
+ t.Fatal("message didn't match")
+ }
- if rpost1.Data.(*model.Post).Hashtags != "#hashtag" {
- t.Fatal("hashtag didn't match")
- }
+ if rpost1.Data.(*model.Post).Hashtags != "#hashtag" {
+ t.Fatal("hashtag didn't match")
+ }
- post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
- rpost2, err := Client.CreateValetPost(post2)
- if err != nil {
- t.Fatal(err)
- }
+ post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: rpost1.Data.(*model.Post).Id}
+ rpost2, err := Client.CreateValetPost(post2)
+ if err != nil {
+ 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}
- _, err = Client.CreateValetPost(post3)
- if err != nil {
- 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}
+ _, err = Client.CreateValetPost(post3)
+ if err != nil {
+ t.Fatal(err)
+ }
- post4 := &model.Post{ChannelId: "junk", Message: "a" + model.NewId() + "a"}
- _, err = Client.CreateValetPost(post4)
- if err.StatusCode != http.StatusForbidden {
- t.Fatal("Should have been forbidden")
- }
+ post4 := &model.Post{ChannelId: "junk", Message: "a" + model.NewId() + "a"}
+ _, err = Client.CreateValetPost(post4)
+ if err.StatusCode != http.StatusForbidden {
+ t.Fatal("Should have been forbidden")
+ }
- Client.LoginByEmail(team.Domain, user2.Email, "pwd")
- post5 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
- _, err = Client.CreateValetPost(post5)
- if err != nil {
- t.Fatal(err)
- }
+ Client.LoginByEmail(team.Domain, user2.Email, "pwd")
+ post5 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ _, err = Client.CreateValetPost(post5)
+ if err != nil {
+ t.Fatal(err)
+ }
- 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)
- Srv.Store.User().VerifyEmail(user3.Id)
+ 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)
+ 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 = Client.Must(Client.CreateChannel(channel3)).Data.(*model.Channel)
+ 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)
- post6 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
- _, err = Client.CreateValetPost(post6)
- if err.StatusCode != http.StatusForbidden {
- t.Fatal("Should have been forbidden")
- }
+ post6 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"}
+ _, err = Client.CreateValetPost(post6)
+ if err.StatusCode != http.StatusForbidden {
+ t.Fatal("Should have been forbidden")
+ }
- if _, err = Client.DoPost("/channels/"+channel3.Id+"/create", "garbage"); err == nil {
- t.Fatal("should have been an error")
+ if _, err = Client.DoPost("/channels/"+channel3.Id+"/create", "garbage"); err == nil {
+ 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")
+ }
}
}
diff --git a/api/team.go b/api/team.go
index b04d8c588..cb60602c6 100644
--- a/api/team.go
+++ b/api/team.go
@@ -157,9 +157,11 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- CreateValet(c, rteam)
- if c.Err != nil {
- return
+ if utils.Cfg.TeamSettings.AllowValet {
+ CreateValet(c, rteam)
+ if c.Err != nil {
+ return
+ }
}
InviteMembers(rteam, ruser, teamSignup.Invites)
diff --git a/api/user.go b/api/user.go
index c0ebc05e0..83e29b28e 100644
--- a/api/user.go
+++ b/api/user.go
@@ -145,6 +145,10 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
func CreateValet(c *Context, team *model.Team) *model.User {
+ if !utils.Cfg.TeamSettings.AllowValet {
+ return &model.User{}
+ }
+
valet := &model.User{}
valet.TeamId = team.Id
valet.Email = utils.Cfg.EmailSettings.FeedbackEmail