summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--api/context.go21
-rw-r--r--api/file.go76
-rw-r--r--api/file_test.go9
-rw-r--r--api/templates/error.html1
-rw-r--r--model/client.go18
-rw-r--r--utils/mail.go2
-rw-r--r--web/react/components/file_attachment.jsx15
-rw-r--r--web/react/components/new_channel.jsx11
-rw-r--r--web/react/components/post_right.jsx7
-rw-r--r--web/react/components/view_image.jsx18
-rw-r--r--web/react/utils/client.jsx14
-rw-r--r--web/react/utils/utils.jsx17
-rw-r--r--web/sass-files/sass/partials/_base.scss4
14 files changed, 175 insertions, 40 deletions
diff --git a/.travis.yml b/.travis.yml
index b8a503714..877977dd4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,7 +19,7 @@ before_install:
install:
- export PATH=$PATH:$HOME/gopath/bin
- go get github.com/tools/godep
-- godep restore
+#- godep restore
before_script:
- mysql -e "CREATE DATABASE IF NOT EXISTS mattermost_test ;" -uroot
- mysql -e "CREATE USER 'mmuser'@'%' IDENTIFIED BY 'mostest' ;" -uroot
diff --git a/api/context.go b/api/context.go
index 8babf85f2..aaf304e2c 100644
--- a/api/context.go
+++ b/api/context.go
@@ -4,14 +4,15 @@
package api
import (
- l4g "code.google.com/p/log4go"
- "github.com/mattermost/platform/model"
- "github.com/mattermost/platform/store"
- "github.com/mattermost/platform/utils"
"net"
"net/http"
"net/url"
"strings"
+
+ l4g "code.google.com/p/log4go"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/store"
+ "github.com/mattermost/platform/utils"
)
var sessionCache *utils.Cache = utils.NewLru(model.SESSION_CACHE_SIZE)
@@ -431,10 +432,22 @@ func IsPrivateIpAddress(ipAddress string) bool {
}
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
+
+ protocol := "http"
+ if utils.Cfg.ServiceSettings.UseSSL {
+ forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
+ if forwardProto != "http" {
+ protocol = "https"
+ }
+ }
+
+ SiteURL := protocol + "://" + r.Host
+
m := make(map[string]string)
m["Message"] = err.Message
m["Details"] = err.DetailedError
m["SiteName"] = utils.Cfg.ServiceSettings.SiteName
+ m["SiteURL"] = SiteURL
w.WriteHeader(err.StatusCode)
ServerTemplates.ExecuteTemplate(w, "error.html", m)
diff --git a/api/file.go b/api/file.go
index 558f9357e..50482a057 100644
--- a/api/file.go
+++ b/api/file.go
@@ -30,12 +30,15 @@ import (
"time"
)
+var fileInfoCache *utils.Cache = utils.NewLru(1000)
+
func InitFile(r *mux.Router) {
l4g.Debug("Initializing file api routes")
sr := r.PathPrefix("/files").Subrouter()
sr.Handle("/upload", ApiUserRequired(uploadFile)).Methods("POST")
- sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET", "HEAD")
+ sr.Handle("/get/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFile)).Methods("GET")
+ sr.Handle("/get_info/{channel_id:[A-Za-z0-9]+}/{user_id:[A-Za-z0-9]+}/{filename:([A-Za-z0-9]+/)?.+(\\.[A-Za-z0-9]{3,})?}", ApiAppHandler(getFileInfo)).Methods("GET")
sr.Handle("/get_public_link", ApiUserRequired(getPublicLink)).Methods("POST")
}
@@ -213,9 +216,72 @@ type ImageGetResult struct {
ImageData []byte
}
+func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
+ if !utils.IsS3Configured() && !utils.Cfg.ServiceSettings.UseLocalStorage {
+ c.Err = model.NewAppError("getFileInfo", "Unable to get file info. Amazon S3 not configured and local server storage turned off. ", "")
+ c.Err.StatusCode = http.StatusNotImplemented
+ return
+ }
+
+ params := mux.Vars(r)
+
+ channelId := params["channel_id"]
+ if len(channelId) != 26 {
+ c.SetInvalidParam("getFileInfo", "channel_id")
+ return
+ }
+
+ userId := params["user_id"]
+ if len(userId) != 26 {
+ c.SetInvalidParam("getFileInfo", "user_id")
+ return
+ }
+
+ filename := params["filename"]
+ if len(filename) == 0 {
+ c.SetInvalidParam("getFileInfo", "filename")
+ return
+ }
+
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, channelId, c.Session.UserId)
+
+ path := "teams/" + c.Session.TeamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
+ size := ""
+
+ if s, ok := fileInfoCache.Get(path); ok {
+ size = s.(string)
+ } else {
+
+ fileData := make(chan []byte)
+ asyncGetFile(path, fileData)
+
+ f := <-fileData
+
+ if f == nil {
+ c.Err = model.NewAppError("getFileInfo", "Could not find file.", "path="+path)
+ c.Err.StatusCode = http.StatusNotFound
+ return
+ }
+
+ size = strconv.Itoa(len(f))
+ fileInfoCache.Add(path, size)
+ }
+
+ if !c.HasPermissionsToChannel(cchan, "getFileInfo") {
+ return
+ }
+
+ w.Header().Set("Cache-Control", "max-age=2592000, public")
+
+ result := make(map[string]string)
+ result["filename"] = filename
+ result["size"] = size
+ w.Write([]byte(model.MapToJson(result)))
+}
+
func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.IsS3Configured() && !utils.Cfg.ServiceSettings.UseLocalStorage {
- c.Err = model.NewAppError("getFile", "Unable to upload file. Amazon S3 not configured and local server storage turned off. ", "")
+ c.Err = model.NewAppError("getFile", "Unable to get file. Amazon S3 not configured and local server storage turned off. ", "")
c.Err.StatusCode = http.StatusNotImplemented
return
}
@@ -281,11 +347,7 @@ func getFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Cache-Control", "max-age=2592000, public")
- w.Header().Set("Content-Length", strconv.Itoa(len(f)))
-
- if r.Method != "HEAD" {
- w.Write(f)
- }
+ w.Write(f)
}
func asyncGetFile(path string, fileData chan []byte) {
diff --git a/api/file_test.go b/api/file_test.go
index 566fd69d0..eb1fcf2ce 100644
--- a/api/file_test.go
+++ b/api/file_test.go
@@ -201,6 +201,15 @@ func TestGetFile(t *testing.T) {
t.Fatal(downErr)
}
+ if resp, downErr := Client.GetFileInfo(filenames[0]); downErr != nil {
+ t.Fatal(downErr)
+ } else {
+ m := resp.Data.(map[string]string)
+ if len(m["size"]) == 0 {
+ t.Fail()
+ }
+ }
+
team2 := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
team2 = Client.Must(Client.CreateTeam(team2)).Data.(*model.Team)
diff --git a/api/templates/error.html b/api/templates/error.html
index f38bb81a1..3474c9e1e 100644
--- a/api/templates/error.html
+++ b/api/templates/error.html
@@ -14,6 +14,7 @@
<div class="error__icon"><i class="fa fa-exclamation-triangle"></i></div>
<h2>{{ .SiteName }} needs your help:</h2>
<p>{{.Message}}</p>
+ <a href="{{.SiteURL}}">Go back to team site</a>
</div>
</div>
</body>
diff --git a/model/client.go b/model/client.go
index 17e2466df..9fcb06cf8 100644
--- a/model/client.go
+++ b/model/client.go
@@ -589,6 +589,24 @@ func (c *Client) GetFile(url string, isFullUrl bool) (*Result, *AppError) {
}
}
+func (c *Client) GetFileInfo(url string) (*Result, *AppError) {
+ var rq *http.Request
+ rq, _ = http.NewRequest("GET", c.Url+"/files/get_info"+url, nil)
+
+ if len(c.AuthToken) > 0 {
+ rq.Header.Set(HEADER_AUTH, "BEARER "+c.AuthToken)
+ }
+
+ if rp, err := c.HttpClient.Do(rq); err != nil {
+ return nil, NewAppError(url, "We encountered an error while connecting to the server", err.Error())
+ } else if rp.StatusCode >= 300 {
+ return nil, AppErrorFromJson(rp.Body)
+ } else {
+ return &Result{rp.Header.Get(HEADER_REQUEST_ID),
+ rp.Header.Get(HEADER_ETAG_SERVER), MapFromJson(rp.Body)}, nil
+ }
+}
+
func (c *Client) GetPublicLink(data map[string]string) (*Result, *AppError) {
if r, err := c.DoPost("/files/get_public_link", MapToJson(data)); err != nil {
return nil, err
diff --git a/utils/mail.go b/utils/mail.go
index 783a2de8c..7cb178626 100644
--- a/utils/mail.go
+++ b/utils/mail.go
@@ -12,6 +12,7 @@ import (
"net"
"net/mail"
"net/smtp"
+ "time"
)
func CheckMailSettings() *model.AppError {
@@ -101,6 +102,7 @@ func SendMail(to, subject, body string) *model.AppError {
headers["Subject"] = html.UnescapeString(subject)
headers["MIME-version"] = "1.0"
headers["Content-Type"] = "text/html"
+ headers["Date"] = time.Now().Format(time.RFC1123Z)
message := ""
for k, v := range headers {
diff --git a/web/react/components/file_attachment.jsx b/web/react/components/file_attachment.jsx
index c36c908d2..ab550d500 100644
--- a/web/react/components/file_attachment.jsx
+++ b/web/react/components/file_attachment.jsx
@@ -2,6 +2,7 @@
// See License.txt for license information.
var utils = require('../utils/utils.jsx');
+var Client = require('../utils/client.jsx');
var Constants = require('../utils/constants.jsx');
module.exports = React.createClass({
@@ -103,12 +104,16 @@ module.exports = React.createClass({
if (this.state.fileSize < 0) {
var self = this;
- // asynchronously request the size of the file so that we can display it next to the thumbnail
- utils.getFileSize(utils.getFileUrl(filename), function(fileSize) {
- if (self.canSetState) {
- self.setState({fileSize: fileSize});
+ Client.getFileInfo(
+ filename,
+ function(data) {
+ if (self.canSetState) {
+ self.setState({fileSize: parseInt(data["size"], 10)});
+ }
+ },
+ function(err) {
}
- });
+ );
} else {
fileSizeString = utils.fileSizeToString(this.state.fileSize);
}
diff --git a/web/react/components/new_channel.jsx b/web/react/components/new_channel.jsx
index 38c9ea76d..fc24a7cdc 100644
--- a/web/react/components/new_channel.jsx
+++ b/web/react/components/new_channel.jsx
@@ -84,6 +84,17 @@ module.exports = React.createClass({
var button = e.relatedTarget;
self.setState({channelType: $(button).attr('data-channeltype')});
});
+ $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose);
+ },
+ componentWillUnmount: function() {
+ $(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose);
+ },
+ handleClose: function() {
+ $(this.getDOMNode()).find('.form-control').each(function clearForms() {
+ this.value = '';
+ });
+
+ this.setState({channelType: '', displayNameError: '', nameError: '', serverError: '', inValid: false});
},
getInitialState: function() {
return {channelType: ''};
diff --git a/web/react/components/post_right.jsx b/web/react/components/post_right.jsx
index ac4c8a6d7..fb45ad28e 100644
--- a/web/react/components/post_right.jsx
+++ b/web/react/components/post_right.jsx
@@ -26,6 +26,13 @@ RhsHeaderPost = React.createClass({
});
AppDispatcher.handleServerAction({
+ type: ActionTypes.RECIEVED_SEARCH_TERM,
+ term: null,
+ do_search: false,
+ is_mention_search: false
+ });
+
+ AppDispatcher.handleServerAction({
type: ActionTypes.RECIEVED_POST_SELECTED,
results: null
});
diff --git a/web/react/components/view_image.jsx b/web/react/components/view_image.jsx
index 6077c4ebc..24efce0f1 100644
--- a/web/react/components/view_image.jsx
+++ b/web/react/components/view_image.jsx
@@ -224,18 +224,24 @@ module.exports = React.createClass({
</div>
</div>
);
+ bgClass = 'white-bg';
// asynchronously request the actual size of this file
if (!(filename in this.state.fileSizes)) {
var self = this;
- utils.getFileSize(utils.getFileUrl(filename), function fileSizeOp(fileSize) {
- if (self.canSetState) {
- var fileSizes = self.state.fileSizes;
- fileSizes[filename] = fileSize;
- self.setState(fileSizes);
+ Client.getFileInfo(
+ filename,
+ function(data) {
+ if (self.canSetState) {
+ var fileSizes = self.state.fileSizes;
+ fileSizes[filename] = parseInt(data["size"], 10);
+ self.setState(fileSizes);
+ }
+ },
+ function(err) {
}
- });
+ );
}
}
} else {
diff --git a/web/react/utils/client.jsx b/web/react/utils/client.jsx
index 754843697..13d6c3f54 100644
--- a/web/react/utils/client.jsx
+++ b/web/react/utils/client.jsx
@@ -831,6 +831,20 @@ module.exports.uploadFile = function(formData, success, error) {
return request;
};
+module.exports.getFileInfo = function(filename, success, error) {
+ $.ajax({
+ url: '/api/v1/files/get_info' + filename,
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'GET',
+ success: success,
+ error: function onError(xhr, status, err) {
+ var e = handleError('getFileInfo', xhr, status, err);
+ error(e);
+ }
+ });
+};
+
module.exports.getPublicLink = function(data, success, error) {
$.ajax({
url: '/api/v1/files/get_public_link',
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index 77b204793..00da9ce5f 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -604,23 +604,6 @@ module.exports.splitFileLocation = function(fileLocation) {
return {ext: ext, name: filename, path: filePath};
};
-// Asynchronously gets the size of a file by requesting its headers. If successful, it calls the
-// provided callback with the file size in bytes as the argument.
-module.exports.getFileSize = function(url, callback) {
- var request = new XMLHttpRequest();
-
- request.open('HEAD', url, true);
- request.onreadystatechange = function onReadyStateChange() {
- if (request.readyState === 4 && request.status === 200) {
- if (callback) {
- callback(parseInt(request.getResponseHeader('content-length'), 10));
- }
- }
- };
-
- request.send();
-};
-
module.exports.toTitleCase = function(str) {
function doTitleCase(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
diff --git a/web/sass-files/sass/partials/_base.scss b/web/sass-files/sass/partials/_base.scss
index 5b68b488f..e817761ee 100644
--- a/web/sass-files/sass/partials/_base.scss
+++ b/web/sass-files/sass/partials/_base.scss
@@ -124,3 +124,7 @@ div.theme {
.black-bg {
background-color: black !important;
}
+
+.white-bg {
+ background-color: white !important;
+}