diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-10-04 11:42:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-04 11:42:38 -0400 |
commit | fadd9514f6e71590aba781a7035e1de4150137b0 (patch) | |
tree | a265d44f377281abd56baf31fe878e08f90f7d4b /app | |
parent | fa80cb10a8ad047f9504c49ed2671d31650d1878 (diff) | |
download | chat-fadd9514f6e71590aba781a7035e1de4150137b0.tar.gz chat-fadd9514f6e71590aba781a7035e1de4150137b0.tar.bz2 chat-fadd9514f6e71590aba781a7035e1de4150137b0.zip |
PLT-7718 Patch for files (#7564)
* Patch for files
* Fix merge
* Fix tests
* Fix another test
Diffstat (limited to 'app')
-rw-r--r-- | app/authorization.go | 3 | ||||
-rw-r--r-- | app/file.go | 5 | ||||
-rw-r--r-- | app/file_test.go | 14 |
3 files changed, 21 insertions, 1 deletions
diff --git a/app/authorization.go b/app/authorization.go index ae5c7c3b3..01180e8d8 100644 --- a/app/authorization.go +++ b/app/authorization.go @@ -4,6 +4,7 @@ package app import ( + "net/http" "strings" l4g "github.com/alecthomas/log4go" @@ -50,6 +51,8 @@ func (a *App) SessionHasPermissionToChannel(session model.Session, channelId str channel, err := a.GetChannel(channelId) if err == nil && channel.TeamId != "" { return SessionHasPermissionToTeam(session, channel.TeamId, permission) + } else if err != nil && err.StatusCode == http.StatusNotFound { + return false } return SessionHasPermissionTo(session, permission) diff --git a/app/file.go b/app/file.go index 36a23e3d8..2beb7231a 100644 --- a/app/file.go +++ b/app/file.go @@ -291,8 +291,11 @@ func (a *App) UploadFiles(teamId string, channelId string, userId string, fileHe return resStruct, nil } -func (a *App) DoUploadFile(now time.Time, teamId string, channelId string, userId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) { +func (a *App) DoUploadFile(now time.Time, rawTeamId string, rawChannelId string, rawUserId string, rawFilename string, data []byte) (*model.FileInfo, *model.AppError) { filename := filepath.Base(rawFilename) + teamId := filepath.Base(rawTeamId) + channelId := filepath.Base(rawChannelId) + userId := filepath.Base(rawUserId) info, err := model.GetInfoForBytes(filename, data) if err != nil { diff --git a/app/file_test.go b/app/file_test.go index 62511ceea..f3141fa18 100644 --- a/app/file_test.go +++ b/app/file_test.go @@ -85,4 +85,18 @@ func TestDoUploadFile(t *testing.T) { if info3.Path != fmt.Sprintf("20080305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info3.Id, filename) { t.Fatal("stored file at incorrect path", info3.Path) } + + info4, err := th.App.DoUploadFile(time.Date(2009, 3, 5, 1, 2, 3, 4, time.Local), "../../"+teamId, "../../"+channelId, "../../"+userId, "../../"+filename, data) + if err != nil { + t.Fatal(err) + } else { + defer func() { + <-th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id) + utils.RemoveFile(info3.Path) + }() + } + + if info4.Path != fmt.Sprintf("20090305/teams/%v/channels/%v/users/%v/%v/%v", teamId, channelId, userId, info4.Id, filename) { + t.Fatal("stored file at incorrect path", info4.Path) + } } |