Open platform to collect and prioritize feedback
feature: user can choose between Letter and Gravatar (#697)
Guilherme Oenning9ab26eb57db0
diff --git a/app/actions/settings.go b/app/actions/settings.goindex 9a0d7d733..aed332b83 100644--- a/app/actions/settings.go+++ b/app/actions/settings.go@@ -32,6 +32,10 @@ func (input *UpdateUserSettings) Validate(user *models.User, services *app.Serviresult.AddFieldFailure("name", "Name is required.")}+ if input.Model.AvatarType < 1 || input.Model.AvatarType > 3 {+ result.AddFieldFailure("avatarType", "Invalid avatar type.")+ }+if len(input.Model.Name) > 50 {result.AddFieldFailure("name", "Name must have less than 50 characters.")}diff --git a/app/actions/settings_test.go b/app/actions/settings_test.goindex 4c08bb2e4..cd601553c 100644--- a/app/actions/settings_test.go+++ b/app/actions/settings_test.go@@ -15,7 +15,12 @@ func TestInvalidUserNames(t *testing.T) {"","123456789012345678901234567890123456789012345678901", // 51 chars} {- action := &actions.UpdateUserSettings{Model: &models.UpdateUserSettings{Name: name}}+ action := &actions.UpdateUserSettings{+ Model: &models.UpdateUserSettings{+ Name: name,+ AvatarType: models.AvatarTypeGravatar,+ },+ }result := action.Validate(nil, services)ExpectFailed(result, "name")}@@ -28,7 +33,12 @@ func TestValidUserNames(t *testing.T) {"Jon Snow","Arya",} {- action := &actions.UpdateUserSettings{Model: &models.UpdateUserSettings{Name: name}}+ action := &actions.UpdateUserSettings{+ Model: &models.UpdateUserSettings{+ Name: name,+ AvatarType: models.AvatarTypeGravatar,+ },+ }result := action.Validate(nil, services)ExpectSuccess(result)}@@ -52,7 +62,7 @@ func TestInvalidSettings(t *testing.T) {},}result := action.Validate(nil, services)- ExpectFailed(result, "settings")+ ExpectFailed(result, "settings", "avatarType")}}@@ -72,8 +82,9 @@ func TestValidSettings(t *testing.T) {} {action := &actions.UpdateUserSettings{Model: &models.UpdateUserSettings{- Name: "John Snow",- Settings: settings,+ Name: "John Snow",+ Settings: settings,+ AvatarType: models.AvatarTypeGravatar,},}result := action.Validate(nil, services)diff --git a/app/cmd/routes.go b/app/cmd/routes.goindex 3d1bfc593..6cfd4837a 100644--- a/app/cmd/routes.go+++ b/app/cmd/routes.go@@ -64,7 +64,8 @@ func routes(r *web.Engine) *web.Engine {tenantAssets := r.Group(){tenantAssets.Use(middlewares.ClientCache(5 * 24 * time.Hour))- tenantAssets.Get("/avatars/:size/:id/:name", handlers.Avatar())+ tenantAssets.Get("/avatars/letter/:id/:name", handlers.LetterAvatar())+ tenantAssets.Get("/avatars/gravatar/:id/:name", handlers.Gravatar())tenantAssets.Use(middlewares.ClientCache(30 * 24 * time.Hour))tenantAssets.Get("/favicon/*bkey", handlers.Favicon())diff --git a/app/handlers/images.go b/app/handlers/images.goindex f6bf1554c..d42305dbb 100644--- a/app/handlers/images.go+++ b/app/handlers/images.go@@ -17,12 +17,57 @@ import ("github.com/goenning/letteravatar")-//Avatar returns a gravatar picture of fallsback to letter avatar based on name-func Avatar() web.HandlerFunc {+//LetterAvatar returns a letter gravatar picture based on given name+func LetterAvatar() web.HandlerFunc {return func(c web.Context) error {+ id := c.Param("id")name := c.Param("name")- size, _ := c.ParamAsInt("size")+ if name == "" {+ name = "?"+ }++ size, err := c.QueryParamAsInt("size")+ if err != nil {+ return c.Failure(err)+ }++ if size >= 200 {+ size = 200+ }++ img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{+ PaletteKey: fmt.Sprintf("%s:%s", id, name),+ })+ if err != nil {+ return c.Failure(err)+ }++ buf := new(bytes.Buffer)+ err = png.Encode(buf, img)+ if err != nil {+ return c.Failure(err)+ }++ return c.Image("image/png", buf.Bytes())+ }+}++//Gravatar returns a gravatar picture of fallsback to letter avatar based on name+func Gravatar() web.HandlerFunc {+ return func(c web.Context) error {id, err := c.ParamAsInt("id")+ if err != nil {+ return c.NotFound()+ }++ size, err := c.QueryParamAsInt("size")+ if err != nil {+ return c.Failure(err)+ }++ if size >= 200 {+ size = 200+ }if err == nil && id > 0 {user, err := c.Services().Users.GetByID(id)@@ -47,20 +92,7 @@ func Avatar() web.HandlerFunc {}}- img, err := letteravatar.Draw(size, strings.ToUpper(letteravatar.Extract(name)), &letteravatar.Options{- PaletteKey: fmt.Sprintf("%d:%s", id, name),- })- if err != nil {- return c.Failure(err)- }-- buf := new(bytes.Buffer)- err = png.Encode(buf, img)- if err != nil {- return c.Failure(err)- }-- return c.Image("image/png", buf.Bytes())+ return LetterAvatar()(c)}}diff --git a/app/handlers/images_test.go b/app/handlers/images_test.goindex 8cddba7ce..2be3a665a 100644--- a/app/handlers/images_test.go+++ b/app/handlers/images_test.go@@ -23,11 +23,11 @@ func TestGravatarHandler(t *testing.T) {}services.Users.Register(user)code, response := server.+ WithURL("https://demo.test.fider.io/?size=50").OnTenant(mock.DemoTenant).AddParam("id", user.ID).- AddParam("size", 50).AddParam("name", user.Name).- Execute(handlers.Avatar())+ Execute(handlers.Gravatar())expectedAvatar := []byte{255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 96, 0, 96, 0, 0, 255, 254, 0, 59, 67, 82, 69, 65, 84, 79, 82, 58, 32, 103, 100, 45, 106, 112, 101, 103, 32, 118, 49, 46, 48, 32, 40, 117, 115, 105, 110, 103, 32, 73, 74, 71, 32, 74, 80, 69, 71, 32, 118, 54, 50, 41, 44, 32, 113, 117, 97, 108, 105, 116, 121, 32, 61, 32, 57, 48, 10, 255, 219, 0, 67, 0, 3, 2, 2, 3, 2, 2, 3, 3, 3, 3, 4, 3, 3, 4, 5, 8, 5, 5, 4, 4, 5, 10, 7, 7, 6, 8, 12, 10, 12, 12, 11, 10, 11, 11, 13, 14, 18, 16, 13, 14, 17, 14, 11, 11, 16, 22, 16, 17, 19, 20, 21, 21, 21, 12, 15, 23, 24, 22, 20, 24, 18, 20, 21, 20, 255, 219, 0, 67, 1, 3, 4, 4, 5, 4, 5, 9, 5, 5, 9, 20, 13, 11, 13, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 255, 192, 0, 17, 8, 0, 50, 0, 50, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 252, 207, 109, 22, 21, 199, 12, 61, 112, 213, 57, 209, 237, 33, 182, 105, 165, 46, 168, 163, 183, 57, 62, 149, 245, 7, 236, 5, 225, 255, 0, 3, 235, 159, 181, 46, 155, 99, 227, 221, 31, 79, 214, 244, 137, 244, 107, 150, 182, 179, 213, 33, 89, 160, 123, 133, 101, 32, 148, 111, 148, 144, 130, 67, 200, 237, 94, 239, 255, 0, 5, 55, 248, 123, 240, 166, 203, 194, 254, 23, 210, 126, 29, 120, 111, 194, 158, 24, 214, 165, 214, 86, 43, 171, 171, 8, 161, 179, 45, 7, 145, 35, 54, 66, 224, 20, 12, 83, 45, 142, 14, 209, 223, 7, 179, 151, 70, 212, 79, 38, 51, 189, 175, 61, 207, 139, 79, 193, 22, 210, 244, 49, 168, 222, 70, 100, 114, 155, 150, 44, 0, 188, 142, 6, 113, 147, 214, 188, 207, 84, 125, 62, 210, 249, 173, 96, 178, 44, 85, 182, 231, 130, 73, 252, 171, 236, 77, 122, 230, 211, 83, 248, 123, 13, 181, 133, 237, 189, 237, 205, 148, 40, 151, 83, 7, 85, 141, 36, 85, 220, 9, 98, 113, 180, 237, 206, 115, 192, 53, 243, 111, 135, 188, 51, 164, 71, 227, 107, 121, 117, 45, 95, 79, 186, 182, 50, 3, 32, 176, 147, 206, 216, 51, 215, 177, 35, 220, 10, 43, 69, 69, 46, 84, 42, 18, 114, 187, 155, 216, 169, 160, 248, 58, 195, 92, 133, 198, 207, 42, 120, 240, 94, 41, 19, 4, 3, 208, 253, 56, 171, 147, 124, 54, 180, 83, 247, 98, 3, 25, 232, 223, 227, 95, 74, 254, 206, 158, 16, 240, 47, 141, 255, 0, 110, 47, 15, 120, 71, 80, 180, 77, 127, 194, 122, 134, 149, 112, 37, 242, 103, 150, 5, 44, 45, 222, 85, 108, 198, 202, 195, 13, 26, 140, 103, 191, 61, 13, 125, 161, 241, 7, 246, 40, 248, 19, 166, 207, 226, 11, 75, 123, 61, 86, 11, 230, 137, 26, 22, 143, 85, 148, 165, 129, 59, 137, 3, 113, 57, 227, 105, 195, 238, 60, 142, 153, 171, 167, 21, 39, 203, 107, 179, 58, 142, 80, 138, 159, 53, 147, 63, 36, 207, 195, 155, 44, 253, 216, 255, 0, 241, 239, 254, 42, 138, 250, 238, 251, 224, 231, 192, 219, 11, 219, 139, 89, 126, 37, 220, 44, 144, 200, 209, 178, 181, 237, 190, 65, 7, 4, 31, 147, 218, 138, 233, 246, 17, 236, 190, 244, 115, 123, 106, 157, 223, 226, 121, 191, 236, 225, 225, 237, 38, 235, 196, 90, 30, 175, 127, 4, 114, 125, 140, 93, 100, 191, 241, 6, 27, 54, 253, 48, 77, 124, 243, 241, 167, 198, 35, 226, 39, 196, 237, 94, 235, 78, 139, 26, 104, 185, 107, 125, 58, 218, 17, 144, 33, 86, 33, 118, 129, 221, 190, 241, 247, 106, 244, 107, 47, 23, 73, 225, 15, 133, 90, 133, 196, 13, 229, 220, 75, 20, 144, 68, 71, 4, 51, 182, 220, 143, 112, 9, 63, 133, 120, 5, 178, 204, 242, 55, 144, 28, 176, 82, 78, 204, 228, 14, 245, 203, 94, 126, 226, 130, 245, 59, 240, 112, 213, 212, 126, 136, 244, 13, 55, 74, 178, 240, 239, 135, 124, 77, 160, 235, 186, 69, 235, 248, 154, 254, 218, 6, 210, 86, 221, 247, 164, 18, 137, 163, 102, 50, 42, 57, 249, 140, 94, 114, 224, 130, 65, 113, 144, 59, 114, 87, 90, 123, 216, 216, 219, 93, 164, 166, 11, 168, 159, 99, 194, 210, 1, 42, 54, 73, 4, 40, 59, 128, 192, 28, 144, 57, 53, 235, 31, 7, 143, 143, 126, 30, 106, 54, 94, 32, 240, 236, 210, 232, 154, 157, 131, 75, 50, 203, 106, 26, 43, 150, 67, 20, 76, 81, 164, 94, 118, 178, 49, 194, 156, 242, 132, 17, 212, 87, 97, 241, 150, 255, 0, 196, 30, 54, 240, 54, 163, 172, 248, 150, 120, 237, 158, 105, 197, 202, 202, 2, 192, 215, 239, 130, 0, 242, 219, 27, 74, 156, 238, 0, 99, 43, 129, 201, 192, 227, 183, 83, 177, 212, 229, 146, 91, 220, 227, 127, 103, 175, 137, 175, 225, 175, 142, 190, 1, 241, 13, 228, 134, 40, 99, 186, 58, 117, 212, 209, 49, 70, 141, 103, 86, 133, 159, 35, 160, 11, 38, 239, 248, 11, 12, 98, 189, 215, 246, 171, 241, 135, 142, 45, 245, 173, 91, 77, 209, 124, 79, 126, 44, 245, 139, 159, 54, 243, 124, 196, 201, 147, 144, 64, 110, 170, 164, 99, 229, 30, 149, 241, 45, 148, 139, 230, 52, 82, 62, 200, 228, 227, 118, 126, 235, 127, 11, 126, 127, 161, 53, 245, 126, 187, 227, 120, 254, 34, 120, 99, 70, 241, 35, 184, 150, 226, 242, 216, 45, 216, 207, 41, 118, 152, 89, 129, 244, 203, 124, 224, 127, 118, 68, 174, 202, 18, 188, 92, 14, 76, 92, 57, 92, 106, 37, 177, 226, 171, 240, 158, 2, 163, 204, 190, 99, 39, 241, 125, 123, 209, 91, 242, 106, 110, 36, 108, 103, 25, 52, 86, 156, 144, 254, 83, 139, 219, 213, 254, 98, 75, 109, 16, 120, 175, 192, 113, 105, 198, 65, 19, 191, 207, 28, 135, 160, 96, 73, 25, 246, 237, 248, 215, 157, 234, 191, 12, 124, 83, 160, 193, 113, 52, 154, 116, 173, 104, 138, 124, 201, 237, 220, 58, 21, 235, 147, 131, 211, 128, 121, 244, 174, 183, 71, 241, 141, 151, 135, 60, 63, 100, 247, 83, 22, 148, 198, 25, 97, 143, 150, 111, 240, 252, 107, 152, 241, 151, 197, 61, 91, 197, 182, 198, 199, 119, 216, 244, 204, 130, 109, 227, 57, 47, 142, 155, 219, 191, 211, 165, 101, 87, 217, 181, 119, 185, 215, 134, 85, 163, 39, 20, 189, 219, 255, 0, 86, 56, 239, 51, 228, 219, 142, 125, 107, 214, 62, 16, 252, 25, 241, 47, 199, 75, 235, 75, 107, 101, 187, 155, 78, 179, 30, 76, 183, 140, 75, 45, 180, 99, 36, 12, 177, 194, 168, 207, 78, 131, 53, 15, 134, 252, 1, 168, 63, 129, 228, 241, 11, 91, 88, 106, 0, 198, 124, 184, 46, 98, 102, 109, 163, 142, 10, 144, 115, 199, 124, 213, 95, 17, 106, 30, 37, 248, 117, 161, 157, 30, 211, 84, 159, 79, 178, 212, 80, 61, 205, 189, 155, 180, 105, 38, 224, 172, 59, 231, 161, 0, 250, 226, 185, 121, 26, 179, 107, 67, 181, 212, 231, 188, 96, 245, 48, 190, 38, 248, 13, 62, 29, 120, 170, 243, 71, 77, 98, 203, 89, 16, 57, 95, 58, 206, 64, 227, 232, 112, 72, 4, 122, 100, 214, 175, 195, 127, 19, 182, 157, 165, 221, 233, 247, 26, 149, 188, 86, 79, 47, 157, 29, 172, 163, 14, 36, 192, 5, 149, 136, 192, 4, 0, 8, 207, 59, 87, 142, 5, 112, 166, 202, 115, 100, 110, 202, 17, 0, 144, 71, 188, 247, 98, 9, 199, 228, 42, 189, 17, 151, 44, 174, 141, 37, 14, 120, 114, 201, 158, 181, 37, 234, 51, 177, 15, 193, 39, 24, 52, 87, 147, 110, 62, 166, 138, 232, 250, 199, 145, 195, 245, 37, 252, 223, 128, 249, 216, 179, 140, 146, 112, 160, 115, 244, 162, 220, 3, 113, 16, 35, 32, 176, 227, 241, 162, 138, 228, 61, 37, 178, 62, 222, 240, 253, 180, 48, 120, 14, 241, 34, 137, 35, 65, 230, 0, 168, 160, 1, 197, 121, 119, 199, 187, 120, 158, 227, 74, 221, 26, 55, 250, 29, 185, 229, 71, 247, 18, 138, 43, 210, 173, 252, 63, 184, 249, 236, 63, 241, 126, 103, 156, 120, 158, 24, 227, 248, 96, 74, 162, 169, 254, 215, 65, 144, 49, 199, 144, 213, 230, 180, 81, 94, 124, 186, 30, 229, 47, 132, 40, 162, 138, 147, 99, 255, 217}Expect(code).Equals(http.StatusOK)@@ -46,10 +46,10 @@ func TestGravatarNotFound_LetterAvatarHandler(t *testing.T) {services.Users.Register(user)code, response := server.OnTenant(mock.DemoTenant).+ WithURL("https://demo.test.fider.io/?size=50").AddParam("id", user.ID).- AddParam("size", 50).AddParam("name", user.Name).- Execute(handlers.Avatar())+ Execute(handlers.Gravatar())expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 3, 6, 73, 68, 65, 84, 120, 156, 236, 152, 75, 79, 19, 81, 20, 128, 207, 204, 212, 210, 18, 90, 232, 211, 34, 196, 40, 6, 65, 129, 0, 209, 2, 11, 100, 97, 140, 113, 225, 2, 127, 3, 198, 196, 184, 55, 38, 38, 36, 198, 132, 168, 11, 149, 152, 24, 35, 97, 99, 220, 24, 23, 46, 140, 186, 49, 38, 242, 42, 20, 10, 72, 241, 149, 64, 75, 12, 125, 208, 86, 104, 7, 90, 103, 134, 206, 29, 211, 14, 25, 154, 66, 116, 46, 96, 101, 113, 191, 213, 225, 204, 153, 123, 191, 204, 185, 15, 82, 205, 197, 87, 157, 176, 255, 160, 255, 183, 192, 246, 16, 45, 28, 136, 22, 14, 68, 11, 7, 162, 133, 3, 209, 194, 129, 104, 225, 64, 180, 112, 32, 90, 56, 104, 212, 20, 117, 84, 158, 57, 119, 248, 172, 242, 103, 50, 157, 138, 164, 34, 19, 97, 143, 55, 54, 171, 36, 105, 138, 190, 209, 114, 93, 199, 20, 45, 115, 203, 15, 39, 31, 109, 29, 228, 90, 211, 213, 131, 197, 118, 1, 173, 223, 113, 223, 75, 163, 244, 30, 104, 89, 245, 150, 26, 243, 241, 188, 228, 133, 35, 231, 125, 9, 255, 125, 79, 111, 52, 21, 5, 0, 36, 161, 53, 97, 181, 177, 162, 1, 0, 94, 124, 127, 25, 74, 134, 243, 70, 232, 168, 108, 7, 0, 119, 120, 226, 175, 78, 216, 77, 124, 58, 211, 255, 192, 211, 251, 120, 250, 201, 251, 31, 31, 214, 81, 186, 170, 244, 104, 79, 251, 109, 147, 206, 36, 63, 29, 12, 12, 203, 65, 75, 121, 75, 222, 139, 173, 229, 173, 27, 53, 139, 67, 106, 38, 194, 211, 154, 138, 76, 143, 134, 220, 31, 23, 7, 251, 102, 250, 187, 71, 110, 241, 34, 111, 212, 26, 174, 52, 116, 201, 79, 63, 69, 103, 18, 60, 155, 145, 112, 56, 243, 94, 108, 203, 138, 38, 215, 147, 147, 145, 169, 189, 215, 202, 197, 23, 247, 189, 158, 127, 3, 0, 205, 246, 102, 171, 222, 42, 247, 209, 21, 116, 1, 192, 177, 178, 42, 139, 222, 162, 84, 154, 117, 166, 234, 178, 106, 0, 24, 13, 185, 213, 116, 112, 183, 59, 209, 21, 26, 5, 0, 138, 2, 167, 227, 148, 156, 217, 236, 163, 227, 180, 82, 230, 116, 56, 41, 74, 126, 170, 170, 131, 187, 213, 10, 174, 133, 228, 192, 166, 183, 201, 193, 92, 124, 62, 156, 92, 202, 106, 109, 246, 177, 181, 60, 19, 71, 127, 197, 190, 254, 252, 86, 8, 45, 36, 33, 94, 20, 0, 160, 180, 168, 84, 73, 14, 7, 71, 0, 160, 214, 92, 99, 212, 26, 0, 192, 168, 53, 156, 48, 215, 102, 242, 129, 17, 245, 35, 239, 246, 56, 213, 208, 153, 35, 70, 16, 121, 37, 35, 239, 53, 154, 162, 157, 217, 15, 230, 116, 56, 105, 42, 51, 203, 192, 226, 96, 129, 180, 76, 58, 19, 147, 157, 50, 198, 45, 43, 201, 80, 50, 60, 31, 247, 41, 189, 147, 247, 160, 63, 177, 16, 88, 11, 22, 72, 171, 222, 114, 82, 14, 230, 86, 230, 114, 243, 242, 210, 174, 183, 212, 217, 139, 109, 117, 214, 186, 220, 173, 240, 207, 181, 180, 140, 246, 82, 117, 39, 0, 172, 112, 241, 220, 91, 40, 187, 188, 92, 162, 132, 24, 154, 185, 220, 208, 197, 80, 52, 146, 208, 112, 1, 180, 40, 138, 170, 53, 215, 116, 183, 221, 172, 40, 57, 4, 0, 125, 222, 126, 36, 161, 220, 2, 150, 103, 189, 81, 47, 0, 52, 218, 50, 119, 209, 108, 236, 115, 156, 79, 96, 77, 161, 234, 78, 84, 184, 219, 209, 35, 73, 168, 228, 64, 9, 67, 51, 0, 32, 34, 241, 217, 151, 231, 158, 165, 201, 173, 149, 3, 129, 161, 38, 123, 227, 70, 140, 179, 216, 119, 162, 37, 239, 121, 0, 224, 69, 97, 44, 228, 126, 235, 127, 231, 79, 44, 108, 91, 57, 30, 158, 224, 210, 156, 78, 163, 227, 210, 220, 88, 120, 28, 87, 139, 82, 243, 179, 155, 81, 107, 80, 78, 38, 9, 128, 21, 88, 54, 123, 247, 253, 25, 123, 177, 189, 136, 209, 242, 162, 16, 73, 69, 112, 181, 84, 125, 45, 86, 88, 101, 133, 85, 220, 161, 119, 96, 163, 176, 79, 255, 59, 37, 90, 56, 16, 45, 28, 136, 22, 14, 68, 11, 7, 162, 133, 3, 209, 194, 129, 104, 225, 240, 59, 0, 0, 255, 255, 193, 108, 28, 164, 14, 189, 96, 131, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}Expect(code).Equals(http.StatusOK)@@ -63,10 +63,10 @@ func TestUnknownUser_LetterAvatarHandler(t *testing.T) {server, _ := mock.NewServer()code, response := server.OnTenant(mock.DemoTenant).+ WithURL("https://demo.test.fider.io/?size=50").AddParam("id", 0).- AddParam("size", 50).AddParam("name", "Jon Snow").- Execute(handlers.Avatar())+ Execute(handlers.Gravatar())expectedAvatar := []byte{137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 50, 0, 0, 0, 50, 8, 2, 0, 0, 0, 145, 93, 31, 230, 0, 0, 2, 137, 73, 68, 65, 84, 120, 156, 236, 152, 75, 79, 19, 81, 20, 199, 255, 3, 51, 244, 65, 95, 80, 74, 43, 160, 149, 135, 36, 5, 177, 169, 137, 40, 42, 209, 152, 200, 74, 19, 87, 110, 248, 84, 126, 7, 227, 70, 23, 110, 140, 137, 154, 248, 32, 33, 152, 72, 20, 13, 6, 8, 62, 210, 74, 209, 218, 161, 239, 55, 237, 152, 67, 167, 37, 141, 36, 222, 139, 19, 202, 226, 254, 114, 51, 28, 78, 239, 220, 249, 245, 204, 205, 153, 73, 101, 237, 225, 61, 28, 63, 58, 218, 45, 112, 48, 66, 139, 7, 161, 197, 131, 208, 226, 65, 104, 241, 32, 180, 120, 16, 90, 60, 8, 45, 30, 132, 22, 15, 242, 127, 157, 237, 61, 133, 241, 243, 20, 124, 120, 141, 76, 162, 177, 164, 130, 145, 41, 156, 24, 134, 205, 65, 255, 22, 114, 248, 21, 198, 151, 143, 40, 230, 143, 74, 203, 100, 129, 219, 71, 129, 210, 165, 103, 44, 54, 92, 190, 5, 187, 107, 127, 142, 98, 130, 163, 23, 167, 39, 176, 244, 20, 234, 246, 145, 104, 253, 77, 232, 26, 57, 105, 26, 214, 222, 97, 251, 59, 180, 42, 122, 188, 152, 184, 8, 179, 21, 211, 115, 120, 254, 0, 187, 21, 150, 101, 12, 221, 91, 138, 9, 253, 39, 41, 136, 108, 96, 125, 25, 105, 21, 153, 36, 194, 235, 120, 255, 10, 245, 210, 14, 140, 48, 174, 100, 104, 181, 58, 26, 95, 178, 82, 106, 201, 199, 163, 248, 246, 153, 130, 114, 169, 29, 90, 165, 2, 149, 199, 238, 162, 157, 164, 254, 68, 244, 171, 158, 175, 238, 98, 229, 13, 215, 74, 70, 55, 136, 149, 5, 212, 106, 232, 148, 105, 39, 221, 184, 139, 241, 16, 172, 246, 67, 44, 99, 180, 86, 124, 11, 11, 143, 145, 138, 83, 236, 232, 165, 205, 62, 55, 143, 43, 183, 209, 235, 109, 171, 22, 128, 68, 12, 47, 31, 97, 241, 9, 194, 27, 168, 148, 41, 227, 25, 196, 236, 29, 186, 179, 204, 24, 221, 32, 154, 196, 34, 52, 58, 58, 49, 56, 138, 201, 25, 152, 45, 8, 206, 66, 141, 210, 230, 99, 128, 185, 90, 157, 50, 186, 204, 52, 90, 144, 244, 191, 154, 70, 71, 103, 31, 134, 198, 104, 72, 141, 124, 173, 74, 205, 98, 249, 197, 222, 92, 137, 90, 63, 27, 204, 213, 26, 11, 34, 112, 129, 130, 103, 247, 145, 207, 234, 73, 171, 77, 15, 202, 69, 58, 246, 15, 97, 242, 18, 5, 233, 29, 26, 77, 82, 170, 30, 40, 102, 198, 171, 49, 87, 43, 249, 91, 15, 134, 167, 244, 192, 210, 13, 127, 128, 130, 66, 22, 185, 52, 5, 212, 214, 247, 202, 118, 238, 42, 53, 207, 58, 146, 132, 209, 198, 41, 153, 29, 198, 171, 49, 87, 43, 22, 33, 51, 151, 7, 103, 130, 240, 249, 233, 185, 235, 242, 64, 81, 232, 163, 213, 183, 250, 156, 108, 18, 171, 75, 56, 59, 131, 190, 1, 220, 156, 167, 130, 85, 138, 176, 247, 232, 61, 34, 165, 226, 199, 38, 227, 213, 36, 142, 223, 183, 76, 22, 132, 174, 147, 83, 147, 82, 129, 156, 194, 107, 45, 211, 124, 126, 4, 166, 225, 116, 239, 103, 106, 53, 108, 109, 226, 211, 162, 126, 175, 13, 214, 170, 99, 181, 195, 225, 134, 44, 211, 27, 75, 34, 70, 155, 250, 64, 186, 157, 176, 57, 233, 205, 162, 84, 160, 54, 198, 252, 216, 169, 195, 223, 32, 242, 25, 26, 255, 36, 151, 162, 113, 88, 142, 233, 219, 169, 208, 226, 65, 104, 241, 32, 180, 120, 16, 90, 60, 8, 45, 30, 132, 22, 15, 66, 139, 135, 63, 1, 0, 0, 255, 255, 117, 91, 183, 108, 67, 255, 85, 68, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}Expect(code).Equals(http.StatusOK)diff --git a/app/handlers/settings_test.go b/app/handlers/settings_test.goindex 9d234b0e6..103fc0fb5 100644--- a/app/handlers/settings_test.go+++ b/app/handlers/settings_test.go@@ -45,7 +45,7 @@ func TestUpdateUserSettingsHandler_ValidName(t *testing.T) {code, _ := server.OnTenant(mock.DemoTenant).AsUser(mock.JonSnow).- ExecutePost(handlers.UpdateUserSettings(), `{ "name": "Jon Stark" }`)+ ExecutePost(handlers.UpdateUserSettings(), `{ "name": "Jon Stark", "avatarType": "gravatar" }`)user, _ := services.Users.GetByEmail("[email protected]")@@ -62,6 +62,7 @@ func TestUpdateUserSettingsHandler_NewSettings(t *testing.T) {AsUser(mock.JonSnow).ExecutePost(handlers.UpdateUserSettings(), `{"name": "Jon Stark",+ "avatarType": "gravatar","settings": {"event_notification_new_post": "1","event_notification_new_comment": "2",diff --git a/app/middlewares/setup.go b/app/middlewares/setup.goindex ad7beb5b0..634c013a8 100644--- a/app/middlewares/setup.go+++ b/app/middlewares/setup.go@@ -62,8 +62,8 @@ func WorkerSetup() worker.MiddlewareFunc {c.SetServices(&app.Services{Tenants: postgres.NewTenantStorage(trx),- Users: postgres.NewUserStorage(trx),- Posts: postgres.NewPostStorage(trx),+ Users: postgres.NewUserStorage(trx, c),+ Posts: postgres.NewPostStorage(trx, c),Tags: postgres.NewTagStorage(trx),Notifications: postgres.NewNotificationStorage(trx),Emailer: di.NewEmailer(c.Logger()),@@ -150,8 +150,8 @@ func WebSetup() web.MiddlewareFunc {c.SetServices(&app.Services{Tenants: tenantStorage,OAuth: web.NewOAuthService(oauthBaseURL, tenantStorage),- Users: postgres.NewUserStorage(trx),- Posts: postgres.NewPostStorage(trx),+ Users: postgres.NewUserStorage(trx, &c),+ Posts: postgres.NewPostStorage(trx, &c),Tags: postgres.NewTagStorage(trx),Notifications: postgres.NewNotificationStorage(trx),Emailer: di.NewEmailer(c.Logger()),diff --git a/app/models/feedback.go b/app/models/feedback.goindex 2ceb76ceb..acd040fbd 100644--- a/app/models/feedback.go+++ b/app/models/feedback.go@@ -22,14 +22,18 @@ type Post struct {Tags []string `json:"tags"`}+//VoteUser represents a user that voted on a post+type VoteUser struct {+ ID int `json:"id"`+ Name string `json:"name"`+ Email string `json:"email,omitempty"`+ AvatarURL string `json:"avatarURL,omitempty"`+}+//Vote represents a vote given by a user on a posttype Vote struct {- User *struct {- ID int `json:"id" db:"id"`- Name string `json:"name" db:"name"`- Email string `json:"email,omitempty" db:"email"`- } `json:"user" db:"user"`- CreatedAt time.Time `json:"createdAt" db:"created_at"`+ User *VoteUser `json:"user"`+ CreatedAt time.Time `json:"createdAt"`}// CanBeVoted returns true if this post can have its vote changeddiff --git a/app/models/identity.go b/app/models/identity.goindex 5905a6a97..a75a6df39 100644--- a/app/models/identity.go+++ b/app/models/identity.go@@ -1,7 +1,6 @@package modelsimport (- "encoding/json""time""github.com/getfider/fider/app/pkg/jwt"@@ -40,36 +39,55 @@ type Upload struct {//User represents an user inside our applicationtype User struct {- ShowEmail bool- ID int- Name string- Email string- Tenant *Tenant- Role Role- Providers []*UserProvider- Status UserStatus-}--// MarshalJSON interface redefinition-func (u User) MarshalJSON() ([]byte, error) {- email := ""- if u.ShowEmail {- email = u.Email- }+ ID int `json:"id"`+ Name string `json:"name"`+ Tenant *Tenant `json:"-"`+ Email string `json:"-"`+ Role Role `json:"role"`+ Providers []*UserProvider `json:"-"`+ AvatarType AvatarType `json:"-"`+ AvatarURL string `json:"avatarURL,omitempty"`+ Status UserStatus `json:"status"`+}++//AvatarType are the possible types of a user avatar+type AvatarType int++var (+ //AvatarTypeLetter is the default avatar type for users+ AvatarTypeLetter AvatarType = 1+ //AvatarTypeGravatar fetches avatar from gravatar (if available)+ AvatarTypeGravatar AvatarType = 2+ //AvatarTypeCustom uses a user uploaded avatar+ AvatarTypeCustom AvatarType = 3+)++var avatarTypesIDs = map[AvatarType]string{+ AvatarTypeLetter: "letter",+ AvatarTypeGravatar: "gravatar",+ AvatarTypeCustom: "custom",+}- return json.Marshal(&struct {- ID int `json:"id"`- Name string `json:"name"`- Email string `json:"email,omitempty"`- Role Role `json:"role"`- Status UserStatus `json:"status"`- }{- ID: u.ID,- Name: u.Name,- Email: email,- Role: u.Role,- Status: u.Status,- })+var avatarTypesName = map[string]AvatarType{+ "letter": AvatarTypeLetter,+ "gravatar": AvatarTypeGravatar,+ "custom": AvatarTypeCustom,+}++// String returns the string version of the user status+func (t AvatarType) String() string {+ return avatarTypesIDs[t]+}++// MarshalText returns the Text version of the avatar type+func (t AvatarType) MarshalText() ([]byte, error) {+ return []byte(avatarTypesIDs[t]), nil+}++// UnmarshalText parse string into a avatar type+func (t *AvatarType) UnmarshalText(text []byte) error {+ *t = avatarTypesName[string(text)]+ return nil}//UserStatus is the status of a user@@ -355,8 +373,9 @@ type CompleteProfile struct {// UpdateUserSettings is the model used to update user's settingstype UpdateUserSettings struct {- Name string `json:"name"`- Settings map[string]string `json:"settings"`+ Name string `json:"name"`+ AvatarType AvatarType `json:"avatarType"`+ Settings map[string]string `json:"settings"`}// CreateUser is the input model to create a new userdiff --git a/app/pkg/dbx/setup.sql b/app/pkg/dbx/setup.sqlindex ffa46bc71..f118bcce3 100644--- a/app/pkg/dbx/setup.sql+++ b/app/pkg/dbx/setup.sql@@ -5,28 +5,28 @@ TRUNCATE TABLE tenants RESTART IDENTITY CASCADE;INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey)VALUES ('Demonstration', 'demo', now(), '', '', '', 1, false, '', '');-INSERT INTO users (name, email, tenant_id, created_at, role, status)-VALUES ('Jon Snow', '[email protected]', 1, now(), 3, 1);+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)+VALUES ('Jon Snow', '[email protected]', 1, now(), 3, 1, 2, '');INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)VALUES (1, 1, 'facebook', 'FB1234', now());-INSERT INTO users (name, email, tenant_id, created_at, role, status)-VALUES ('Arya Stark', '[email protected]', 1, now(), 1, 1);+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)+VALUES ('Arya Stark', '[email protected]', 1, now(), 1, 1, 2, '');INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)VALUES (2, 1, 'google', 'GO5678', now());-INSERT INTO users (name, email, tenant_id, created_at, role, status)-VALUES ('Sansa Stark', '[email protected]', 1, now(), 1, 1);+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)+VALUES ('Sansa Stark', '[email protected]', 1, now(), 1, 1, 2, '');INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey)VALUES ('Avengers', 'avengers', now(), 'feedback.avengers.com', '', '', 1, false, '', '');-INSERT INTO users (name, email, tenant_id, created_at, role, status)-VALUES ('Tony Stark', '[email protected]', 2, now(), 3, 1);+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)+VALUES ('Tony Stark', '[email protected]', 2, now(), 3, 1, 2, '');INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)VALUES (4, 2, 'facebook', 'FB2222', now());-INSERT INTO users (name, email, tenant_id, created_at, role, status)-VALUES ('The Hulk', '[email protected]', 2, now(), 1, 1);+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)+VALUES ('The Hulk', '[email protected]', 2, now(), 1, 1, 2, '');INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)VALUES (5, 2, 'google', 'GO1111', now());diff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex bbe1e9515..9270e6e14 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -138,6 +138,7 @@ func (ctx *Context) Enqueue(task worker.Task) {wc.SetTenant(c.Tenant())wc.SetBaseURL(c.BaseURL())wc.SetLogoURL(c.LogoURL())+ wc.SetAssetsBaseURL(c.TenantAssetsURL(""))return task.Job(wc)}}diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.goindex 511cd9cbb..4a96c0b60 100644--- a/app/pkg/web/renderer.go+++ b/app/pkg/web/renderer.go@@ -226,6 +226,8 @@ func (r *Renderer) Render(w io.Writer, name string, props Props, ctx *Context) {"email": u.Email,"role": u.Role,"status": u.Status,+ "avatarType": u.AvatarType,+ "avatarURL": u.AvatarURL,"isAdministrator": u.IsAdministrator(),"isCollaborator": u.IsCollaborator(),}diff --git a/app/pkg/web/renderer_test.go b/app/pkg/web/renderer_test.goindex 41024299f..f86b5b9bd 100644--- a/app/pkg/web/renderer_test.go+++ b/app/pkg/web/renderer_test.go@@ -14,6 +14,7 @@ import ()func compareRendererResponse(buf *bytes.Buffer, fileName string, ctx *web.Context) {+ // ioutil.WriteFile(env.Path(fileName), []byte(strings.Replace(buf.String(), ctx.ContextID(), "CONTEXT_ID", -1)), 0744)bytes, err := ioutil.ReadFile(env.Path(fileName))Expect(err).IsNil()Expect(strings.Replace(buf.String(), ctx.ContextID(), "CONTEXT_ID", -1)).Equals(string(bytes))@@ -89,10 +90,13 @@ func TestRenderer_AuthenticatedUser(t *testing.T) {buf := new(bytes.Buffer)ctx := newGetContext("https://demo.test.fider.io:3000/", nil)ctx.SetUser(&models.User{- Name: "Jon Snow",- Email: "[email protected]",- Status: models.UserActive,- Role: models.RoleAdministrator,+ ID: 5,+ Name: "Jon Snow",+ Email: "[email protected]",+ Status: models.UserActive,+ Role: models.RoleAdministrator,+ AvatarType: models.AvatarTypeGravatar,+ AvatarURL: "https://demo.test.fider.io:3000/avatars/gravatar/5/Jon%20Snow",})renderer := web.NewRenderer(&models.SystemSettings{}, noop.NewLogger())renderer.Render(buf, "index.html", web.Props{diff --git a/app/pkg/web/testdata/user.html b/app/pkg/web/testdata/user.htmlindex 3d9293deb..6fa85ba69 100755--- a/app/pkg/web/testdata/user.html+++ b/app/pkg/web/testdata/user.html@@ -38,7 +38,7 @@<script id="server-data" type="application/json">- {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider","__user":{"email":"[email protected]","id":0,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}+ {"__assets":{"CSS":["/assets/css/file1.css"],"JS":["/assets/js/file1.js","/assets/js/file2.js"]},"__contextID":"CONTEXT_ID","__currentURL":"https://demo.test.fider.io:3000/","__description":"My Page Description","__favicon":"https://demo.test.fider.io:3000/favicon","__logo":"https://getfider.com/images/logo-100x100.png","__props":null,"__settings":{"baseURL":"https://demo.test.fider.io:3000","buildTime":"","compiler":"","domain":"","environment":"","globalAssetsURL":"https://demo.test.fider.io:3000","googleAnalytics":"","hasLegal":false,"mode":"","oauth":[],"tenantAssetsURL":"https://demo.test.fider.io:3000","version":""},"__tenant":null,"__title":"My Page Title · Fider","__user":{"avatarType":"gravatar","avatarURL":"https://demo.test.fider.io:3000/avatars/gravatar/5/Jon%20Snow","email":"[email protected]","id":5,"isAdministrator":true,"isCollaborator":true,"name":"Jon Snow","role":"administrator","status":"active"}}</script><script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,fetch" crossorigin="anonymous"></script>diff --git a/app/pkg/worker/context.go b/app/pkg/worker/context.goindex 0124108ff..0bd45a511 100644--- a/app/pkg/worker/context.go+++ b/app/pkg/worker/context.go@@ -1,6 +1,8 @@package workerimport (+ "fmt"+"github.com/getfider/fider/app""github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx"@@ -11,15 +13,16 @@ import (//Context holds references to services available for jobstype Context struct {- workerID string- taskName string- services *app.Services- logger log.Logger- db *dbx.Database- baseURL string- logoURL string- user *models.User- tenant *models.Tenant+ workerID string+ taskName string+ services *app.Services+ logger log.Logger+ db *dbx.Database+ baseURL string+ logoURL string+ assetsBaseURL string+ user *models.User+ tenant *models.Tenant}//NewContext creates a new context@@ -50,6 +53,11 @@ func (c *Context) SetLogoURL(logoURL string) {c.logoURL = logoURL}+//SetAssetsBaseURL on context+func (c *Context) SetAssetsBaseURL(assetsBaseURL string) {+ c.assetsBaseURL = assetsBaseURL+}+//SetUser on contextfunc (c *Context) SetUser(user *models.User) {c.user = user@@ -128,3 +136,9 @@ func (c *Context) Failure(err error) error {func (c Context) LogoURL() string {return c.logoURL}++// TenantAssetsURL return the full URL to a tenant-specific static asset+func (c Context) TenantAssetsURL(path string, a ...interface{}) string {+ path = fmt.Sprintf(path, a...)+ return c.assetsBaseURL + path+}diff --git a/app/storage/postgres/common.go b/app/storage/postgres/common.goindex 783739a3d..2360ac0a1 100644--- a/app/storage/postgres/common.go+++ b/app/storage/postgres/common.go@@ -1,10 +1,12 @@package postgresimport (+ "net/url""regexp""strings""github.com/getfider/fider/app/models"+ "github.com/getfider/fider/app/storage")var onlyalphanumeric = regexp.MustCompile("[^a-zA-Z0-9 |]+")@@ -64,3 +66,10 @@ func getViewData(view string) (string, []models.PostStatus, string) {}return condition, statuses, sort}++func buildAvatarURL(ctx storage.Context, avatarType models.AvatarType, id int, name string) string {+ if name == "" {+ name = "-"+ }+ return ctx.TenantAssetsURL("/avatars/%s/%d/%s", avatarType.String(), id, url.PathEscape(name))+}diff --git a/app/storage/postgres/post.go b/app/storage/postgres/post.goindex e5ab5f800..44c8056f4 100644--- a/app/storage/postgres/post.go+++ b/app/storage/postgres/post.go@@ -10,6 +10,7 @@ import ("github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx""github.com/getfider/fider/app/pkg/errors"+ "github.com/getfider/fider/app/storage""github.com/gosimple/slug""github.com/lib/pq")@@ -38,7 +39,7 @@ type dbPost struct {Tags []string `db:"tags"`}-func (i *dbPost) toModel() *models.Post {+func (i *dbPost) toModel(ctx storage.Context) *models.Post {post := &models.Post{ID: i.ID,Number: i.Number,@@ -50,7 +51,7 @@ func (i *dbPost) toModel() *models.Post {VotesCount: i.VotesCount,CommentsCount: i.CommentsCount,Status: models.PostStatus(i.Status),- User: i.User.toModel(),+ User: i.User.toModel(ctx),Tags: i.Tags,}@@ -58,7 +59,7 @@ func (i *dbPost) toModel() *models.Post {post.Response = &models.PostResponse{Text: i.Response.String,RespondedAt: i.RespondedAt.Time,- User: i.ResponseUser.toModel(),+ User: i.ResponseUser.toModel(ctx),}if post.Status == models.PostDuplicate && i.OriginalNumber.Valid {post.Response.Original = &models.OriginalPost{@@ -81,15 +82,15 @@ type dbComment struct {EditedBy *dbUser `db:"edited_by"`}-func (c *dbComment) toModel() *models.Comment {+func (c *dbComment) toModel(ctx storage.Context) *models.Comment {comment := &models.Comment{ID: c.ID,Content: c.Content,CreatedAt: c.CreatedAt,- User: c.User.toModel(),+ User: c.User.toModel(ctx),}if c.EditedAt.Valid {- comment.EditedBy = c.EditedBy.toModel()+ comment.EditedBy = c.EditedBy.toModel(ctx)comment.EditedAt = &c.EditedAt.Time}return comment@@ -100,17 +101,42 @@ type dbStatusCount struct {Count int `db:"count"`}+type dbVote struct {+ User *struct {+ ID int `db:"id"`+ Name string `db:"name"`+ Email string `db:"email"`+ AvatarType int64 `db:"avatar_type"`+ } `db:"user"`+ CreatedAt time.Time `db:"created_at"`+}++func (v *dbVote) toModel(ctx storage.Context) *models.Vote {+ vote := &models.Vote{+ CreatedAt: v.CreatedAt,+ User: &models.VoteUser{+ ID: v.User.ID,+ Name: v.User.Name,+ Email: v.User.Email,+ AvatarURL: buildAvatarURL(ctx, models.AvatarType(v.User.AvatarType), v.User.ID, v.User.Name),+ },+ }+ return vote+}+// PostStorage contains read and write operations for poststype PostStorage struct {trx *dbx.Trxtenant *models.Tenantuser *models.User+ ctx storage.Context}// NewPostStorage creates a new PostStorage-func NewPostStorage(trx *dbx.Trx) *PostStorage {+func NewPostStorage(trx *dbx.Trx, ctx storage.Context) *PostStorage {return &PostStorage{trx: trx,+ ctx: ctx,}}@@ -179,6 +205,7 @@ var (u.email AS user_email,u.role AS user_role,u.status AS user_status,+ u.avatar_type AS user_avatar_type,p.response,p.response_date,r.id AS response_user_id,@@ -186,6 +213,7 @@ var (r.email AS response_user_email,r.role AS response_user_role,r.status AS response_user_status,+ r.avatar_type AS response_user_avatar_type,d.number AS original_number,d.title AS original_title,d.slug AS original_slug,@@ -230,7 +258,7 @@ func (s *PostStorage) getSingle(query string, args ...interface{}) (*models.Postreturn nil, err}- return post.toModel(), nil+ return post.toModel(s.ctx), nil}// GetByID returns post by given id@@ -329,7 +357,7 @@ func (s *PostStorage) Search(query, view, limit string, tags []string) ([]*modelvar result = make([]*models.Post, len(posts))for i, post := range posts {- result[i] = post.toModel()+ result[i] = post.toModel(s.ctx)}return result, nil}@@ -347,11 +375,13 @@ func (s *PostStorage) GetCommentsByPost(post *models.Post) ([]*models.Comment, eu.email AS user_email,u.role AS user_role,u.status AS user_status,+ u.avatar_type AS user_avatar_type,e.id AS edited_by_id,e.name AS edited_by_name,e.email AS edited_by_email,e.role AS edited_by_role,- e.status AS edited_by_status+ e.status AS edited_by_status,+ e.avatar_type AS edited_by_avatar_typeFROM comments cINNER JOIN posts pON p.id = c.post_id@@ -372,7 +402,7 @@ func (s *PostStorage) GetCommentsByPost(post *models.Post) ([]*models.Comment, evar result = make([]*models.Comment, len(comments))for i, comment := range comments {- result[i] = comment.toModel()+ result[i] = comment.toModel(s.ctx)}return result, nil}@@ -457,11 +487,13 @@ func (s *PostStorage) GetCommentByID(id int) (*models.Comment, error) {u.email AS user_email,u.role AS user_role,u.status AS user_status,+ u.avatar_type AS user_avatar_type,e.id AS edited_by_id,e.name AS edited_by_name,e.email AS edited_by_email,e.role AS edited_by_role,- e.status AS edited_by_status+ e.status AS edited_by_status,+ e.avatar_type AS edited_by_avatar_typeFROM comments cINNER JOIN users uON u.id = c.user_id@@ -477,7 +509,7 @@ func (s *PostStorage) GetCommentByID(id int) (*models.Comment, error) {return nil, err}- return comment.toModel(), nil+ return comment.toModel(s.ctx), nil}// UpdateComment with given ID and content@@ -623,7 +655,7 @@ func (s *PostStorage) GetActiveSubscribers(number int, channel models.Notificativar result = make([]*models.User, len(users))for i, user := range users {- result[i] = user.toModel()+ result[i] = user.toModel(s.ctx)}return result, nil}@@ -671,7 +703,7 @@ func (s *PostStorage) MarkAsDuplicate(post *models.Post, original *models.Post)}for _, u := range users {- if err := s.AddVote(original, u.toModel()); err != nil {+ if err := s.AddVote(original, u.toModel(s.ctx)); err != nil {return err}}@@ -730,13 +762,14 @@ func (s *PostStorage) ListVotes(post *models.Post, limit int) ([]*models.Vote, esqlLimit = strconv.Itoa(limit)}- votes := []*models.Vote{}+ votes := []*dbVote{}err := s.trx.Select(&votes, `SELECTpv.created_at,u.id AS user_id,u.name AS user_name,- u.email AS user_email+ u.email AS user_email,+ u.avatar_type AS user_avatar_typeFROM post_votes pvINNER JOIN users uON u.id = pv.user_id@@ -748,5 +781,10 @@ func (s *PostStorage) ListVotes(post *models.Post, limit int) ([]*models.Vote, eif err != nil {return nil, errors.Wrap(err, "failed to get votes of post")}- return votes, nil++ var result = make([]*models.Vote, len(votes))+ for i, vote := range votes {+ result[i] = vote.toModel(s.ctx)+ }+ return result, nil}diff --git a/app/storage/postgres/setup_test.go b/app/storage/postgres/setup_test.goindex d072d6041..06f141fad 100644--- a/app/storage/postgres/setup_test.go+++ b/app/storage/postgres/setup_test.go@@ -1,6 +1,7 @@package postgres_testimport (+ "fmt""os""testing"@@ -28,13 +29,20 @@ var aryaStark *models.Uservar sansaStark *models.Uservar tonyStark *models.User+type Context struct{}++func (c Context) TenantAssetsURL(path string, a ...interface{}) string {+ return "http://cdn.test.fider.io" + fmt.Sprintf(path, a...)+}+func SetupDatabaseTest(t *testing.T) {RegisterT(t)trx, _ = db.Begin()+ ctx := &Context{}tenants = postgres.NewTenantStorage(trx)- users = postgres.NewUserStorage(trx)- posts = postgres.NewPostStorage(trx)+ users = postgres.NewUserStorage(trx, ctx)+ posts = postgres.NewPostStorage(trx, ctx)tags = postgres.NewTagStorage(trx)notifications = postgres.NewNotificationStorage(trx)events = postgres.NewEventStorage(trx)diff --git a/app/storage/postgres/user.go b/app/storage/postgres/user.goindex 06f43ccd4..72581aec4 100644--- a/app/storage/postgres/user.go+++ b/app/storage/postgres/user.go@@ -11,16 +11,18 @@ import ("github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx""github.com/getfider/fider/app/pkg/errors"+ "github.com/getfider/fider/app/storage")type dbUser struct {- ID sql.NullInt64 `db:"id"`- Name sql.NullString `db:"name"`- Email sql.NullString `db:"email"`- Tenant *dbTenant `db:"tenant"`- Role sql.NullInt64 `db:"role"`- Status sql.NullInt64 `db:"status"`- Providers []*dbUserProvider+ ID sql.NullInt64 `db:"id"`+ Name sql.NullString `db:"name"`+ Email sql.NullString `db:"email"`+ Tenant *dbTenant `db:"tenant"`+ Role sql.NullInt64 `db:"role"`+ Status sql.NullInt64 `db:"status"`+ AvatarType sql.NullInt64 `db:"avatar_type"`+ Providers []*dbUserProvider}type dbUserProvider struct {@@ -28,19 +30,22 @@ type dbUserProvider struct {UID sql.NullString `db:"provider_uid"`}-func (u *dbUser) toModel() *models.User {+func (u *dbUser) toModel(ctx storage.Context) *models.User {if u == nil {return nil}+ avatarType := models.AvatarType(u.AvatarType.Int64)user := &models.User{- ID: int(u.ID.Int64),- Name: u.Name.String,- Email: u.Email.String,- Tenant: u.Tenant.toModel(),- Role: models.Role(u.Role.Int64),- Providers: make([]*models.UserProvider, len(u.Providers)),- Status: models.UserStatus(u.Status.Int64),+ ID: int(u.ID.Int64),+ Name: u.Name.String,+ Email: u.Email.String,+ Tenant: u.Tenant.toModel(),+ Role: models.Role(u.Role.Int64),+ Providers: make([]*models.UserProvider, len(u.Providers)),+ Status: models.UserStatus(u.Status.Int64),+ AvatarType: avatarType,+ AvatarURL: buildAvatarURL(ctx, avatarType, int(u.ID.Int64), u.Name.String),}for i, p := range u.Providers {@@ -63,11 +68,12 @@ type UserStorage struct {tenant *models.Tenantuser *models.Usertrx *dbx.Trx+ ctx storage.Context}// NewUserStorage creates a new UserStorage-func NewUserStorage(trx *dbx.Trx) *UserStorage {- return &UserStorage{trx: trx}+func NewUserStorage(trx *dbx.Trx, ctx storage.Context) *UserStorage {+ return &UserStorage{trx: trx, ctx: ctx}}// SetCurrentTenant to current context@@ -82,7 +88,7 @@ func (s *UserStorage) SetCurrentUser(user *models.User) {// GetByID returns a user based on given idfunc (s *UserStorage) GetByID(userID int) (*models.User, error) {- user, err := getUser(s.trx, "id = $1", userID)+ user, err := s.getUser(s.trx, "id = $1", userID)if err != nil {return nil, errors.Wrap(err, "failed to get user with id '%d'", userID)}@@ -91,7 +97,7 @@ func (s *UserStorage) GetByID(userID int) (*models.User, error) {// GetByEmail returns a user based on given emailfunc (s *UserStorage) GetByEmail(email string) (*models.User, error) {- user, err := getUser(s.trx, "email = $1 AND tenant_id = $2", email, s.tenant.ID)+ user, err := s.getUser(s.trx, "email = $1 AND tenant_id = $2", email, s.tenant.ID)if err != nil {return nil, errors.Wrap(err, "failed to get user with email '%s'", email)}@@ -122,8 +128,8 @@ func (s *UserStorage) Register(user *models.User) error {user.Status = models.UserActiveuser.Email = strings.TrimSpace(user.Email)if err := s.trx.Get(&user.ID,- "INSERT INTO users (name, email, created_at, tenant_id, role, status) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id",- user.Name, user.Email, now, s.tenant.ID, user.Role, models.UserActive); err != nil {+ "INSERT INTO users (name, email, created_at, tenant_id, role, status, avatar_type, avatar_bkey) VALUES ($1, $2, $3, $4, $5, $6, $7, '') RETURNING id",+ user.Name, user.Email, now, s.tenant.ID, user.Role, models.UserActive, models.AvatarTypeGravatar); err != nil {return errors.Wrap(err, "failed to register new user")}@@ -148,8 +154,8 @@ func (s *UserStorage) RegisterProvider(userID int, provider *models.UserProvider// Update user profilefunc (s *UserStorage) Update(settings *models.UpdateUserSettings) error {- cmd := "UPDATE users SET name = $2 WHERE id = $1 AND tenant_id = $3"- _, err := s.trx.Execute(cmd, s.user.ID, settings.Name, s.tenant.ID)+ cmd := "UPDATE users SET name = $3, avatar_type = $4 WHERE id = $1 AND tenant_id = $2"+ _, err := s.trx.Execute(cmd, s.user.ID, s.tenant.ID, settings.Name, settings.AvatarType)if err != nil {return errors.Wrap(err, "failed to update user")}@@ -224,9 +230,9 @@ func (s *UserStorage) ChangeEmail(userID int, email string) error {}// GetByID returns a user based on given id-func getUser(trx *dbx.Trx, filter string, args ...interface{}) (*models.User, error) {+func (s *UserStorage) getUser(trx *dbx.Trx, filter string, args ...interface{}) (*models.User, error) {user := dbUser{}- sql := fmt.Sprintf("SELECT id, name, email, tenant_id, role, status FROM users WHERE status != %d AND ", models.UserDeleted)+ sql := fmt.Sprintf("SELECT id, name, email, tenant_id, role, status, avatar_type FROM users WHERE status != %d AND ", models.UserDeleted)err := trx.Get(&user, sql+filter, args...)if err != nil {return nil, err@@ -237,14 +243,14 @@ func getUser(trx *dbx.Trx, filter string, args ...interface{}) (*models.User, erreturn nil, err}- return user.toModel(), nil+ return user.toModel(s.ctx), nil}// GetAll return all users of current tenantfunc (s *UserStorage) GetAll() ([]*models.User, error) {var users []*dbUsererr := s.trx.Select(&users, `- SELECT id, name, email, tenant_id, role, status+ SELECT id, name, email, tenant_id, role, status, avatar_typeFROM usersWHERE tenant_id = $1AND status != $2@@ -255,7 +261,7 @@ func (s *UserStorage) GetAll() ([]*models.User, error) {var result = make([]*models.User, len(users))for i, user := range users {- result[i] = user.toModel()+ result[i] = user.toModel(s.ctx)}return result, nil}@@ -340,7 +346,7 @@ func (s *UserStorage) RegenerateAPIKey() (string, error) {// GetByAPIKey returns a user based on its API keyfunc (s *UserStorage) GetByAPIKey(apiKey string) (*models.User, error) {- user, err := getUser(s.trx, "api_key = $1 AND tenant_id = $2", apiKey, s.tenant.ID)+ user, err := s.getUser(s.trx, "api_key = $1 AND tenant_id = $2", apiKey, s.tenant.ID)if err != nil {return nil, errors.Wrap(err, "failed to get user with API Key '%s'", apiKey)}diff --git a/app/storage/postgres/user_test.go b/app/storage/postgres/user_test.goindex f0f6abac5..fbd5ab458 100644--- a/app/storage/postgres/user_test.go+++ b/app/storage/postgres/user_test.go@@ -21,6 +21,7 @@ func TestUserStorage_GetByID(t *testing.T) {Expect(user.Tenant.ID).Equals(1)Expect(user.Name).Equals("Jon Snow")Expect(user.Email).Equals("[email protected]")+ Expect(user.AvatarURL).Equals("http://cdn.test.fider.io/avatars/gravatar/1/Jon%20Snow")Expect(user.Providers).HasLen(1)Expect(user.Providers[0].UID).Equals("FB1234")Expect(user.Providers[0].Name).Equals("facebook")diff --git a/app/storage/storage.go b/app/storage/storage.goindex 748c5943e..468c28ceb 100644--- a/app/storage/storage.go+++ b/app/storage/storage.go@@ -6,6 +6,11 @@ import ("github.com/getfider/fider/app/models")+// Context holds everything storages need to know about execution context+type Context interface {+ TenantAssetsURL(path string, a ...interface{}) string+}+// Base is a generic storage base interfacetype Base interface {SetCurrentTenant(*models.Tenant)diff --git a/migrations/201812230904_user_avatar_type.sql b/migrations/201812230904_user_avatar_type.sqlnew file mode 100644index 000000000..9e4640c2b--- /dev/null+++ b/migrations/201812230904_user_avatar_type.sql@@ -0,0 +1,8 @@+alter table users add column avatar_type smallint null;+alter table users add column avatar_bkey varchar(512) null;++update users set avatar_type = 2; -- gravatar+update users set avatar_bkey = '';++alter table users alter column avatar_type set not null;+alter table users alter column avatar_bkey set not null;\ No newline at end of filediff --git a/public/components/ShowPostResponse.tsx b/public/components/ShowPostResponse.tsxindex 8589e01e7..9c5985923 100644--- a/public/components/ShowPostResponse.tsx+++ b/public/components/ShowPostResponse.tsx@@ -2,7 +2,7 @@ import "./ShowPostResponse.scss";import React from "react";import { PostResponse, PostStatus } from "@fider/models";-import { Gravatar, MultiLineText, UserName, Segment } from "@fider/components/common";+import { Avatar, MultiLineText, UserName, Segment } from "@fider/components/common";interface ShowPostStatusProps {status: PostStatus;@@ -56,7 +56,7 @@ export const ShowPostResponse = (props: PostResponseProps): JSX.Element => {{status.show && <ShowPostStatus status={status} />}{props.showUser && (<>- <Gravatar user={props.response.user} size="small" /> <UserName user={props.response.user} />+ <Avatar user={props.response.user} size="small" /> <UserName user={props.response.user} /></>)}{status === PostStatus.Duplicate ? DuplicateDetails(props) : StatusDetails(props)}diff --git a/public/components/VoteCounter.spec.tsx b/public/components/VoteCounter.spec.tsxindex 168fec555..bad9e509a 100644--- a/public/components/VoteCounter.spec.tsx+++ b/public/components/VoteCounter.spec.tsx@@ -19,7 +19,8 @@ beforeEach(() => {id: 5,name: "John",role: UserRole.Collaborator,- status: UserStatus.Active+ status: UserStatus.Active,+ avatarURL: "/avatars/letter/5/John"},hasVoted: false,response: null,diff --git a/public/components/common/Gravatar.scss b/public/components/common/Avatar.scsssimilarity index 100%rename from public/components/common/Gravatar.scssrename to public/components/common/Avatar.scssdiff --git a/public/components/common/Avatar.tsx b/public/components/common/Avatar.tsxnew file mode 100644index 000000000..8594e5bc0--- /dev/null+++ b/public/components/common/Avatar.tsx@@ -0,0 +1,25 @@+import "./Avatar.scss";++import React from "react";+import { classSet } from "@fider/services";+import { isCollaborator, UserRole } from "@fider/models";++interface AvatarProps {+ user: {+ role?: UserRole;+ avatarURL: string;+ };+ size?: "small" | "normal" | "large";+}++export const Avatar = (props: AvatarProps) => {+ const size = props.size || "normal";++ const className = classSet({+ "c-avatar": true,+ [`m-${size}`]: true,+ "m-staff": props.user.role && isCollaborator(props.user.role)+ });++ return <img className={className} title={name} src={`${props.user.avatarURL}?size=50`} />;+};diff --git a/public/components/common/Gravatar.tsx b/public/components/common/Gravatar.tsxdeleted file mode 100644index 72c13314c..000000000--- a/public/components/common/Gravatar.tsx+++ /dev/null@@ -1,29 +0,0 @@-import "./Gravatar.scss";--import React from "react";-import { classSet, Fider } from "@fider/services";-import { isCollaborator, UserRole } from "@fider/models";--interface GravatarProps {- user?: {- id: number;- name: string;- role?: UserRole;- };- size?: "small" | "normal" | "large";-}--export const Gravatar = (props: GravatarProps) => {- const size = props.size || "normal";- const id = props.user ? props.user.id : 0;- const name = props.user ? props.user.name : "";- const url = `${Fider.settings.tenantAssetsURL}/avatars/50/${id}/${encodeURIComponent(name || "?")}`;-- const className = classSet({- "c-avatar": true,- [`m-${size}`]: true,- "m-staff": props.user && props.user.role && isCollaborator(props.user.role)- });-- return <img className={className} title={name} src={url} />;-};diff --git a/public/components/common/Header.tsx b/public/components/common/Header.tsxindex aa8c9b2f9..6c2531d82 100644--- a/public/components/common/Header.tsx+++ b/public/components/common/Header.tsx@@ -1,7 +1,7 @@import "./Header.scss";import React from "react";-import { SignInModal, EnvironmentInfo, Gravatar, TenantLogo } from "@fider/components";+import { SignInModal, EnvironmentInfo, Avatar, TenantLogo } from "@fider/components";import { actions, Fider } from "@fider/services";import { FaUser, FaCog, FaCaretDown } from "react-icons/fa";@@ -77,7 +77,7 @@ export class Header extends React.Component<{}, HeaderState> {</a>{showRightMenu && (<div onClick={this.showModal} className="c-menu-item-signin">- {Fider.session.isAuthenticated && <Gravatar user={Fider.session.user} />}+ {Fider.session.isAuthenticated && <Avatar user={Fider.session.user} />}{this.state.unreadNotifications > 0 && <div className="c-unread-dot" />}{!Fider.session.isAuthenticated && <span>Sign in</span>}{Fider.session.isAuthenticated && <FaCaretDown />}diff --git a/public/components/common/index.tsx b/public/components/common/index.tsxindex fa3b7ccf5..6d88ca0cd 100644--- a/public/components/common/index.tsx+++ b/public/components/common/index.tsx@@ -10,7 +10,7 @@ export * from "./form/Field";export * from "./form/Checkbox";export * from "./MultiLineText";export * from "./EnvironmentInfo";-export * from "./Gravatar";+export * from "./Avatar";export * from "./Message";export * from "./Hint";export * from "./Footer";diff --git a/public/models/identity.ts b/public/models/identity.tsindex 22eecfb79..2ea8c4932 100644--- a/public/models/identity.ts+++ b/public/models/identity.ts@@ -14,6 +14,13 @@ export interface User {name: string;role: UserRole;status: UserStatus;+ avatarURL: string;+}++export enum UserAvatarType {+ Letter = "letter",+ Gravatar = "gravatar",+ Custom = "custom"}export enum UserStatus {@@ -36,6 +43,8 @@ export interface CurrentUser {id: number;name: string;email: string;+ avatarType: UserAvatarType;+ avatarURL: string;role: UserRole;status: UserStatus;isAdministrator: boolean;diff --git a/public/models/post.ts b/public/models/post.tsindex c1bb87017..3e5082108 100644--- a/public/models/post.ts+++ b/public/models/post.ts@@ -87,5 +87,6 @@ export interface Vote {id: number;name: string;email: string;+ avatarURL: string;};}diff --git a/public/pages/Administration/pages/ManageMembers.page.tsx b/public/pages/Administration/pages/ManageMembers.page.tsxindex 1d496a349..d4cd7b0f1 100644--- a/public/pages/Administration/pages/ManageMembers.page.tsx+++ b/public/pages/Administration/pages/ManageMembers.page.tsx@@ -1,7 +1,7 @@import "./ManageMembers.page.scss";import React from "react";-import { Segment, List, Input, ListItem, Gravatar, UserName, DropDown, DropDownItem } from "@fider/components/common";+import { Segment, List, Input, ListItem, Avatar, UserName, DropDown, DropDownItem } from "@fider/components/common";import { User, UserRole, UserStatus } from "@fider/models";import { AdminBasePage } from "../components/AdminBasePage";import { FaUsers, FaEllipsisH, FaTimes, FaSearch } from "react-icons/fa";@@ -38,7 +38,7 @@ const UserListItem = (props: UserListItemProps) => {return (<ListItem>- <Gravatar user={props.user} />+ <Avatar user={props.user} /><div className="l-user-details"><UserName user={props.user} /><span>diff --git a/public/pages/MySettings/MySettings.page.tsx b/public/pages/MySettings/MySettings.page.tsxindex 3eb438e22..a01ab8da1 100644--- a/public/pages/MySettings/MySettings.page.tsx+++ b/public/pages/MySettings/MySettings.page.tsx@@ -2,9 +2,9 @@ import "./MySettings.page.scss";import React from "react";-import { Modal, Form, Button, Gravatar, Heading, Field, Input } from "@fider/components";+import { Modal, Form, Button, Heading, Input, Select, SelectOption } from "@fider/components";-import { UserSettings } from "@fider/models";+import { UserSettings, UserAvatarType } from "@fider/models";import { Failure, actions, Fider } from "@fider/services";import { FaRegAddressCard } from "react-icons/fa";import { NotificationSettings } from "./components/NotificationSettings";@@ -15,6 +15,7 @@ interface MySettingsPageState {showModal: boolean;name: string;newEmail: string;+ avatarType: UserAvatarType;changingEmail: boolean;error?: Failure;userSettings: UserSettings;@@ -30,6 +31,7 @@ export default class MySettingsPage extends React.Component<MySettingsPageProps,this.state = {showModal: false,changingEmail: false,+ avatarType: Fider.session.user.avatarType,newEmail: "",name: Fider.session.user.name,userSettings: this.props.userSettings@@ -37,7 +39,7 @@ export default class MySettingsPage extends React.Component<MySettingsPageProps,}private confirm = async () => {- const result = await actions.updateUserSettings(this.state.name, this.state.userSettings);+ const result = await actions.updateUserSettings(this.state.name, this.state.avatarType, this.state.userSettings);if (result.ok) {location.reload();} else if (result.error) {@@ -70,6 +72,12 @@ export default class MySettingsPage extends React.Component<MySettingsPageProps,});};+ private avatarTypeChanged = (opt?: SelectOption) => {+ if (opt) {+ this.setState({ avatarType: opt.value as UserAvatarType });+ }+ };+private setName = (name: string) => {this.setState({ name });};@@ -117,22 +125,6 @@ export default class MySettingsPage extends React.Component<MySettingsPageProps,<div className="row"><div className="col-lg-7"><Form error={this.state.error}>- <Field label="Avatar">- <p>- <Gravatar user={Fider.session.user} />- </p>- <div className="info">- <p>- This site uses{" "}- <a href="https://en.gravatar.com/" target="blank">- Gravatar- </a>{" "}- to display profile avatars. <br />A letter avatar based on your name is generated for profiles- without a Gravatar.- </p>- </div>- </Field>-<Inputlabel="Email"field="email"@@ -161,6 +153,31 @@ export default class MySettingsPage extends React.Component<MySettingsPageProps,<Input label="Name" field="name" value={this.state.name} maxLength={100} onChange={this.setName} />+ <Select+ label="Avatar"+ field="avatarType"+ defaultValue={this.state.avatarType}+ options={[+ { label: "Letter", value: UserAvatarType.Letter },+ { label: "Gravatar", value: UserAvatarType.Gravatar }+ ]}+ onChange={this.avatarTypeChanged}+ >+ {this.state.avatarType === UserAvatarType.Gravatar && (+ <p className="info">+ A{" "}+ <a href="https://en.gravatar.com" target="_blank">+ Gravatar+ </a>{" "}+ will be used based on your email. If you don't have a Gravatar, a letter avatar based on your+ initials is generated for you.+ </p>+ )}+ {this.state.avatarType === UserAvatarType.Letter && (+ <p className="info">A letter avatar based on your initials is generated for you.</p>+ )}+ </Select>+<NotificationSettingsuserSettings={this.props.userSettings}settingsChanged={this.setNotificationSettings}diff --git a/public/pages/ShowPost/ShowPost.page.tsx b/public/pages/ShowPost/ShowPost.page.tsxindex d17e28b8d..4c8835125 100644--- a/public/pages/ShowPost/ShowPost.page.tsx+++ b/public/pages/ShowPost/ShowPost.page.tsx@@ -10,7 +10,7 @@ import {ShowPostResponse,Button,UserName,- Gravatar,+ Avatar,Moment,MultiLineText,List,@@ -104,7 +104,7 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho)}<span className="info">- <Moment date={this.props.post.createdAt} /> · <Gravatar user={this.props.post.user} />{" "}+ <Moment date={this.props.post.createdAt} /> · <Avatar user={this.props.post.user} />{" "}<UserName user={this.props.post.user} /></span></div>diff --git a/public/pages/ShowPost/components/CommentInput.tsx b/public/pages/ShowPost/components/CommentInput.tsxindex 743035d9e..15ecd79b2 100644--- a/public/pages/ShowPost/components/CommentInput.tsx+++ b/public/pages/ShowPost/components/CommentInput.tsx@@ -1,7 +1,7 @@import React from "react";import { Post } from "@fider/models";-import { Gravatar, UserName, Button, TextArea, Form } from "@fider/components/common";+import { Avatar, UserName, Button, TextArea, Form } from "@fider/components/common";import { SignInModal } from "@fider/components";import { cache, actions, Failure, Fider } from "@fider/services";@@ -71,7 +71,7 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu<><SignInModal isOpen={this.state.showSignIn} /><div className={`c-comment-input ${Fider.session.isAuthenticated && "m-authenticated"}`}>- {Fider.session.isAuthenticated && <Gravatar user={Fider.session.user} />}+ {Fider.session.isAuthenticated && <Avatar user={Fider.session.user} />}<Form error={this.state.error}>{Fider.session.isAuthenticated && <UserName user={Fider.session.user} />}<TextAreadiff --git a/public/pages/ShowPost/components/ShowComment.tsx b/public/pages/ShowPost/components/ShowComment.tsxindex d63e22aa9..8ee202d15 100644--- a/public/pages/ShowPost/components/ShowComment.tsx+++ b/public/pages/ShowPost/components/ShowComment.tsx@@ -1,7 +1,7 @@import React from "react";import { Comment, Post } from "@fider/models";import {- Gravatar,+ Avatar,UserName,Moment,Form,@@ -130,7 +130,7 @@ export class ShowComment extends React.Component<ShowCommentProps, ShowCommentStreturn (<div className="c-comment">{this.modal()}- <Gravatar user={c.user} />+ <Avatar user={c.user} /><div className="c-comment-content"><UserName user={c.user} /><div className="c-comment-metadata">diff --git a/public/pages/ShowPost/components/VotesModal.tsx b/public/pages/ShowPost/components/VotesModal.tsxindex bae696d0b..0d5278863 100644--- a/public/pages/ShowPost/components/VotesModal.tsx+++ b/public/pages/ShowPost/components/VotesModal.tsx@@ -2,7 +2,7 @@ import "./VotesModal.scss";import React from "react";import { Post, Vote } from "@fider/models";-import { Modal, Button, Loader, List, ListItem, Gravatar, UserName, Moment, Input } from "@fider/components";+import { Modal, Button, Loader, List, ListItem, Avatar, UserName, Moment, Input } from "@fider/components";import { actions } from "@fider/services";import { FaTimes, FaSearch } from "react-icons/fa";@@ -79,7 +79,7 @@ export class VotesModal extends React.Component<VotesModalProps, VotesModalState<List hover={true}>{this.state.filteredVotes.map(x => (<ListItem key={x.user.id}>- <Gravatar user={x.user} />+ <Avatar user={x.user} /><span className="l-user"><UserName user={x.user} /><span className="info">{x.user.email}</span>diff --git a/public/pages/ShowPost/components/VotesPanel.tsx b/public/pages/ShowPost/components/VotesPanel.tsxindex c9546f4ef..facc84ec2 100644--- a/public/pages/ShowPost/components/VotesPanel.tsx+++ b/public/pages/ShowPost/components/VotesPanel.tsx@@ -2,7 +2,7 @@ import "./VotesPanel.scss";import React from "react";import { Post, Vote } from "@fider/models";-import { Gravatar } from "@fider/components";+import { Avatar } from "@fider/components";import { Fider, classSet } from "@fider/services";import { VotesModal } from "./VotesModal";@@ -50,7 +50,7 @@ export class VotesPanel extends React.Component<VotesPanelProps, VotesPanelState<span className="subtitle">Voters</span><div className="l-votes-list">{this.props.votes.map(x => (- <Gravatar key={x.user.id} user={x.user} />+ <Avatar key={x.user.id} user={x.user} />))}{extraVotesCount > 0 && (<span onClick={this.showModal} className={moreVotesClassName}>diff --git a/public/pages/UI/UIToolkit.page.tsx b/public/pages/UI/UIToolkit.page.tsxindex 708e6a4a5..d4c78b95e 100644--- a/public/pages/UI/UIToolkit.page.tsx+++ b/public/pages/UI/UIToolkit.page.tsx@@ -9,7 +9,7 @@ import {UserName,ListItem,Toggle,- Gravatar,+ Avatar,ShowTag,Segment,Segments,@@ -36,14 +36,16 @@ const jonSnow: User = {id: 0,name: "Jon Snow",role: UserRole.Administrator,- status: UserStatus.Active+ status: UserStatus.Active,+ avatarURL: "/avatars/letter/0/Jon%20Snow"};const aryaStark: User = {id: 0,name: "Arya Snow",role: UserRole.Visitor,- status: UserStatus.Active+ status: UserStatus.Active,+ avatarURL: "/avatars/letter/0/Arya%20Snow"};const easyTag: Tag = { id: 2, slug: "easy", name: "easy", color: "FB3A62", isPublic: true };@@ -175,10 +177,10 @@ export default class UIToolkitPage extends React.Component<{}, UIToolkitPageStat<List><ListItem>- <Gravatar user={jonSnow} /> <UserName user={jonSnow} />+ <Avatar user={jonSnow} /> <UserName user={jonSnow} /></ListItem><ListItem>- <Gravatar user={aryaStark} /> <UserName user={aryaStark} />+ <Avatar user={aryaStark} /> <UserName user={aryaStark} /></ListItem></List>diff --git a/public/services/actions/user.ts b/public/services/actions/user.tsindex d7f2af417..2fd1d7f18 100644--- a/public/services/actions/user.ts+++ b/public/services/actions/user.ts@@ -1,9 +1,14 @@import { http, Result } from "@fider/services/http";-import { UserSettings } from "@fider/models";+import { UserSettings, UserAvatarType } from "@fider/models";-export const updateUserSettings = async (name: string, settings: UserSettings): Promise<Result> => {+export const updateUserSettings = async (+ name: string,+ avatarType: UserAvatarType,+ settings: UserSettings+): Promise<Result> => {return await http.post("/_api/user/settings", {name,+ avatarType,settings});};