diff options
-rw-r--r-- | api/export.go | 6 | ||||
-rw-r--r-- | api/file.go | 64 | ||||
-rw-r--r-- | api/file_benchmark_test.go | 2 | ||||
-rw-r--r-- | api/file_test.go | 56 | ||||
-rw-r--r-- | api/user.go | 12 | ||||
-rw-r--r-- | api/user_test.go | 26 | ||||
-rw-r--r-- | config/config.json | 4 | ||||
-rw-r--r-- | docker/dev/config_docker.json | 2 | ||||
-rw-r--r-- | docker/local/config_docker.json | 2 | ||||
-rw-r--r-- | model/config.go | 4 | ||||
-rw-r--r-- | utils/config.go | 6 | ||||
-rw-r--r-- | web/react/components/admin_console/admin_controller.jsx | 4 | ||||
-rw-r--r-- | web/react/components/admin_console/admin_sidebar.jsx | 2 | ||||
-rw-r--r-- | web/react/components/admin_console/image_settings.jsx | 76 | ||||
-rw-r--r-- | web/react/components/signup_team.jsx | 2 |
15 files changed, 134 insertions, 134 deletions
diff --git a/api/export.go b/api/export.go index 6d7698282..73142a0e4 100644 --- a/api/export.go +++ b/api/export.go @@ -278,11 +278,11 @@ func copyDirToExportWriter(writer ExportWriter, inPath string, outPath string) * } func ExportLocalStorage(writer ExportWriter, options *ExportOptions, teamId string) *model.AppError { - teamDir := utils.Cfg.ImageSettings.Directory + "teams/" + teamId + teamDir := utils.Cfg.FileSettings.Directory + "teams/" + teamId - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { return model.NewAppError("ExportLocalStorage", "S3 is not supported for local storage export.", "") - } else if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { if err := copyDirToExportWriter(writer, teamDir, EXPORT_LOCAL_STORAGE_FOLDER); err != nil { return err } diff --git a/api/file.go b/api/file.go index acb18a7d4..694fc734c 100644 --- a/api/file.go +++ b/api/file.go @@ -69,7 +69,7 @@ func InitFile(r *mux.Router) { } func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewAppError("uploadFile", "Unable to upload file. Image storage is not configured.", "") c.Err.StatusCode = http.StatusNotImplemented return @@ -217,8 +217,8 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch // Create thumbnail go func() { - thumbWidth := float64(utils.Cfg.ImageSettings.ThumbnailWidth) - thumbHeight := float64(utils.Cfg.ImageSettings.ThumbnailHeight) + thumbWidth := float64(utils.Cfg.FileSettings.ThumbnailWidth) + thumbHeight := float64(utils.Cfg.FileSettings.ThumbnailHeight) imgWidth := float64(width) imgHeight := float64(height) @@ -226,9 +226,9 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch if imgHeight < thumbHeight && imgWidth < thumbWidth { thumbnail = img } else if imgHeight/imgWidth < thumbHeight/thumbWidth { - thumbnail = resize.Resize(0, utils.Cfg.ImageSettings.ThumbnailHeight, img, resize.Lanczos3) + thumbnail = resize.Resize(0, utils.Cfg.FileSettings.ThumbnailHeight, img, resize.Lanczos3) } else { - thumbnail = resize.Resize(utils.Cfg.ImageSettings.ThumbnailWidth, 0, img, resize.Lanczos3) + thumbnail = resize.Resize(utils.Cfg.FileSettings.ThumbnailWidth, 0, img, resize.Lanczos3) } buf := new(bytes.Buffer) @@ -247,8 +247,8 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch // Create preview go func() { var preview image.Image - if width > int(utils.Cfg.ImageSettings.PreviewWidth) { - preview = resize.Resize(utils.Cfg.ImageSettings.PreviewWidth, utils.Cfg.ImageSettings.PreviewHeight, img, resize.Lanczos3) + if width > int(utils.Cfg.FileSettings.PreviewWidth) { + preview = resize.Resize(utils.Cfg.FileSettings.PreviewWidth, utils.Cfg.FileSettings.PreviewHeight, img, resize.Lanczos3) } else { preview = img } @@ -294,7 +294,7 @@ type ImageGetResult struct { } func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewAppError("uploadFile", "Unable to get file info. Image storage is not configured.", "") c.Err.StatusCode = http.StatusNotImplemented return @@ -357,7 +357,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) { } func getFile(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewAppError("uploadFile", "Unable to get file. Image storage is not configured.", "") c.Err.StatusCode = http.StatusNotImplemented return @@ -400,7 +400,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) { asyncGetFile(path, fileData) if len(hash) > 0 && len(data) > 0 && len(teamId) == 26 { - if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt)) { + if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.FileSettings.PublicLinkSalt)) { c.Err = model.NewAppError("getFile", "The public link does not appear to be valid", "") return } @@ -442,13 +442,13 @@ func asyncGetFile(path string, fileData chan []byte) { } func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewAppError("uploadFile", "Unable to get link. Image storage is not configured.", "") c.Err.StatusCode = http.StatusNotImplemented return } - if !utils.Cfg.ImageSettings.EnablePublicLink { + if !utils.Cfg.FileSettings.EnablePublicLink { c.Err = model.NewAppError("getPublicLink", "Public links have been disabled", "") c.Err.StatusCode = http.StatusForbidden } @@ -478,7 +478,7 @@ func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) { newProps["time"] = fmt.Sprintf("%v", model.GetMillis()) data := model.MapToJson(newProps) - hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt)) + hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.FileSettings.PublicLinkSalt)) url := fmt.Sprintf("%s/api/v1/files/get/%s/%s/%s?d=%s&h=%s&t=%s", c.GetSiteURL(), channelId, userId, filename, url.QueryEscape(data), url.QueryEscape(hash), c.Session.TeamId) @@ -511,13 +511,13 @@ func getExport(c *Context, w http.ResponseWriter, r *http.Request) { func writeFile(f []byte, path string) *model.AppError { - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) ext := filepath.Ext(path) @@ -534,12 +534,12 @@ func writeFile(f []byte, path string) *model.AppError { if err != nil { return model.NewAppError("writeFile", "Encountered an error writing to S3", err.Error()) } - } else if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if err := os.MkdirAll(filepath.Dir(utils.Cfg.ImageSettings.Directory+path), 0774); err != nil { + } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + if err := os.MkdirAll(filepath.Dir(utils.Cfg.FileSettings.Directory+path), 0774); err != nil { return model.NewAppError("writeFile", "Encountered an error creating the directory for the new file", err.Error()) } - if err := ioutil.WriteFile(utils.Cfg.ImageSettings.Directory+path, f, 0644); err != nil { + if err := ioutil.WriteFile(utils.Cfg.FileSettings.Directory+path, f, 0644); err != nil { return model.NewAppError("writeFile", "Encountered an error writing to local server storage", err.Error()) } } else { @@ -551,13 +551,13 @@ func writeFile(f []byte, path string) *model.AppError { func readFile(path string) ([]byte, *model.AppError) { - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) // try to get the file from S3 with some basic retry logic tries := 0 @@ -573,8 +573,8 @@ func readFile(path string) ([]byte, *model.AppError) { } time.Sleep(3000 * time.Millisecond) } - } else if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if f, err := ioutil.ReadFile(utils.Cfg.ImageSettings.Directory + path); err != nil { + } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + if f, err := ioutil.ReadFile(utils.Cfg.FileSettings.Directory + path); err != nil { return nil, model.NewAppError("readFile", "Encountered an error reading from local server storage", err.Error()) } else { return f, nil @@ -585,14 +585,14 @@ func readFile(path string) ([]byte, *model.AppError) { } func openFileWriteStream(path string) (io.Writer, *model.AppError) { - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { return nil, model.NewAppError("openFileWriteStream", "S3 is not supported.", "") - } else if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if err := os.MkdirAll(filepath.Dir(utils.Cfg.ImageSettings.Directory+path), 0774); err != nil { + } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + if err := os.MkdirAll(filepath.Dir(utils.Cfg.FileSettings.Directory+path), 0774); err != nil { return nil, model.NewAppError("openFileWriteStream", "Encountered an error creating the directory for the new file", err.Error()) } - if fileHandle, err := os.Create(utils.Cfg.ImageSettings.Directory + path); err != nil { + if fileHandle, err := os.Create(utils.Cfg.FileSettings.Directory + path); err != nil { return nil, model.NewAppError("openFileWriteStream", "Encountered an error writing to local server storage", err.Error()) } else { fileHandle.Chmod(0644) diff --git a/api/file_benchmark_test.go b/api/file_benchmark_test.go index f7d5de1d9..47f8bff43 100644 --- a/api/file_benchmark_test.go +++ b/api/file_benchmark_test.go @@ -38,7 +38,7 @@ func BenchmarkGetFile(b *testing.B) { newProps["time"] = fmt.Sprintf("%v", model.GetMillis()) data := model.MapToJson(newProps) - hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt)) + hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.FileSettings.PublicLinkSalt)) // wait a bit for files to ready time.Sleep(5 * time.Second) diff --git a/api/file_test.go b/api/file_test.go index 072a3fab1..657c08131 100644 --- a/api/file_test.go +++ b/api/file_test.go @@ -68,7 +68,7 @@ func TestUploadFile(t *testing.T) { } resp, appErr := Client.UploadFile("/files/upload", body.Bytes(), writer.FormDataContentType()) - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { if appErr != nil { t.Fatal(appErr) } @@ -81,11 +81,11 @@ func TestUploadFile(t *testing.T) { fileId := strings.Split(filename, ".")[0] var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) // wait a bit for files to ready time.Sleep(5 * time.Second) @@ -104,7 +104,7 @@ func TestUploadFile(t *testing.T) { if err != nil { t.Fatal(err) } - } else if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_LOCAL { + } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { filenames := strings.Split(resp.Data.(*model.FileUploadResponse).Filenames[0], "/") filename := filenames[len(filenames)-2] + "/" + filenames[len(filenames)-1] if strings.Contains(filename, "../") { @@ -115,17 +115,17 @@ func TestUploadFile(t *testing.T) { // wait a bit for files to ready time.Sleep(5 * time.Second) - path := utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename + path := utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } @@ -151,7 +151,7 @@ func TestGetFile(t *testing.T) { channel1 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - if utils.Cfg.ImageSettings.DriverName != "" { + if utils.Cfg.FileSettings.DriverName != "" { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -222,7 +222,7 @@ func TestGetFile(t *testing.T) { newProps["time"] = fmt.Sprintf("%v", model.GetMillis()) data := model.MapToJson(newProps) - hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.ImageSettings.PublicLinkSalt)) + hash := model.HashPassword(fmt.Sprintf("%v:%v", data, utils.Cfg.FileSettings.PublicLinkSalt)) Client.LoginByEmail(team2.Name, user2.Email, "pwd") @@ -262,13 +262,13 @@ func TestGetFile(t *testing.T) { t.Fatal("Should have errored - user not logged in and link not public") } - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) filenames := strings.Split(resp.Data.(*model.FileUploadResponse).Filenames[0], "/") filename := filenames[len(filenames)-2] + "/" + filenames[len(filenames)-1] @@ -293,17 +293,17 @@ func TestGetFile(t *testing.T) { filename := filenames[len(filenames)-2] + "/" + filenames[len(filenames)-1] fileId := strings.Split(filename, ".")[0] - path := utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename + path := utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } @@ -334,7 +334,7 @@ func TestGetPublicLink(t *testing.T) { channel1 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) - if utils.Cfg.ImageSettings.DriverName != "" { + if utils.Cfg.FileSettings.DriverName != "" { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -410,14 +410,14 @@ func TestGetPublicLink(t *testing.T) { t.Fatal("should have errored, user not member of channel") } - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { // perform clean-up on s3 var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) filenames := strings.Split(resp.Data.(*model.FileUploadResponse).Filenames[0], "/") filename := filenames[len(filenames)-2] + "/" + filenames[len(filenames)-1] @@ -442,17 +442,17 @@ func TestGetPublicLink(t *testing.T) { filename := filenames[len(filenames)-2] + "/" + filenames[len(filenames)-1] fileId := strings.Split(filename, ".")[0] - path := utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename + path := utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + filename if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_thumb.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } - path = utils.Cfg.ImageSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" + path = utils.Cfg.FileSettings.Directory + "teams/" + team.Id + "/channels/" + channel1.Id + "/users/" + user1.Id + "/" + fileId + "_preview.jpg" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } diff --git a/api/user.go b/api/user.go index 5bb65e2ed..40410cc5b 100644 --- a/api/user.go +++ b/api/user.go @@ -646,7 +646,7 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError initial := string(strings.ToUpper(username)[0]) - fontBytes, err := ioutil.ReadFile(utils.FindDir("web/static/fonts") + utils.Cfg.ImageSettings.InitialFont) + fontBytes, err := ioutil.ReadFile(utils.FindDir("web/static/fonts") + utils.Cfg.FileSettings.InitialFont) if err != nil { return nil, model.NewAppError("createProfileImage", "Could not create default profile image font", err.Error()) } @@ -655,8 +655,8 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError return nil, model.NewAppError("createProfileImage", "Could not create default profile image font", err.Error()) } - width := int(utils.Cfg.ImageSettings.ProfileWidth) - height := int(utils.Cfg.ImageSettings.ProfileHeight) + width := int(utils.Cfg.FileSettings.ProfileWidth) + height := int(utils.Cfg.FileSettings.ProfileHeight) color := colors[int64(seed)%int64(len(colors))] dstImg := image.NewRGBA(image.Rect(0, 0, width, height)) srcImg := image.White @@ -695,7 +695,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } else { var img []byte - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { var err *model.AppError if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil { c.Err = err @@ -732,7 +732,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { - if len(utils.Cfg.ImageSettings.DriverName) == 0 { + if len(utils.Cfg.FileSettings.DriverName) == 0 { c.Err = model.NewAppError("uploadProfileImage", "Unable to upload file. Image storage is not configured.", "") c.Err.StatusCode = http.StatusNotImplemented return @@ -775,7 +775,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } // Scale profile image - img = resize.Resize(utils.Cfg.ImageSettings.ProfileWidth, utils.Cfg.ImageSettings.ProfileHeight, img, resize.Lanczos3) + img = resize.Resize(utils.Cfg.FileSettings.ProfileWidth, utils.Cfg.FileSettings.ProfileHeight, img, resize.Lanczos3) buf := new(bytes.Buffer) err = png.Encode(buf, img) diff --git a/api/user_test.go b/api/user_test.go index 34eefce59..669da4d20 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -352,19 +352,19 @@ func TestUserCreateImage(t *testing.T) { Client.DoApiGet("/users/"+user.Id+"/image", "", "") - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) if err := bucket.Del("teams/" + user.TeamId + "/users/" + user.Id + "/profile.png"); err != nil { t.Fatal(err) } } else { - path := utils.Cfg.ImageSettings.Directory + "teams/" + user.TeamId + "/users/" + user.Id + "/profile.png" + path := utils.Cfg.FileSettings.Directory + "teams/" + user.TeamId + "/users/" + user.Id + "/profile.png" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } @@ -382,7 +382,7 @@ func TestUserUploadProfileImage(t *testing.T) { user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) - if utils.Cfg.ImageSettings.DriverName != "" { + if utils.Cfg.FileSettings.DriverName != "" { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -450,19 +450,19 @@ func TestUserUploadProfileImage(t *testing.T) { Client.DoApiGet("/users/"+user.Id+"/image", "", "") - if utils.Cfg.ImageSettings.DriverName == model.IMAGE_DRIVER_S3 { + if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth - auth.AccessKey = utils.Cfg.ImageSettings.AmazonS3AccessKeyId - auth.SecretKey = utils.Cfg.ImageSettings.AmazonS3SecretAccessKey + auth.AccessKey = utils.Cfg.FileSettings.AmazonS3AccessKeyId + auth.SecretKey = utils.Cfg.FileSettings.AmazonS3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.ImageSettings.AmazonS3Region]) - bucket := s.Bucket(utils.Cfg.ImageSettings.AmazonS3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.FileSettings.AmazonS3Region]) + bucket := s.Bucket(utils.Cfg.FileSettings.AmazonS3Bucket) if err := bucket.Del("teams/" + user.TeamId + "/users/" + user.Id + "/profile.png"); err != nil { t.Fatal(err) } } else { - path := utils.Cfg.ImageSettings.Directory + "teams/" + user.TeamId + "/users/" + user.Id + "/profile.png" + path := utils.Cfg.FileSettings.Directory + "teams/" + user.TeamId + "/users/" + user.Id + "/profile.png" if err := os.Remove(path); err != nil { t.Fatal("Couldn't remove file at " + path) } diff --git a/config/config.json b/config/config.json index c0f33a346..aa92ccf4e 100644 --- a/config/config.json +++ b/config/config.json @@ -33,11 +33,11 @@ "FileFormat": "", "FileLocation": "" }, - "ImageSettings": { + "FileSettings": { "DriverName": "local", "Directory": "./data/", "EnablePublicLink": true, - "PublicLinkSalt": "LhaAWC6lYEKHTkBKsvyXNIOfUIT37AXe", + "PublicLinkSalt": "A705AklYF8MFDOfcwh3I488G8vtLlVip", "ThumbnailWidth": 120, "ThumbnailHeight": 100, "PreviewWidth": 1024, diff --git a/docker/dev/config_docker.json b/docker/dev/config_docker.json index e33396214..16a4007fa 100644 --- a/docker/dev/config_docker.json +++ b/docker/dev/config_docker.json @@ -33,7 +33,7 @@ "FileFormat": "", "FileLocation": "" }, - "ImageSettings": { + "FileSettings": { "DriverName": "local", "Directory": "/mattermost/data/", "EnablePublicLink": true, diff --git a/docker/local/config_docker.json b/docker/local/config_docker.json index e33396214..16a4007fa 100644 --- a/docker/local/config_docker.json +++ b/docker/local/config_docker.json @@ -33,7 +33,7 @@ "FileFormat": "", "FileLocation": "" }, - "ImageSettings": { + "FileSettings": { "DriverName": "local", "Directory": "/mattermost/data/", "EnablePublicLink": true, diff --git a/model/config.go b/model/config.go index 1e95277a2..69f2127b2 100644 --- a/model/config.go +++ b/model/config.go @@ -58,7 +58,7 @@ type LogSettings struct { FileLocation string } -type ImageSettings struct { +type FileSettings struct { DriverName string Directory string EnablePublicLink bool @@ -123,7 +123,7 @@ type Config struct { TeamSettings TeamSettings SqlSettings SqlSettings LogSettings LogSettings - ImageSettings ImageSettings + FileSettings FileSettings EmailSettings EmailSettings RateLimitSettings RateLimitSettings PrivacySettings PrivacySettings diff --git a/utils/config.go b/utils/config.go index c42d5c9df..5d786699b 100644 --- a/utils/config.go +++ b/utils/config.go @@ -188,9 +188,9 @@ func getClientProperties(c *model.Config) map[string]string { props["ShowEmailAddress"] = strconv.FormatBool(c.PrivacySettings.ShowEmailAddress) - props["EnablePublicLink"] = strconv.FormatBool(c.ImageSettings.EnablePublicLink) - props["ProfileHeight"] = fmt.Sprintf("%v", c.ImageSettings.ProfileHeight) - props["ProfileWidth"] = fmt.Sprintf("%v", c.ImageSettings.ProfileWidth) + props["EnablePublicLink"] = strconv.FormatBool(c.FileSettings.EnablePublicLink) + props["ProfileHeight"] = fmt.Sprintf("%v", c.FileSettings.ProfileHeight) + props["ProfileWidth"] = fmt.Sprintf("%v", c.FileSettings.ProfileWidth) return props } diff --git a/web/react/components/admin_console/admin_controller.jsx b/web/react/components/admin_console/admin_controller.jsx index ce7d61ca9..6fddfef07 100644 --- a/web/react/components/admin_console/admin_controller.jsx +++ b/web/react/components/admin_console/admin_controller.jsx @@ -9,7 +9,7 @@ var LoadingScreen = require('../loading_screen.jsx'); var EmailSettingsTab = require('./email_settings.jsx'); var LogSettingsTab = require('./log_settings.jsx'); var LogsTab = require('./logs.jsx'); -var ImageSettingsTab = require('./image_settings.jsx'); +var FileSettingsTab = require('./image_settings.jsx'); var PrivacySettingsTab = require('./privacy_settings.jsx'); var RateSettingsTab = require('./rate_settings.jsx'); var GitLabSettingsTab = require('./gitlab_settings.jsx'); @@ -61,7 +61,7 @@ export default class AdminController extends React.Component { } else if (this.state.selected === 'logs') { tab = <LogsTab />; } else if (this.state.selected === 'image_settings') { - tab = <ImageSettingsTab config={this.state.config} />; + tab = <FileSettingsTab config={this.state.config} />; } else if (this.state.selected === 'privacy_settings') { tab = <PrivacySettingsTab config={this.state.config} />; } else if (this.state.selected === 'rate_settings') { diff --git a/web/react/components/admin_console/admin_sidebar.jsx b/web/react/components/admin_console/admin_sidebar.jsx index 0983c1276..17ce39c7c 100644 --- a/web/react/components/admin_console/admin_sidebar.jsx +++ b/web/react/components/admin_console/admin_sidebar.jsx @@ -80,7 +80,7 @@ export default class AdminSidebar extends React.Component { className={this.isSelected('image_settings')} onClick={this.handleClick.bind(this, 'image_settings')} > - {'Image Settings'} + {'File Settings'} </a> </li> <li> diff --git a/web/react/components/admin_console/image_settings.jsx b/web/react/components/admin_console/image_settings.jsx index f84f1c735..25d5ad857 100644 --- a/web/react/components/admin_console/image_settings.jsx +++ b/web/react/components/admin_console/image_settings.jsx @@ -5,7 +5,7 @@ var Client = require('../../utils/client.jsx'); var AsyncClient = require('../../utils/async_client.jsx'); var crypto = require('crypto'); -export default class ImageSettings extends React.Component { +export default class FileSettings extends React.Component { constructor(props) { super(props); @@ -16,7 +16,7 @@ export default class ImageSettings extends React.Component { this.state = { saveNeeded: false, serverError: null, - DriverName: this.props.config.ImageSettings.DriverName + DriverName: this.props.config.FileSettings.DriverName }; } @@ -42,61 +42,61 @@ export default class ImageSettings extends React.Component { $('#save-button').button('loading'); var config = this.props.config; - config.ImageSettings.DriverName = React.findDOMNode(this.refs.DriverName).value; - config.ImageSettings.Directory = React.findDOMNode(this.refs.Directory).value; - config.ImageSettings.AmazonS3AccessKeyId = React.findDOMNode(this.refs.AmazonS3AccessKeyId).value; - config.ImageSettings.AmazonS3SecretAccessKey = React.findDOMNode(this.refs.AmazonS3SecretAccessKey).value; - config.ImageSettings.AmazonS3Bucket = React.findDOMNode(this.refs.AmazonS3Bucket).value; - config.ImageSettings.AmazonS3Region = React.findDOMNode(this.refs.AmazonS3Region).value; - config.ImageSettings.EnablePublicLink = React.findDOMNode(this.refs.EnablePublicLink).checked; - - config.ImageSettings.PublicLinkSalt = React.findDOMNode(this.refs.PublicLinkSalt).value.trim(); - - if (config.ImageSettings.PublicLinkSalt === '') { - config.ImageSettings.PublicLinkSalt = crypto.randomBytes(256).toString('base64').substring(0, 32); - React.findDOMNode(this.refs.PublicLinkSalt).value = config.ImageSettings.PublicLinkSalt; + config.FileSettings.DriverName = React.findDOMNode(this.refs.DriverName).value; + config.FileSettings.Directory = React.findDOMNode(this.refs.Directory).value; + config.FileSettings.AmazonS3AccessKeyId = React.findDOMNode(this.refs.AmazonS3AccessKeyId).value; + config.FileSettings.AmazonS3SecretAccessKey = React.findDOMNode(this.refs.AmazonS3SecretAccessKey).value; + config.FileSettings.AmazonS3Bucket = React.findDOMNode(this.refs.AmazonS3Bucket).value; + config.FileSettings.AmazonS3Region = React.findDOMNode(this.refs.AmazonS3Region).value; + config.FileSettings.EnablePublicLink = React.findDOMNode(this.refs.EnablePublicLink).checked; + + config.FileSettings.PublicLinkSalt = React.findDOMNode(this.refs.PublicLinkSalt).value.trim(); + + if (config.FileSettings.PublicLinkSalt === '') { + config.FileSettings.PublicLinkSalt = crypto.randomBytes(256).toString('base64').substring(0, 32); + React.findDOMNode(this.refs.PublicLinkSalt).value = config.FileSettings.PublicLinkSalt; } var thumbnailWidth = 120; if (!isNaN(parseInt(React.findDOMNode(this.refs.ThumbnailWidth).value, 10))) { thumbnailWidth = parseInt(React.findDOMNode(this.refs.ThumbnailWidth).value, 10); } - config.ImageSettings.ThumbnailWidth = thumbnailWidth; + config.FileSettings.ThumbnailWidth = thumbnailWidth; React.findDOMNode(this.refs.ThumbnailWidth).value = thumbnailWidth; var thumbnailHeight = 100; if (!isNaN(parseInt(React.findDOMNode(this.refs.ThumbnailHeight).value, 10))) { thumbnailHeight = parseInt(React.findDOMNode(this.refs.ThumbnailHeight).value, 10); } - config.ImageSettings.ThumbnailHeight = thumbnailHeight; + config.FileSettings.ThumbnailHeight = thumbnailHeight; React.findDOMNode(this.refs.ThumbnailHeight).value = thumbnailHeight; var previewWidth = 1024; if (!isNaN(parseInt(React.findDOMNode(this.refs.PreviewWidth).value, 10))) { previewWidth = parseInt(React.findDOMNode(this.refs.PreviewWidth).value, 10); } - config.ImageSettings.PreviewWidth = previewWidth; + config.FileSettings.PreviewWidth = previewWidth; React.findDOMNode(this.refs.PreviewWidth).value = previewWidth; var previewHeight = 0; if (!isNaN(parseInt(React.findDOMNode(this.refs.PreviewHeight).value, 10))) { previewHeight = parseInt(React.findDOMNode(this.refs.PreviewHeight).value, 10); } - config.ImageSettings.PreviewHeight = previewHeight; + config.FileSettings.PreviewHeight = previewHeight; React.findDOMNode(this.refs.PreviewHeight).value = previewHeight; var profileWidth = 128; if (!isNaN(parseInt(React.findDOMNode(this.refs.ProfileWidth).value, 10))) { profileWidth = parseInt(React.findDOMNode(this.refs.ProfileWidth).value, 10); } - config.ImageSettings.ProfileWidth = profileWidth; + config.FileSettings.ProfileWidth = profileWidth; React.findDOMNode(this.refs.ProfileWidth).value = profileWidth; var profileHeight = 128; if (!isNaN(parseInt(React.findDOMNode(this.refs.ProfileHeight).value, 10))) { profileHeight = parseInt(React.findDOMNode(this.refs.ProfileHeight).value, 10); } - config.ImageSettings.ProfileHeight = profileHeight; + config.FileSettings.ProfileHeight = profileHeight; React.findDOMNode(this.refs.ProfileHeight).value = profileHeight; Client.saveConfig( @@ -143,7 +143,7 @@ export default class ImageSettings extends React.Component { return ( <div className='wrapper--fixed'> - <h3>{'Image Settings'}</h3> + <h3>{'File Settings'}</h3> <form className='form-horizontal' role='form' @@ -161,7 +161,7 @@ export default class ImageSettings extends React.Component { className='form-control' id='DriverName' ref='DriverName' - defaultValue={this.props.config.ImageSettings.DriverName} + defaultValue={this.props.config.FileSettings.DriverName} onChange={this.handleChange.bind(this, 'DriverName')} > <option value=''>{'Disable File Storage'}</option> @@ -185,7 +185,7 @@ export default class ImageSettings extends React.Component { id='Directory' ref='Directory' placeholder='Ex "./data/"' - defaultValue={this.props.config.ImageSettings.Directory} + defaultValue={this.props.config.FileSettings.Directory} onChange={this.handleChange} disabled={!enableFile} /> @@ -207,7 +207,7 @@ export default class ImageSettings extends React.Component { id='AmazonS3AccessKeyId' ref='AmazonS3AccessKeyId' placeholder='Ex "AKIADTOVBGERKLCBV"' - defaultValue={this.props.config.ImageSettings.AmazonS3AccessKeyId} + defaultValue={this.props.config.FileSettings.AmazonS3AccessKeyId} onChange={this.handleChange} disabled={!enableS3} /> @@ -229,7 +229,7 @@ export default class ImageSettings extends React.Component { id='AmazonS3SecretAccessKey' ref='AmazonS3SecretAccessKey' placeholder='Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"' - defaultValue={this.props.config.ImageSettings.AmazonS3SecretAccessKey} + defaultValue={this.props.config.FileSettings.AmazonS3SecretAccessKey} onChange={this.handleChange} disabled={!enableS3} /> @@ -251,7 +251,7 @@ export default class ImageSettings extends React.Component { id='AmazonS3Bucket' ref='AmazonS3Bucket' placeholder='Ex "mattermost-media"' - defaultValue={this.props.config.ImageSettings.AmazonS3Bucket} + defaultValue={this.props.config.FileSettings.AmazonS3Bucket} onChange={this.handleChange} disabled={!enableS3} /> @@ -273,7 +273,7 @@ export default class ImageSettings extends React.Component { id='AmazonS3Region' ref='AmazonS3Region' placeholder='Ex "us-east-1"' - defaultValue={this.props.config.ImageSettings.AmazonS3Region} + defaultValue={this.props.config.FileSettings.AmazonS3Region} onChange={this.handleChange} disabled={!enableS3} /> @@ -295,7 +295,7 @@ export default class ImageSettings extends React.Component { id='ThumbnailWidth' ref='ThumbnailWidth' placeholder='Ex "120"' - defaultValue={this.props.config.ImageSettings.ThumbnailWidth} + defaultValue={this.props.config.FileSettings.ThumbnailWidth} onChange={this.handleChange} /> <p className='help-text'>{'Width of thumbnails generated from uploaded images. Updating this value changes how thumbnail images render in future, but does not change images created in the past.'}</p> @@ -316,7 +316,7 @@ export default class ImageSettings extends React.Component { id='ThumbnailHeight' ref='ThumbnailHeight' placeholder='Ex "100"' - defaultValue={this.props.config.ImageSettings.ThumbnailHeight} + defaultValue={this.props.config.FileSettings.ThumbnailHeight} onChange={this.handleChange} /> <p className='help-text'>{'Height of thumbnails generated from uploaded images. Updating this value changes how thumbnail images render in future, but does not change images created in the past.'}</p> @@ -337,7 +337,7 @@ export default class ImageSettings extends React.Component { id='PreviewWidth' ref='PreviewWidth' placeholder='Ex "1024"' - defaultValue={this.props.config.ImageSettings.PreviewWidth} + defaultValue={this.props.config.FileSettings.PreviewWidth} onChange={this.handleChange} /> <p className='help-text'>{'Maximum width of preview image. Updating this value changes how preview images render in future, but does not change images created in the past.'}</p> @@ -358,7 +358,7 @@ export default class ImageSettings extends React.Component { id='PreviewHeight' ref='PreviewHeight' placeholder='Ex "0"' - defaultValue={this.props.config.ImageSettings.PreviewHeight} + defaultValue={this.props.config.FileSettings.PreviewHeight} onChange={this.handleChange} /> <p className='help-text'>{'Maximum height of preview image ("0": Sets to auto-size). Updating this value changes how preview images render in future, but does not change images created in the past.'}</p> @@ -379,7 +379,7 @@ export default class ImageSettings extends React.Component { id='ProfileWidth' ref='ProfileWidth' placeholder='Ex "1024"' - defaultValue={this.props.config.ImageSettings.ProfileWidth} + defaultValue={this.props.config.FileSettings.ProfileWidth} onChange={this.handleChange} /> <p className='help-text'>{'Width of profile picture.'}</p> @@ -400,7 +400,7 @@ export default class ImageSettings extends React.Component { id='ProfileHeight' ref='ProfileHeight' placeholder='Ex "0"' - defaultValue={this.props.config.ImageSettings.ProfileHeight} + defaultValue={this.props.config.FileSettings.ProfileHeight} onChange={this.handleChange} /> <p className='help-text'>{'Height of profile picture.'}</p> @@ -421,7 +421,7 @@ export default class ImageSettings extends React.Component { name='EnablePublicLink' value='true' ref='EnablePublicLink' - defaultChecked={this.props.config.ImageSettings.EnablePublicLink} + defaultChecked={this.props.config.FileSettings.EnablePublicLink} onChange={this.handleChange} /> {'true'} @@ -431,7 +431,7 @@ export default class ImageSettings extends React.Component { type='radio' name='EnablePublicLink' value='false' - defaultChecked={!this.props.config.ImageSettings.EnablePublicLink} + defaultChecked={!this.props.config.FileSettings.EnablePublicLink} onChange={this.handleChange} /> {'false'} @@ -454,7 +454,7 @@ export default class ImageSettings extends React.Component { id='PublicLinkSalt' ref='PublicLinkSalt' placeholder='Ex "gxHVDcKUyP2y1eiyW8S8na1UYQAfq6J6"' - defaultValue={this.props.config.ImageSettings.PublicLinkSalt} + defaultValue={this.props.config.FileSettings.PublicLinkSalt} onChange={this.handleChange} /> <p className='help-text'>{'32-character salt added to signing of public image links.'}</p> @@ -491,6 +491,6 @@ export default class ImageSettings extends React.Component { } } -ImageSettings.propTypes = { +FileSettings.propTypes = { config: React.PropTypes.object }; diff --git a/web/react/components/signup_team.jsx b/web/react/components/signup_team.jsx index 7f320e0b2..4112138fa 100644 --- a/web/react/components/signup_team.jsx +++ b/web/react/components/signup_team.jsx @@ -4,7 +4,7 @@ const ChoosePage = require('./team_signup_choose_auth.jsx'); const EmailSignUpPage = require('./team_signup_with_email.jsx'); const SSOSignupPage = require('./team_signup_with_sso.jsx'); -var Constants = require('../utils/constants.jsx'); +const Constants = require('../utils/constants.jsx'); export default class TeamSignUp extends React.Component { constructor(props) { |