summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/command.go29
-rw-r--r--api/command_logout.go3
-rw-r--r--api/command_logout_test.go3
-rw-r--r--api/file.go35
-rw-r--r--api/post.go18
-rw-r--r--api/team.go76
6 files changed, 152 insertions, 12 deletions
diff --git a/api/command.go b/api/command.go
index 451de2c33..99fd05d7a 100644
--- a/api/command.go
+++ b/api/command.go
@@ -69,16 +69,18 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if result := <-Srv.Store.Command().GetByTeam(c.Session.TeamId); result.Err != nil {
- c.Err = result.Err
- return
- } else {
- teamCmds := result.Data.([]*model.Command)
- for _, cmd := range teamCmds {
- if cmd.AutoComplete && !seen[cmd.Id] {
- cmd.Sanitize()
- seen[cmd.Trigger] = true
- commands = append(commands, cmd)
+ if *utils.Cfg.ServiceSettings.EnableCommands {
+ if result := <-Srv.Store.Command().GetByTeam(c.Session.TeamId); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ teamCmds := result.Data.([]*model.Command)
+ for _, cmd := range teamCmds {
+ if cmd.AutoComplete && !seen[cmd.Id] {
+ cmd.Sanitize()
+ seen[cmd.Trigger] = true
+ commands = append(commands, cmd)
+ }
}
}
}
@@ -114,6 +116,13 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) {
handleResponse(c, w, response, channelId, provider.GetCommand(c), true)
return
} else {
+
+ if !*utils.Cfg.ServiceSettings.EnableCommands {
+ c.Err = model.NewLocAppError("executeCommand", "api.command.disabled.app_error", nil, "")
+ c.Err.StatusCode = http.StatusNotImplemented
+ return
+ }
+
chanChan := Srv.Store.Channel().Get(channelId)
teamChan := Srv.Store.Team().Get(c.Session.TeamId)
userChan := Srv.Store.User().Get(c.Session.UserId)
diff --git a/api/command_logout.go b/api/command_logout.go
index fb69b4f85..912093162 100644
--- a/api/command_logout.go
+++ b/api/command_logout.go
@@ -33,5 +33,6 @@ func (me *LogoutProvider) GetCommand(c *Context) *model.Command {
}
func (me *LogoutProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
- return &model.CommandResponse{GotoLocation: "/logout", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
+
+ return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/logout", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: c.T("api.command_logout.success_message")}
}
diff --git a/api/command_logout_test.go b/api/command_logout_test.go
index 86979316b..eee7520a8 100644
--- a/api/command_logout_test.go
+++ b/api/command_logout_test.go
@@ -4,6 +4,7 @@
package api
import (
+ "strings"
"testing"
"github.com/mattermost/platform/model"
@@ -26,7 +27,7 @@ func TestLogoutTestCommand(t *testing.T) {
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
rs1 := Client.Must(Client.Command(channel1.Id, "/logout", false)).Data.(*model.CommandResponse)
- if rs1.GotoLocation != "/logout" {
+ if !strings.HasSuffix(rs1.GotoLocation, "logout") {
t.Fatal("failed to logout")
}
}
diff --git a/api/file.go b/api/file.go
index 0011afd5b..9150e4bfe 100644
--- a/api/file.go
+++ b/api/file.go
@@ -547,6 +547,41 @@ func writeFile(f []byte, path string) *model.AppError {
return nil
}
+func moveFile(oldPath, newPath string) *model.AppError {
+ if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
+ fileData := make(chan []byte)
+ getFileAndForget(oldPath, fileData)
+ fileBytes := <-fileData
+
+ if fileBytes == nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.get_from_s3.app_error", nil, "")
+ }
+
+ var auth aws.Auth
+ auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId
+ auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey
+
+ s := s3.New(auth, awsRegion())
+ bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket)
+
+ if err := bucket.Del(oldPath); err != nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.delete_from_s3.app_error", nil, err.Error())
+ }
+
+ if err := writeFile(fileBytes, newPath); err != nil {
+ return err
+ }
+ } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL {
+ if err := os.Rename(utils.Cfg.FileSettings.Directory+oldPath, utils.Cfg.FileSettings.Directory+newPath); err != nil {
+ return model.NewLocAppError("moveFile", "api.file.move_file.rename.app_error", nil, err.Error())
+ }
+ } else {
+ return model.NewLocAppError("moveFile", "api.file.move_file.configured.app_error", nil, "")
+ }
+
+ return nil
+}
+
func writeFileLocally(f []byte, path string) *model.AppError {
if err := os.MkdirAll(filepath.Dir(path), 0774); err != nil {
return model.NewLocAppError("writeFile", "api.file.write_file_locally.create_dir.app_error", nil, err.Error())
diff --git a/api/post.go b/api/post.go
index e6560a8e8..cd78b16f0 100644
--- a/api/post.go
+++ b/api/post.go
@@ -1094,6 +1094,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
message.Add("post", post.ToJson())
PublishAndForget(message)
+ DeletePostFilesAndForget(c.Session.TeamId, post)
result := make(map[string]string)
result["id"] = postId
@@ -1101,6 +1102,23 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func DeletePostFilesAndForget(teamId string, post *model.Post) {
+ go func() {
+ if len(post.Filenames) == 0 {
+ return
+ }
+
+ prefix := "teams/" + teamId + "/channels/" + post.ChannelId + "/users/" + post.UserId + "/"
+ for _, filename := range post.Filenames {
+ splitUrl := strings.Split(filename, "/")
+ oldPath := prefix + splitUrl[len(splitUrl)-2] + "/" + splitUrl[len(splitUrl)-1]
+ newPath := prefix + splitUrl[len(splitUrl)-2] + "/deleted_" + splitUrl[len(splitUrl)-1]
+ moveFile(oldPath, newPath)
+ }
+
+ }()
+}
+
func getPostsBefore(c *Context, w http.ResponseWriter, r *http.Request) {
getPostsBeforeOrAfter(c, w, r, true)
}
diff --git a/api/team.go b/api/team.go
index 052d6e698..2f680dc76 100644
--- a/api/team.go
+++ b/api/team.go
@@ -8,6 +8,7 @@ import (
"fmt"
l4g "github.com/alecthomas/log4go"
"github.com/gorilla/mux"
+ "github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
@@ -25,6 +26,7 @@ func InitTeam(r *mux.Router) {
sr := r.PathPrefix("/teams").Subrouter()
sr.Handle("/create", ApiAppHandler(createTeam)).Methods("POST")
sr.Handle("/create_from_signup", ApiAppHandler(createTeamFromSignup)).Methods("POST")
+ sr.Handle("/create_with_ldap", ApiAppHandler(createTeamWithLdap)).Methods("POST")
sr.Handle("/create_with_sso/{service:[A-Za-z]+}", ApiAppHandler(createTeamFromSSO)).Methods("POST")
sr.Handle("/signup", ApiAppHandler(signupTeam)).Methods("POST")
sr.Handle("/all", ApiUserRequired(getAll)).Methods("GET")
@@ -244,6 +246,80 @@ func createTeamFromSignup(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func createTeamWithLdap(c *Context, w http.ResponseWriter, r *http.Request) {
+ ldap := einterfaces.GetLdapInterface()
+ if ldap == nil {
+ c.Err = model.NewLocAppError("createTeamWithLdap", "ent.ldap.do_login.licence_disable.app_error", nil, "")
+ return
+ }
+
+ teamSignup := model.TeamSignupFromJson(r.Body)
+
+ if teamSignup == nil {
+ c.SetInvalidParam("createTeam", "teamSignup")
+ return
+ }
+
+ teamSignup.Team.PreSave()
+
+ if err := teamSignup.Team.IsValid(*utils.Cfg.TeamSettings.RestrictTeamNames); err != nil {
+ c.Err = err
+ return
+ }
+
+ if !isTeamCreationAllowed(c, teamSignup.Team.Email) {
+ return
+ }
+
+ teamSignup.Team.Id = ""
+
+ found := FindTeamByName(c, teamSignup.Team.Name, "true")
+ if c.Err != nil {
+ return
+ }
+
+ if found {
+ c.Err = model.NewLocAppError("createTeamFromSignup", "api.team.create_team_from_signup.unavailable.app_error", nil, "d="+teamSignup.Team.Name)
+ return
+ }
+
+ user, err := ldap.GetUser(teamSignup.User.Username)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ err = ldap.CheckPassword(teamSignup.User.Username, teamSignup.User.Password)
+ if err != nil {
+ c.Err = err
+ 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
+ }
+
+ user.TeamId = rteam.Id
+ ruser, err := CreateUser(rteam, user)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ 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)
rteam := CreateTeam(c, team)