diff --git a/api4/file.go b/api4/file.go index 3426a04844..ef3f410d4b 100644 --- a/api4/file.go +++ b/api4/file.go @@ -65,92 +65,6 @@ func (api *API) InitFile() { } -func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { - defer io.Copy(ioutil.Discard, r.Body) - - if !*c.App.Config().FileSettings.EnableFileAttachments { - c.Err = model.NewAppError("uploadFile", "api.file.attachments.disabled.app_error", nil, "", http.StatusNotImplemented) - return - } - - if r.ContentLength > *c.App.Config().FileSettings.MaxFileSize { - c.Err = model.NewAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge) - return - } - - now := time.Now() - var resStruct *model.FileUploadResponse - var appErr *model.AppError - - if err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize); err != nil && err != http.ErrNotMultipart { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } else if err == http.ErrNotMultipart { - defer r.Body.Close() - - c.RequireChannelId() - c.RequireFilename() - - if c.Err != nil { - return - } - - channelId := c.Params.ChannelId - filename := c.Params.Filename - - if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_UPLOAD_FILE) { - c.SetPermissionError(model.PERMISSION_UPLOAD_FILE) - return - } - - resStruct, appErr = c.App.UploadFiles( - FILE_TEAM_ID, - channelId, - c.App.Session.UserId, - []io.ReadCloser{r.Body}, - []string{filename}, - []string{}, - now, - ) - } else { - m := r.MultipartForm - - props := m.Value - if len(props["channel_id"]) == 0 { - c.SetInvalidParam("channel_id") - return - } - channelId := props["channel_id"][0] - c.Params.ChannelId = channelId - c.RequireChannelId() - if c.Err != nil { - return - } - - if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_UPLOAD_FILE) { - c.SetPermissionError(model.PERMISSION_UPLOAD_FILE) - return - } - - resStruct, appErr = c.App.UploadMultipartFiles( - FILE_TEAM_ID, - channelId, - c.App.Session.UserId, - m.File["files"], - m.Value["client_ids"], - now, - ) - } - - if appErr != nil { - c.Err = appErr - return - } - - w.WriteHeader(http.StatusCreated) - w.Write([]byte(resStruct.ToJson())) -} - func parseMultipartRequestHeader(req *http.Request) (boundary string, err error) { v := req.Header.Get("Content-Type") if v == "" { diff --git a/config/utils_test.go b/config/utils_test.go index 8bfc2eb33b..131c843e7c 100644 --- a/config/utils_test.go +++ b/config/utils_test.go @@ -204,7 +204,3 @@ func sToP(s string) *string { func bToP(b bool) *bool { return &b } - -func iToP(i int) *int { - return &i -} diff --git a/i18n/en.json b/i18n/en.json index 6a89c055f4..4ecfb9dfe6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1320,10 +1320,6 @@ "id": "api.file.upload_file.storage.app_error", "translation": "Unable to upload file. Image storage is not configured." }, - { - "id": "api.file.upload_file.too_large.app_error", - "translation": "Unable to upload file. File is too large." - }, { "id": "api.file.upload_file.too_large_detailed.app_error", "translation": "Unable to upload file {{.Filename}}. {{.Length}} bytes exceeds the maximum allowed {{.Limit}} bytes." diff --git a/store/sqlstore/integrity_test.go b/store/sqlstore/integrity_test.go index 2f01ed3613..d511f32f83 100644 --- a/store/sqlstore/integrity_test.go +++ b/store/sqlstore/integrity_test.go @@ -86,10 +86,6 @@ func createChannelMemberWithChannelId(ss store.Store, id string) *model.ChannelM return createChannelMember(ss, id, model.NewId()) } -func createChannelMemberWithUserId(ss store.Store, id string) *model.ChannelMember { - return createChannelMember(ss, model.NewId(), id) -} - func createCommandWebhook(ss store.Store, commandId, userId, channelId string) *model.CommandWebhook { m := model.CommandWebhook{} m.CommandId = commandId diff --git a/store/sqlstore/upgrade.go b/store/sqlstore/upgrade.go index 4b216a4a7a..fe29f711e7 100644 --- a/store/sqlstore/upgrade.go +++ b/store/sqlstore/upgrade.go @@ -4,7 +4,6 @@ package sqlstore import ( - "database/sql" "encoding/json" "os" "strings" @@ -602,33 +601,6 @@ func UpgradeDatabaseToVersion57(sqlStore SqlStore) { } } -func getRole(sqlStore SqlStore, name string) (*model.Role, error) { - var dbRole Role - - if err := sqlStore.GetReplica().SelectOne(&dbRole, "SELECT * from Roles WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil { - if err == sql.ErrNoRows { - return nil, errors.Wrapf(err, "failed to find role %s", name) - } else { - return nil, errors.Wrapf(err, "failed to query role %s", name) - } - } - - return dbRole.ToModel(), nil -} - -func saveRole(sqlStore SqlStore, role *model.Role) error { - dbRole := NewRoleFromModel(role) - - dbRole.UpdateAt = model.GetMillis() - if rowsChanged, err := sqlStore.GetMaster().Update(dbRole); err != nil { - return errors.Wrap(err, "failed to update role") - } else if rowsChanged != 1 { - return errors.New("found no role to update") - } - - return nil -} - func UpgradeDatabaseToVersion58(sqlStore SqlStore) { if shouldPerformUpgrade(sqlStore, VERSION_5_7_0, VERSION_5_8_0) { // idx_channels_txt was removed in `UpgradeDatabaseToVersion50`, but merged as part of diff --git a/store/storetest/oauth_store.go b/store/storetest/oauth_store.go index c754a2c277..6d3298c718 100644 --- a/store/storetest/oauth_store.go +++ b/store/storetest/oauth_store.go @@ -213,7 +213,7 @@ func testOAuthStoreRemoveAccessData(t *testing.T, ss store.Store) { require.Nil(t, result, "did not delete access token") } -func testOAuthStoreRemoveAllAccessData(t *testing.T, ss store.Store) { +func TestOAuthStoreRemoveAllAccessData(t *testing.T, ss store.Store) { a1 := model.AccessData{} a1.ClientId = model.NewId() a1.UserId = model.NewId() diff --git a/store/storetest/webhook_store.go b/store/storetest/webhook_store.go index d9aff7048b..810a37224b 100644 --- a/store/storetest/webhook_store.go +++ b/store/storetest/webhook_store.go @@ -228,7 +228,7 @@ func TestWebhookStoreGetIncomingByTeamByUser(t *testing.T, ss store.Store) { }) } -func testWebhookStoreGetIncomingByChannel(t *testing.T, ss store.Store) { +func TestWebhookStoreGetIncomingByChannel(t *testing.T, ss store.Store) { o1 := buildIncomingWebhook() o1, err := ss.Webhook().SaveIncoming(o1) diff --git a/utils/test_files_compiler.go b/utils/test_files_compiler.go index b58ad98bd2..6bf6ad05f0 100644 --- a/utils/test_files_compiler.go +++ b/utils/test_files_compiler.go @@ -10,21 +10,11 @@ import ( "os/exec" "path/filepath" "runtime" - "strings" "testing" "github.com/stretchr/testify/require" ) -func goMod(t *testing.T, dir string, args ...string) { - cmd := exec.Command("go", append([]string{"mod"}, args...)...) - cmd.Dir = dir - output, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Failed to %s: %s", strings.Join(args, " "), string(output)) - } -} - func CompileGo(t *testing.T, sourceCode, outputPath string) { dir, err := ioutil.TempDir(".", "") require.NoError(t, err)