From 05cd781b255a55202757d78292e6f484bc2d4837 Mon Sep 17 00:00:00 2001 From: Simon Poole Date: Tue, 18 Aug 2015 22:45:16 +0200 Subject: [PATCH] Remove default enabling of gravatar, check on initial confirmation of e-mail address and on any changes afterward if a gravatar exists and enable then if the user hasn't uploaded a picture. --- app/controllers/user_controller.rb | 21 +++++++++++++++++++ config/locales/en.yml | 2 ++ ...t_default_gravatar_to_false_for_privacy.rb | 9 ++++++++ test/controllers/user_controller_test.rb | 4 ++-- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20131029121300_set_default_gravatar_to_false_for_privacy.rb diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index c8abb4d85..426a96424 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -297,6 +297,7 @@ class UserController < ApplicationController user = token.user user.status = "active" user.email_valid = true + gravatar_enable(user) user.save! referer = token.referer token.destroy @@ -348,6 +349,7 @@ class UserController < ApplicationController @user.email = @user.new_email @user.new_email = nil @user.email_valid = true + gravatar_enable(@user) if @user.save flash[:notice] = t "user.confirm_email.success" else @@ -799,4 +801,23 @@ class UserController < ApplicationController !blocked end + + ## + # check if this user has a gravatar and set the user pref is true + def gravatar_enable(user) + # code from example https://en.gravatar.com/site/implement/images/ruby/ + return if user.image.present? + hash = Digest::MD5.hexdigest(user.email.downcase) + url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back + response = OSM.http_client.get(URI.parse(url)) + oldsetting = user.image_use_gravatar + user.image_use_gravatar = response.success? + if oldsetting != user.image_use_gravatar + flash[:warning] = if user.image_use_gravatar + t "user.account.gravatar.enabled" + else + t "user.account.gravatar.disabled" + end + end + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c8731ee97..effe6075e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1925,6 +1925,8 @@ en: gravatar: "Use Gravatar" link: "http://wiki.openstreetmap.org/wiki/Gravatar" link text: "what is this?" + disabled: "Gravatar disabled!" + enabled: "Gravatar enabled!" new image: "Add an image" keep image: "Keep the current image" delete image: "Remove the current image" diff --git a/db/migrate/20131029121300_set_default_gravatar_to_false_for_privacy.rb b/db/migrate/20131029121300_set_default_gravatar_to_false_for_privacy.rb new file mode 100644 index 000000000..49f94c9de --- /dev/null +++ b/db/migrate/20131029121300_set_default_gravatar_to_false_for_privacy.rb @@ -0,0 +1,9 @@ +class SetDefaultGravatarToFalseForPrivacy < ActiveRecord::Migration + def up + change_column :users, :image_use_gravatar, :boolean, :default => false + end + + def down + change_column :users, :image_use_gravatar, :boolean, :default => true + end +end diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index 8c3b8adcd..60dde019a 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -961,7 +961,7 @@ class UserControllerTest < ActionController::TestCase assert_select "contributor-terms", :count => 1 do assert_select "[agreed='true']" end - assert_select "img", :count => 1 + assert_select "img", :count => 0 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end @@ -1013,7 +1013,7 @@ class UserControllerTest < ActionController::TestCase assert_select "contributor-terms", :count => 1 do assert_select "[agreed='true'][pd='false']" end - assert_select "img", :count => 1 + assert_select "img", :count => 0 assert_select "roles", :count => 1 do assert_select "role", :count => 0 end -- 2.39.5