]> git.openstreetmap.org Git - rails.git/commitdiff
Remove default enabling of gravatar, check on initial confirmation of e-mail address...
authorSimon Poole <simon@mail.poole.ch>
Tue, 18 Aug 2015 20:45:16 +0000 (22:45 +0200)
committerSimon Poole <simon@poole.ch>
Tue, 16 Aug 2016 19:42:02 +0000 (21:42 +0200)
a gravatar exists and enable then if the user hasn't uploaded a picture.

app/controllers/user_controller.rb
config/locales/en.yml
db/migrate/20131029121300_set_default_gravatar_to_false_for_privacy.rb [new file with mode: 0644]
test/controllers/user_controller_test.rb

index c8abb4d85a3f84ce1389e956b72cad9f558c8319..426a9642472256f079c846ae45d252213d5cd09c 100644 (file)
@@ -297,6 +297,7 @@ class UserController < ApplicationController
         user = token.user
         user.status = "active"
         user.email_valid = true
         user = token.user
         user.status = "active"
         user.email_valid = true
+        gravatar_enable(user)
         user.save!
         referer = token.referer
         token.destroy
         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
         @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
         if @user.save
           flash[:notice] = t "user.confirm_email.success"
         else
@@ -799,4 +801,23 @@ class UserController < ApplicationController
 
     !blocked
   end
 
     !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
 end
index c8731ee97ce6404de116a3810acf51729ddd7b93..effe6075e1efd9afabec4e0d6c7ce83cf824dcb2 100644 (file)
@@ -1925,6 +1925,8 @@ en:
         gravatar: "Use Gravatar"
         link: "http://wiki.openstreetmap.org/wiki/Gravatar"
         link text: "what is this?"
         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"
       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 (file)
index 0000000..49f94c9
--- /dev/null
@@ -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
index 8c3b8adcd88e80fc81a42666695f4de1bdfc97d1..60dde019ab3164566f9dd2ae62704a8885bc8e15 100644 (file)
@@ -961,7 +961,7 @@ class UserControllerTest < ActionController::TestCase
     assert_select "contributor-terms", :count => 1 do
       assert_select "[agreed='true']"
     end
     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
     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 "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
     assert_select "roles", :count => 1 do
       assert_select "role", :count => 0
     end