diff --git a/api/admin.go b/api/admin.go index 7b041619e28..3ed2bee7af7 100644 --- a/api/admin.go +++ b/api/admin.go @@ -35,6 +35,8 @@ func InitAdmin(r *mux.Router) { sr.Handle("/save_compliance_report", ApiUserRequired(saveComplianceReport)).Methods("POST") sr.Handle("/compliance_reports", ApiUserRequired(getComplianceReports)).Methods("GET") sr.Handle("/download_compliance_report/{id:[A-Za-z0-9]+}", ApiUserRequired(downloadComplianceReport)).Methods("GET") + sr.Handle("/upload_brand_image", ApiAdminSystemRequired(uploadBrandImage)).Methods("POST") + sr.Handle("/get_brand_image", ApiAppHandlerTrustRequester(getBrandImage)).Methods("GET") } func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { @@ -422,3 +424,77 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) { } } + +func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { + if len(utils.Cfg.FileSettings.DriverName) == 0 { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "") + c.Err.StatusCode = http.StatusNotImplemented + return + } + + if r.ContentLength > model.MAX_FILE_SIZE { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "") + c.Err.StatusCode = http.StatusRequestEntityTooLarge + return + } + + if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.parse.app_error", nil, "") + return + } + + m := r.MultipartForm + + imageArray, ok := m.File["image"] + if !ok { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.no_file.app_error", nil, "") + c.Err.StatusCode = http.StatusBadRequest + return + } + + if len(imageArray) <= 0 { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.array.app_error", nil, "") + c.Err.StatusCode = http.StatusBadRequest + return + } + + brandInterface := einterfaces.GetBrandInterface() + if brandInterface == nil { + c.Err = model.NewLocAppError("uploadBrandImage", "api.admin.upload_brand_image.not_available.app_error", nil, "") + c.Err.StatusCode = http.StatusNotImplemented + return + } + + if err := brandInterface.SaveBrandImage(imageArray[0]); err != nil { + c.Err = err + return + } + + c.LogAudit("") + + rdata := map[string]string{} + rdata["status"] = "OK" + w.Write([]byte(model.MapToJson(rdata))) +} + +func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) { + if len(utils.Cfg.FileSettings.DriverName) == 0 { + c.Err = model.NewLocAppError("getBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "") + c.Err.StatusCode = http.StatusNotImplemented + return + } + + brandInterface := einterfaces.GetBrandInterface() + if brandInterface == nil { + c.Err = model.NewLocAppError("getBrandImage", "api.admin.get_brand_image.not_available.app_error", nil, "") + c.Err.StatusCode = http.StatusNotImplemented + return + } + + if img, err := brandInterface.GetBrandImage(); err != nil { + w.Write(nil) + } else { + w.Header().Set("Content-Type", "image/png") + w.Write(img) + } +} diff --git a/api/file.go b/api/file.go index ee9703455a2..991516bed53 100644 --- a/api/file.go +++ b/api/file.go @@ -149,7 +149,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) { path := "teams/" + c.Session.TeamId + "/channels/" + channelId + "/users/" + c.Session.UserId + "/" + uid + "/" + filename - if err := writeFile(buf.Bytes(), path); err != nil { + if err := WriteFile(buf.Bytes(), path); err != nil { c.Err = err return } @@ -237,7 +237,7 @@ func handleImagesAndForget(filenames []string, fileData [][]byte, teamId, channe return } - if err := writeFile(buf.Bytes(), dest+name+"_thumb.jpg"); err != nil { + if err := WriteFile(buf.Bytes(), dest+name+"_thumb.jpg"); err != nil { l4g.Error(utils.T("api.file.handle_images_forget.upload_thumb.error"), channelId, userId, filename, err) return } @@ -260,7 +260,7 @@ func handleImagesAndForget(filenames []string, fileData [][]byte, teamId, channe return } - if err := writeFile(buf.Bytes(), dest+name+"_preview.jpg"); err != nil { + if err := WriteFile(buf.Bytes(), dest+name+"_preview.jpg"); err != nil { l4g.Error(utils.T("api.file.handle_images_forget.upload_preview.error"), channelId, userId, filename, err) return } @@ -440,7 +440,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) { func getFileAndForget(path string, fileData chan []byte) { go func() { - data, getErr := readFile(path) + data, getErr := ReadFile(path) if getErr != nil { l4g.Error(getErr) fileData <- nil @@ -506,7 +506,7 @@ func getExport(c *Context, w http.ResponseWriter, r *http.Request) { c.Err.StatusCode = http.StatusForbidden return } - data, err := readFile(EXPORT_PATH + EXPORT_FILENAME) + data, err := ReadFile(EXPORT_PATH + EXPORT_FILENAME) if err != nil { c.Err = model.NewLocAppError("getExport", "api.file.get_export.retrieve.app_error", nil, err.Error()) return @@ -517,7 +517,7 @@ func getExport(c *Context, w http.ResponseWriter, r *http.Request) { w.Write(data) } -func writeFile(f []byte, path string) *model.AppError { +func WriteFile(f []byte, path string) *model.AppError { if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth @@ -540,14 +540,14 @@ func writeFile(f []byte, path string) *model.AppError { } if err != nil { - return model.NewLocAppError("writeFile", "api.file.write_file.s3.app_error", nil, err.Error()) + return model.NewLocAppError("WriteFile", "api.file.write_file.s3.app_error", nil, err.Error()) } } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { - if err := writeFileLocally(f, utils.Cfg.FileSettings.Directory+path); err != nil { + if err := WriteFileLocally(f, utils.Cfg.FileSettings.Directory+path); err != nil { return err } } else { - return model.NewLocAppError("writeFile", "api.file.write_file.configured.app_error", nil, "") + return model.NewLocAppError("WriteFile", "api.file.write_file.configured.app_error", nil, "") } return nil @@ -574,7 +574,7 @@ func moveFile(oldPath, newPath string) *model.AppError { return model.NewLocAppError("moveFile", "api.file.move_file.delete_from_s3.app_error", nil, err.Error()) } - if err := writeFile(fileBytes, newPath); err != nil { + if err := WriteFile(fileBytes, newPath); err != nil { return err } } else if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_LOCAL { @@ -588,19 +588,19 @@ func moveFile(oldPath, newPath string) *model.AppError { return nil } -func writeFileLocally(f []byte, path string) *model.AppError { +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()) + return model.NewLocAppError("WriteFile", "api.file.write_file_locally.create_dir.app_error", nil, err.Error()) } if err := ioutil.WriteFile(path, f, 0644); err != nil { - return model.NewLocAppError("writeFile", "api.file.write_file_locally.writing.app_error", nil, err.Error()) + return model.NewLocAppError("WriteFile", "api.file.write_file_locally.writing.app_error", nil, err.Error()) } return nil } -func readFile(path string) ([]byte, *model.AppError) { +func ReadFile(path string) ([]byte, *model.AppError) { if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 { var auth aws.Auth @@ -620,18 +620,18 @@ func readFile(path string) ([]byte, *model.AppError) { if f != nil { return f, nil } else if tries >= 3 { - return nil, model.NewLocAppError("readFile", "api.file.read_file.get.app_error", nil, "path="+path+", err="+err.Error()) + return nil, model.NewLocAppError("ReadFile", "api.file.read_file.get.app_error", nil, "path="+path+", err="+err.Error()) } time.Sleep(3000 * time.Millisecond) } } 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.NewLocAppError("readFile", "api.file.read_file.reading_local.app_error", nil, err.Error()) + return nil, model.NewLocAppError("ReadFile", "api.file.read_file.reading_local.app_error", nil, err.Error()) } else { return f, nil } } else { - return nil, model.NewLocAppError("readFile", "api.file.read_file.configured.app_error", nil, "") + return nil, model.NewLocAppError("ReadFile", "api.file.read_file.configured.app_error", nil, "") } } diff --git a/api/user.go b/api/user.go index 76eeaa44177..08d096c512d 100644 --- a/api/user.go +++ b/api/user.go @@ -54,7 +54,7 @@ func InitUser(r *mux.Router) { sr.Handle("/verify_email", ApiAppHandler(verifyEmail)).Methods("POST") sr.Handle("/resend_verification", ApiAppHandler(resendVerification)).Methods("POST") sr.Handle("/mfa", ApiAppHandler(checkMfa)).Methods("POST") - sr.Handle("/generate_mfa_qr", ApiUserRequired(generateMfaQrCode)).Methods("GET") + sr.Handle("/generate_mfa_qr", ApiUserRequiredTrustRequester(generateMfaQrCode)).Methods("GET") sr.Handle("/update_mfa", ApiUserRequired(updateMfa)).Methods("POST") sr.Handle("/newimage", ApiUserRequired(uploadProfileImage)).Methods("POST") @@ -1150,14 +1150,14 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { } else { path := "teams/" + c.Session.TeamId + "/users/" + id + "/profile.png" - if data, err := readFile(path); err != nil { + if data, err := ReadFile(path); err != nil { if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil { c.Err = err return } - if err := writeFile(img, path); err != nil { + if err := WriteFile(img, path); err != nil { c.Err = err return } @@ -1185,7 +1185,13 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { return } - if err := r.ParseMultipartForm(10000000); err != nil { + if r.ContentLength > model.MAX_FILE_SIZE { + c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "") + c.Err.StatusCode = http.StatusRequestEntityTooLarge + return + } + + if err := r.ParseMultipartForm(model.MAX_FILE_SIZE); err != nil { c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "") return } @@ -1245,7 +1251,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { path := "teams/" + c.Session.TeamId + "/users/" + c.Session.UserId + "/profile.png" - if err := writeFile(buf.Bytes(), path); err != nil { + if err := WriteFile(buf.Bytes(), path); err != nil { c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, "") return } diff --git a/config/config.json b/config/config.json index 11627df7071..5b05158b59b 100644 --- a/config/config.json +++ b/config/config.json @@ -32,7 +32,9 @@ "EnableUserCreation": true, "RestrictCreationToDomains": "", "RestrictTeamNames": true, - "EnableTeamListing": false + "EnableTeamListing": false, + "EnableCustomBrand": false, + "CustomBrandText": "" }, "SqlSettings": { "DriverName": "mysql", diff --git a/einterfaces/brand.go b/einterfaces/brand.go new file mode 100644 index 00000000000..7c15659bbc1 --- /dev/null +++ b/einterfaces/brand.go @@ -0,0 +1,24 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package einterfaces + +import ( + "github.com/mattermost/platform/model" + "mime/multipart" +) + +type BrandInterface interface { + SaveBrandImage(*multipart.FileHeader) *model.AppError + GetBrandImage() ([]byte, *model.AppError) +} + +var theBrandInterface BrandInterface + +func RegisterBrandInterface(newInterface BrandInterface) { + theBrandInterface = newInterface +} + +func GetBrandInterface() BrandInterface { + return theBrandInterface +} diff --git a/i18n/en.json b/i18n/en.json index c730f57117c..27f9a680a44 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -47,6 +47,66 @@ "id": "September", "translation": "September" }, + { + "id": "api.admin.upload_brand_image.storage.app_error", + "translation": "Unable to upload image. Image storage is not configured." + }, + { + "id": "api.admin.upload_brand_image.too_large.app_error", + "translation": "Unable to upload file. File is too large." + }, + { + "id": "api.admin.upload_brand_image.parse.app_error", + "translation": "Could not parse multipart form" + }, + { + "id": "api.admin.upload_brand_image.no_file.app_error", + "translation": "No file under 'image' in request" + }, + { + "id": "api.admin.upload_brand_image.array.app_error", + "translation": "Empty array under 'image' in request" + }, + { + "id": "api.admin.upload_brand_image.not_available.app_error", + "translation": "Custom branding is not configured or supported on this server" + }, + { + "id": "api.admin.get_brand_image.storage.app_error", + "translation": "Image storage is not configured." + }, + { + "id": "api.admin.get_brand_image.not_available.app_error", + "translation": "Custom branding is not configured or supported on this server" + }, + { + "id": "store.sql_system.get_by_name.app_error", + "translation": "We couldn't find the system variable." + }, + { + "id": "ent.brand.save_brand_image.open.app_error", + "translation": "Unable to open the image." + }, + { + "id": "ent.brand.save_brand_image.decode_config.app_error", + "translation": "Unable to decode image config." + }, + { + "id": "ent.brand.save_brand_image.too_large.app_error", + "translation": "Unable to open image. Image is too large." + }, + { + "id": "ent.brand.save_brand_image.decode.app_error", + "translation": "Unable to decode image." + }, + { + "id": "ent.brand.save_brand_image.encode.app_error", + "translation": "Unable to encode image as PNG." + }, + { + "id": "ent.brand.save_brand_image.save_image.app_error", + "translation": "Unable to save image" + }, { "id": "api.admin.file_read_error", "translation": "Error reading log file" diff --git a/model/config.go b/model/config.go index a8974359d2b..26c71d07f1e 100644 --- a/model/config.go +++ b/model/config.go @@ -158,6 +158,8 @@ type TeamSettings struct { RestrictCreationToDomains string RestrictTeamNames *bool EnableTeamListing *bool + EnableCustomBrand *bool + CustomBrandText *string } type LdapSettings struct { @@ -296,6 +298,16 @@ func (o *Config) SetDefaults() { *o.TeamSettings.EnableTeamListing = false } + if o.TeamSettings.EnableCustomBrand == nil { + o.TeamSettings.EnableCustomBrand = new(bool) + *o.TeamSettings.EnableCustomBrand = false + } + + if o.TeamSettings.CustomBrandText == nil { + o.TeamSettings.CustomBrandText = new(string) + *o.TeamSettings.CustomBrandText = "" + } + if o.EmailSettings.EnableSignInWithEmail == nil { o.EmailSettings.EnableSignInWithEmail = new(bool) diff --git a/model/license.go b/model/license.go index cab22a68579..0cea67c3d1e 100644 --- a/model/license.go +++ b/model/license.go @@ -32,11 +32,12 @@ type Customer struct { } type Features struct { - Users *int `json:"users"` - LDAP *bool `json:"ldap"` - MFA *bool `json:"mfa"` - GoogleSSO *bool `json:"google_sso"` - Compliance *bool `json:"compliance"` + Users *int `json:"users"` + LDAP *bool `json:"ldap"` + MFA *bool `json:"mfa"` + GoogleSSO *bool `json:"google_sso"` + Compliance *bool `json:"compliance"` + CustomBrand *bool `json:"custom_brand"` } func (f *Features) SetDefaults() { @@ -64,6 +65,11 @@ func (f *Features) SetDefaults() { f.Compliance = new(bool) *f.Compliance = true } + + if f.CustomBrand == nil { + f.CustomBrand = new(bool) + *f.CustomBrand = true + } } func (l *License) IsExpired() bool { diff --git a/store/sql_system_store.go b/store/sql_system_store.go index f8da06cecf2..a2b4f639619 100644 --- a/store/sql_system_store.go +++ b/store/sql_system_store.go @@ -114,3 +114,24 @@ func (s SqlSystemStore) Get() StoreChannel { return storeChannel } + +func (s SqlSystemStore) GetByName(name string) StoreChannel { + + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var system model.System + if err := s.GetReplica().SelectOne(&system, "SELECT * FROM Systems WHERE Name = :Name", map[string]interface{}{"Name": name}); err != nil { + result.Err = model.NewLocAppError("SqlSystemStore.GetByName", "store.sql_system.get_by_name.app_error", nil, "") + } + + result.Data = &system + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} diff --git a/store/sql_system_store_test.go b/store/sql_system_store_test.go index ce149e97ab5..74e2876ad42 100644 --- a/store/sql_system_store_test.go +++ b/store/sql_system_store_test.go @@ -30,6 +30,12 @@ func TestSqlSystemStore(t *testing.T) { if systems2[system.Name] != system.Value { t.Fatal() } + + result3 := <-store.System().GetByName(system.Name) + rsystem := result3.Data.(*model.System) + if rsystem.Value != system.Value { + t.Fatal() + } } func TestSqlSystemStoreSaveOrUpdate(t *testing.T) { diff --git a/store/store.go b/store/store.go index 323595ffb1b..4a4fa14813f 100644 --- a/store/store.go +++ b/store/store.go @@ -184,6 +184,7 @@ type SystemStore interface { SaveOrUpdate(system *model.System) StoreChannel Update(system *model.System) StoreChannel Get() StoreChannel + GetByName(name string) StoreChannel } type WebhookStore interface { diff --git a/utils/config.go b/utils/config.go index d8f52ce4999..244ff7180da 100644 --- a/utils/config.go +++ b/utils/config.go @@ -201,6 +201,8 @@ func getClientConfig(c *model.Config) map[string]string { props["EnableUserCreation"] = strconv.FormatBool(c.TeamSettings.EnableUserCreation) props["RestrictTeamNames"] = strconv.FormatBool(*c.TeamSettings.RestrictTeamNames) props["EnableTeamListing"] = strconv.FormatBool(*c.TeamSettings.EnableTeamListing) + props["EnableCustomBrand"] = strconv.FormatBool(*c.TeamSettings.EnableCustomBrand) + props["CustomBrandText"] = *c.TeamSettings.CustomBrandText props["EnableOAuthServiceProvider"] = strconv.FormatBool(c.ServiceSettings.EnableOAuthServiceProvider) diff --git a/utils/license.go b/utils/license.go index 217fd27cea7..fcc08e6b106 100644 --- a/utils/license.go +++ b/utils/license.go @@ -117,6 +117,7 @@ func getClientLicense(l *model.License) map[string]string { props["MFA"] = strconv.FormatBool(*l.Features.MFA) props["GoogleSSO"] = strconv.FormatBool(*l.Features.GoogleSSO) props["Compliance"] = strconv.FormatBool(*l.Features.Compliance) + props["CustomBrand"] = strconv.FormatBool(*l.Features.CustomBrand) props["IssuedAt"] = strconv.FormatInt(l.IssuedAt, 10) props["StartsAt"] = strconv.FormatInt(l.StartsAt, 10) props["ExpiresAt"] = strconv.FormatInt(l.ExpiresAt, 10) diff --git a/webapp/components/admin_console/team_settings.jsx b/webapp/components/admin_console/team_settings.jsx index 654f0085d56..d361c989f09 100644 --- a/webapp/components/admin_console/team_settings.jsx +++ b/webapp/components/admin_console/team_settings.jsx @@ -2,11 +2,11 @@ // See License.txt for license information. import $ from 'jquery'; -import ReactDOM from 'react-dom'; import * as Client from 'utils/client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; +import * as Utils from 'utils/utils.jsx'; -import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'react-intl'; +import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'react-intl'; const holders = defineMessages({ siteNameExample: { @@ -29,42 +29,91 @@ const holders = defineMessages({ import React from 'react'; +const ENABLE_BRAND_ACTION = 'enable_brand_action'; +const DISABLE_BRAND_ACTION = 'disable_brand_action'; + class TeamSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); + this.handleImageChange = this.handleImageChange.bind(this); + this.handleImageSubmit = this.handleImageSubmit.bind(this); + + this.uploading = false; this.state = { saveNeeded: false, + brandImageExists: false, + enableCustomBrand: this.props.config.TeamSettings.EnableCustomBrand, serverError: null }; } - handleChange() { - var s = {saveNeeded: true, serverError: this.state.serverError}; + componentWillMount() { + if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.CustomBrand === 'true') { + $.get('/api/v1/admin/get_brand_image').done(() => this.setState({brandImageExists: true})); + } + } + + componentDidUpdate() { + if (this.refs.image) { + const reader = new FileReader(); + + const img = this.refs.image; + reader.onload = (e) => { + $(img).attr('src', e.target.result); + }; + + reader.readAsDataURL(this.state.brandImage); + } + } + + handleChange(action) { + var s = {saveNeeded: true}; + + if (action === ENABLE_BRAND_ACTION) { + s.enableCustomBrand = true; + } + + if (action === DISABLE_BRAND_ACTION) { + s.enableCustomBrand = false; + } + this.setState(s); } + handleImageChange() { + const element = $(this.refs.fileInput); + if (element.prop('files').length > 0) { + this.setState({fileSelected: true, brandImage: element.prop('files')[0]}); + } + } + handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); var config = this.props.config; - config.TeamSettings.SiteName = ReactDOM.findDOMNode(this.refs.SiteName).value.trim(); - config.TeamSettings.RestrictCreationToDomains = ReactDOM.findDOMNode(this.refs.RestrictCreationToDomains).value.trim(); - config.TeamSettings.EnableTeamCreation = ReactDOM.findDOMNode(this.refs.EnableTeamCreation).checked; - config.TeamSettings.EnableUserCreation = ReactDOM.findDOMNode(this.refs.EnableUserCreation).checked; - config.TeamSettings.RestrictTeamNames = ReactDOM.findDOMNode(this.refs.RestrictTeamNames).checked; - config.TeamSettings.EnableTeamListing = ReactDOM.findDOMNode(this.refs.EnableTeamListing).checked; + config.TeamSettings.SiteName = this.refs.SiteName.value.trim(); + config.TeamSettings.RestrictCreationToDomains = this.refs.RestrictCreationToDomains.value.trim(); + config.TeamSettings.EnableTeamCreation = this.refs.EnableTeamCreation.checked; + config.TeamSettings.EnableUserCreation = this.refs.EnableUserCreation.checked; + config.TeamSettings.RestrictTeamNames = this.refs.RestrictTeamNames.checked; + config.TeamSettings.EnableTeamListing = this.refs.EnableTeamListing.checked; + config.TeamSettings.EnableCustomBrand = this.refs.EnableCustomBrand.checked; + + if (this.refs.CustomBrandText) { + config.TeamSettings.CustomBrandText = this.refs.CustomBrandText.value; + } var MaxUsersPerTeam = 50; - if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value, 10))) { - MaxUsersPerTeam = parseInt(ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value, 10); + if (!isNaN(parseInt(this.refs.MaxUsersPerTeam.value, 10))) { + MaxUsersPerTeam = parseInt(this.refs.MaxUsersPerTeam.value, 10); } config.TeamSettings.MaxUsersPerTeam = MaxUsersPerTeam; - ReactDOM.findDOMNode(this.refs.MaxUsersPerTeam).value = MaxUsersPerTeam; + this.refs.MaxUsersPerTeam.value = MaxUsersPerTeam; Client.saveConfig( config, @@ -86,6 +135,219 @@ class TeamSettings extends React.Component { ); } + handleImageSubmit(e) { + e.preventDefault(); + + if (!this.state.brandImage) { + return; + } + + if (this.uploading) { + return; + } + + $('#upload-button').button('loading'); + this.uploading = true; + + Client.uploadBrandImage(this.state.brandImage, + () => { + $('#upload-button').button('complete'); + this.setState({brandImageExists: true, brandImage: null}); + this.uploading = false; + }, + (err) => { + $('#upload-button').button('reset'); + this.uploading = false; + this.setState({serverImageError: err.message}); + } + ); + } + + createBrandSettings() { + var btnClass = 'btn'; + if (this.state.fileSelected) { + btnClass = 'btn btn-primary'; + } + + var serverImageError = ''; + if (this.state.serverImageError) { + serverImageError =
; + } + + let uploadImage; + let uploadText; + if (this.state.enableCustomBrand) { + let img; + if (this.state.brandImage) { + img = ( +
+
+
+
+