summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/command.go2
-rw-r--r--api/command_test.go5
-rw-r--r--api/file.go67
-rw-r--r--api/user.go21
4 files changed, 42 insertions, 53 deletions
diff --git a/api/command.go b/api/command.go
index 0d2f7597b..427922344 100644
--- a/api/command.go
+++ b/api/command.go
@@ -195,7 +195,7 @@ func joinCommand(c *Context, command *model.Command) bool {
return false
}
- command.GotoLocation = "/channels/" + v.Name
+ command.GotoLocation = c.GetTeamURL() + "/channels/" + v.Name
command.Response = model.RESP_EXECUTED
return true
}
diff --git a/api/command_test.go b/api/command_test.go
index fe52dd41b..d70729448 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -4,6 +4,7 @@
package api
import (
+ "strings"
"testing"
"github.com/mattermost/platform/model"
@@ -126,12 +127,12 @@ func TestJoinCommands(t *testing.T) {
}
rs5 := Client.Must(Client.Command("", "/join "+channel2.Name, false)).Data.(*model.Command)
- if rs5.GotoLocation != "/channels/"+channel2.Name {
+ if !strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name) {
t.Fatal("failed to join channel")
}
rs6 := Client.Must(Client.Command("", "/join "+channel3.Name, false)).Data.(*model.Command)
- if rs6.GotoLocation == "/channels/"+channel3.Name {
+ if strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name) {
t.Fatal("should not have joined direct message channel")
}
diff --git a/api/file.go b/api/file.go
index 1cb05e81b..be8fc5456 100644
--- a/api/file.go
+++ b/api/file.go
@@ -5,16 +5,15 @@ package api
import (
"bytes"
- "code.google.com/p/graphics-go/graphics"
l4g "code.google.com/p/log4go"
"fmt"
+ "github.com/disintegration/imaging"
"github.com/goamz/goamz/aws"
"github.com/goamz/goamz/s3"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"github.com/mssola/user_agent"
- "github.com/nfnt/resize"
"github.com/rwcarlsen/goexif/exif"
_ "golang.org/x/image/bmp"
"image"
@@ -24,7 +23,6 @@ import (
"image/jpeg"
"io"
"io/ioutil"
- "math"
"mime"
"net/http"
"net/url"
@@ -163,7 +161,7 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
name := filename[:strings.LastIndex(filename, ".")]
go func() {
// Decode image bytes into Image object
- img, _, err := image.Decode(bytes.NewReader(fileData[i]))
+ img, imgType, err := image.Decode(bytes.NewReader(fileData[i]))
if err != nil {
l4g.Error("Unable to decode image channelId=%v userId=%v filename=%v err=%v", channelId, userId, filename, err)
return
@@ -175,47 +173,30 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
// Get the image's orientation and ignore any errors since not all images will have orientation data
orientation, _ := getImageOrientation(fileData[i])
- // Create a temporary image that will be manipulated and then used to make the thumbnail and preview image
- var temp *image.RGBA
- switch orientation {
- case Upright, UprightMirrored, UpsideDown, UpsideDownMirrored:
- temp = image.NewRGBA(img.Bounds())
- case RotatedCCW, RotatedCCWMirrored, RotatedCW, RotatedCWMirrored:
- bounds := img.Bounds()
- temp = image.NewRGBA(image.Rect(bounds.Min.Y, bounds.Min.X, bounds.Max.Y, bounds.Max.X))
-
- width, height = height, width
+ if imgType == "png" {
+ dst := image.NewRGBA(img.Bounds())
+ draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
+ draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
+ img = dst
}
- // Draw a white background since JPEGs lack transparency
- draw.Draw(temp, temp.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
-
- // Copy the original image onto the temporary one while rotating it as necessary
switch orientation {
- case UpsideDown, UpsideDownMirrored:
- // rotate 180 degrees
- err := graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi})
- if err != nil {
- l4g.Error("Unable to rotate image")
- }
- case RotatedCW, RotatedCWMirrored:
- // rotate 90 degrees CCW
- graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: 3 * math.Pi / 2})
- if err != nil {
- l4g.Error("Unable to rotate image")
- }
- case RotatedCCW, RotatedCCWMirrored:
- // rotate 90 degrees CW
- graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi / 2})
- if err != nil {
- l4g.Error("Unable to rotate image")
- }
- case Upright, UprightMirrored:
- draw.Draw(temp, temp.Bounds(), img, img.Bounds().Min, draw.Over)
+ case UprightMirrored:
+ img = imaging.FlipH(img)
+ case UpsideDown:
+ img = imaging.Rotate180(img)
+ case UpsideDownMirrored:
+ img = imaging.FlipV(img)
+ case RotatedCWMirrored:
+ img = imaging.Transpose(img)
+ case RotatedCCW:
+ img = imaging.Rotate270(img)
+ case RotatedCCWMirrored:
+ img = imaging.Transverse(img)
+ case RotatedCW:
+ img = imaging.Rotate90(img)
}
- img = temp
-
// Create thumbnail
go func() {
thumbWidth := float64(utils.Cfg.FileSettings.ThumbnailWidth)
@@ -227,9 +208,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.FileSettings.ThumbnailHeight, img, resize.Lanczos3)
+ thumbnail = imaging.Resize(img, 0, utils.Cfg.FileSettings.ThumbnailHeight, imaging.Lanczos)
} else {
- thumbnail = resize.Resize(utils.Cfg.FileSettings.ThumbnailWidth, 0, img, resize.Lanczos3)
+ thumbnail = imaging.Resize(img, utils.Cfg.FileSettings.ThumbnailWidth, 0, imaging.Lanczos)
}
buf := new(bytes.Buffer)
@@ -249,7 +230,7 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
go func() {
var preview image.Image
if width > int(utils.Cfg.FileSettings.PreviewWidth) {
- preview = resize.Resize(utils.Cfg.FileSettings.PreviewWidth, utils.Cfg.FileSettings.PreviewHeight, img, resize.Lanczos3)
+ preview = imaging.Resize(img, utils.Cfg.FileSettings.PreviewWidth, utils.Cfg.FileSettings.PreviewHeight, imaging.Lanczos)
} else {
preview = img
}
diff --git a/api/user.go b/api/user.go
index 92a77e68a..b5f8e997d 100644
--- a/api/user.go
+++ b/api/user.go
@@ -8,13 +8,13 @@ import (
l4g "code.google.com/p/log4go"
b64 "encoding/base64"
"fmt"
+ "github.com/disintegration/imaging"
"github.com/golang/freetype"
"github.com/gorilla/mux"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
"github.com/mssola/user_agent"
- "github.com/nfnt/resize"
"hash/fnv"
"image"
"image/color"
@@ -467,10 +467,14 @@ func RevokeAllSession(c *Context, userId string) {
for _, session := range sessions {
c.LogAuditWithUserId(userId, "session_id="+session.Id)
- sessionCache.Remove(session.Token)
- if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
- c.Err = result.Err
- return
+ if session.IsOAuth {
+ RevokeAccessToken(session.Token)
+ } else {
+ sessionCache.Remove(session.Token)
+ if result := <-Srv.Store.Session().Remove(session.Id); result.Err != nil {
+ c.Err = result.Err
+ return
+ }
}
}
}
@@ -799,7 +803,7 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
// Scale profile image
- img = resize.Resize(utils.Cfg.FileSettings.ProfileWidth, utils.Cfg.FileSettings.ProfileHeight, img, resize.Lanczos3)
+ img = imaging.Resize(img, utils.Cfg.FileSettings.ProfileWidth, utils.Cfg.FileSettings.ProfileHeight, imaging.Lanczos)
buf := new(bytes.Buffer)
err = png.Encode(buf, img)
@@ -1417,7 +1421,7 @@ func GetAuthorizationCode(c *Context, w http.ResponseWriter, r *http.Request, te
func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser, *model.Team, *model.AppError) {
sso := utils.Cfg.GetSSOService(service)
- if sso != nil && !sso.Enable {
+ if sso == nil || !sso.Enable {
return nil, nil, model.NewAppError("AuthorizeOAuthUser", "Unsupported OAuth service provider", "service="+service)
}
@@ -1459,6 +1463,9 @@ func AuthorizeOAuthUser(service, code, state, redirectUri string) (io.ReadCloser
return nil, nil, model.NewAppError("AuthorizeOAuthUser", "Token request failed", err.Error())
} else {
ar = model.AccessResponseFromJson(resp.Body)
+ if ar == nil {
+ return nil, nil, model.NewAppError("AuthorizeOAuthUser", "Bad response from token request", "")
+ }
}
if strings.ToLower(ar.TokenType) != model.ACCESS_TOKEN_TYPE {