summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorcpanato <ctadeu@gmail.com>2018-07-06 10:57:40 +0200
committercpanato <ctadeu@gmail.com>2018-07-06 10:57:40 +0200
commita92f5addccad0f77079308ff853a8251db5f2d09 (patch)
treef4aefb58970b38a5b561551ccd3d4cd430dbdce7 /app
parent4de50ddfc3ef09ddc0a56c8ff9bf2429df524aa5 (diff)
parent0896b5c64ef224f0f8835b9727d1c1b94cbe7c29 (diff)
downloadchat-a92f5addccad0f77079308ff853a8251db5f2d09.tar.gz
chat-a92f5addccad0f77079308ff853a8251db5f2d09.tar.bz2
chat-a92f5addccad0f77079308ff853a8251db5f2d09.zip
Merge remote-tracking branch 'upstream/release-5.1' into release-5.1-daily-merge-20180706
Diffstat (limited to 'app')
-rw-r--r--app/user.go25
-rw-r--r--app/user_test.go2
-rw-r--r--app/webhook.go11
3 files changed, 29 insertions, 9 deletions
diff --git a/app/user.go b/app/user.go
index b00ef19ef..acd3ee9aa 100644
--- a/app/user.go
+++ b/app/user.go
@@ -24,6 +24,7 @@ import (
"github.com/disintegration/imaging"
"github.com/golang/freetype"
+ "github.com/golang/freetype/truetype"
"github.com/mattermost/mattermost-server/einterfaces"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
@@ -696,12 +697,7 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
initial := string(strings.ToUpper(username)[0])
- fontDir, _ := utils.FindDir("fonts")
- fontBytes, err := ioutil.ReadFile(filepath.Join(fontDir, initialFont))
- if err != nil {
- return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.default_font.app_error", nil, err.Error(), http.StatusInternalServerError)
- }
- font, err := freetype.ParseFont(fontBytes)
+ font, err := getFont(initialFont)
if err != nil {
return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.default_font.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -719,7 +715,7 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
c.SetDst(dstImg)
c.SetSrc(srcImg)
- pt := freetype.Pt(IMAGE_PROFILE_PIXEL_DIMENSION/6, IMAGE_PROFILE_PIXEL_DIMENSION*2/3)
+ pt := freetype.Pt(IMAGE_PROFILE_PIXEL_DIMENSION/5, IMAGE_PROFILE_PIXEL_DIMENSION*2/3)
_, err = c.DrawString(initial, pt)
if err != nil {
return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.initial.app_error", nil, err.Error(), http.StatusInternalServerError)
@@ -734,6 +730,21 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
}
}
+func getFont(initialFont string) (*truetype.Font, error) {
+ // Some people have the old default font still set, so just treat that as if they're using the new default
+ if initialFont == "luximbi.ttf" {
+ initialFont = "nunito-bold.ttf"
+ }
+
+ fontDir, _ := utils.FindDir("fonts")
+ fontBytes, err := ioutil.ReadFile(filepath.Join(fontDir, initialFont))
+ if err != nil {
+ return nil, err
+ }
+
+ return freetype.ParseFont(fontBytes)
+}
+
func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) {
var img []byte
readFailed := false
diff --git a/app/user_test.go b/app/user_test.go
index 7952eaa1f..959455121 100644
--- a/app/user_test.go
+++ b/app/user_test.go
@@ -97,7 +97,7 @@ func TestCreateOAuthUser(t *testing.T) {
}
func TestCreateProfileImage(t *testing.T) {
- b, err := CreateProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba", "luximbi.ttf")
+ b, err := CreateProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba", "nunito-bold.ttf")
if err != nil {
t.Fatal(err)
}
diff --git a/app/webhook.go b/app/webhook.go
index c887fec97..8926c94a8 100644
--- a/app/webhook.go
+++ b/app/webhook.go
@@ -587,6 +587,8 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
hook = result.Data.(*model.IncomingWebhook)
}
+ uchan := a.Srv.Store.User().Get(hook.UserId)
+
if len(req.Props) == 0 {
req.Props = make(model.StringInterface)
}
@@ -637,8 +639,15 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel_locked.app_error", nil, "", http.StatusForbidden)
}
+ var user *model.User
+ if result := <-uchan; result.Err != nil {
+ return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "err="+result.Err.Message, http.StatusForbidden)
+ } else {
+ user = result.Data.(*model.User)
+ }
+
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
- channel.Name == model.DEFAULT_CHANNEL {
+ channel.Name == model.DEFAULT_CHANNEL && !a.RolesGrantPermission(user.GetRoles(), model.PERMISSION_MANAGE_SYSTEM.Id) {
return model.NewAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "", http.StatusForbidden)
}