Merge message when Gravatar status has changed with email confirmation
authorSimon Poole <simon@poole.ch>
Fri, 19 Aug 2016 06:59:40 +0000 (08:59 +0200)
committerSimon Poole <simon@poole.ch>
Fri, 19 Aug 2016 06:59:40 +0000 (08:59 +0200)
Merge message when Gravatar status has changed with email confirmation and make messages more verbose and friendly.

app/controllers/user_controller.rb
config/locales/en.yml
test/controllers/user_controller_test.rb

index a7fcdb2..e7dccd8 100644 (file)
@@ -297,7 +297,9 @@ class UserController < ApplicationController
         user = token.user
         user.status = "active"
         user.email_valid = true
-        gravatar_enable(user)
+        if (gravatar_enable(user))
+           flash[:notice] = gravatar_status_message(user)
+        end
         user.save!
         referer = token.referer
         token.destroy
@@ -349,9 +351,9 @@ class UserController < ApplicationController
         @user.email = @user.new_email
         @user.new_email = nil
         @user.email_valid = true
-        gravatar_enable(@user)
+        changed = gravatar_enable(@user)
         if @user.save
-          flash[:notice] = t "user.confirm_email.success"
+          flash[:notice] = (t "user.confirm_email.success") + (changed ? " " + gravatar_status_message(@user) : "") 
         else
           flash[:errors] = @user.errors
         end
@@ -806,18 +808,22 @@ class UserController < ApplicationController
   # 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?
+    return false 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
+    return oldsetting != user.image_use_gravatar
+  end
+
+  ##
+  # display a message about th current status of the gravatar setting
+  def gravatar_status_message(user)
+    if user.image_use_gravatar
+      return t "user.account.gravatar.enabled"
+    else
+      return t "user.account.gravatar.disabled"
     end
   end
 end
index effe607..0d76f5e 100644 (file)
@@ -1925,8 +1925,8 @@ en:
         gravatar: "Use Gravatar"
         link: "http://wiki.openstreetmap.org/wiki/Gravatar"
         link text: "what is this?"
-        disabled: "Gravatar disabled!"
-        enabled: "Gravatar enabled!"
+        disabled: "No Gravatar for this email address."
+        enabled: "Display of your Gravatar has been enabled."
       new image: "Add an image"
       keep image: "Keep the current image"
       delete image: "Remove the current image"
index a621316..ede8410 100644 (file)
@@ -523,6 +523,7 @@ class UserControllerTest < ActionController::TestCase
   def test_confirm_email_success
     user = users(:second_public_user)
     confirm_string = user.tokens.create.token
+
     post :confirm_email, :confirm_string => confirm_string
     assert_response :redirect
     assert_redirected_to :action => :account, :display_name => user.display_name