[ARVADOS] updated: e5e0835b2d374b88e686bf06be0607e10f616e34

git at public.curoverse.com git at public.curoverse.com
Fri Aug 8 20:58:46 EDT 2014


Summary of changes:
 apps/workbench/config/application.default.yml      |  3 --
 services/api/app/mailers/profile_notifier.rb       |  2 +-
 services/api/app/models/user.rb                    | 13 +++++++
 services/api/config/application.default.yml        |  6 +++
 .../functional/arvados/v1/users_controller_test.rb | 43 ++++++++++++++++++++++
 5 files changed, 63 insertions(+), 4 deletions(-)

       via  e5e0835b2d374b88e686bf06be0607e10f616e34 (commit)
       via  a14f6bf083841a868c054e7e00149c6a1bf0b708 (commit)
      from  e5e28415e44e4b3cc1695ba827a1ebc0256fafdd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit e5e0835b2d374b88e686bf06be0607e10f616e34
Author: radhika <radhika at curoverse.com>
Date:   Fri Aug 8 20:57:13 2014 -0400

    3296: profile notification email setting is now on server

diff --git a/apps/workbench/config/application.default.yml b/apps/workbench/config/application.default.yml
index e5c88b2..b639350 100644
--- a/apps/workbench/config/application.default.yml
+++ b/apps/workbench/config/application.default.yml
@@ -132,6 +132,3 @@ common:
   #      - Software developer
   #      - IT
   #      - Other
-
-  # email address to which mail should be sent when the user creates profile for the first time
-  user_profile_notification_address: false

commit a14f6bf083841a868c054e7e00149c6a1bf0b708
Author: radhika <radhika at curoverse.com>
Date:   Fri Aug 8 20:55:49 2014 -0400

    3296: send email when profile is created by user. add tests to profile mailer.

diff --git a/services/api/app/mailers/profile_notifier.rb b/services/api/app/mailers/profile_notifier.rb
index 3863e8a..13e3b34 100644
--- a/services/api/app/mailers/profile_notifier.rb
+++ b/services/api/app/mailers/profile_notifier.rb
@@ -3,6 +3,6 @@ class ProfileNotifier < ActionMailer::Base
 
   def profile_created(user, address)
     @user = user
-    mail(to: address, subject: 'Profile created')
+    mail(to: address, subject: "Profile created by #{@user.email}")
   end
 end
diff --git a/services/api/app/models/user.rb b/services/api/app/models/user.rb
index bcf4d2d..7cd6ac4 100644
--- a/services/api/app/models/user.rb
+++ b/services/api/app/models/user.rb
@@ -13,6 +13,8 @@ class User < ArvadosModel
   before_create :check_auto_admin
   after_create :add_system_group_permission_link
   after_create :send_admin_notifications
+  after_update :send_profile_created_notification
+
 
   has_many :authorized_keys, :foreign_key => :authorized_user_uuid, :primary_key => :uuid
 
@@ -442,4 +444,15 @@ class User < ArvadosModel
       AdminNotifier.new_inactive_user(self).deliver
     end
   end
+
+  # Send notification if the user saved profile for the first time
+  def send_profile_created_notification
+    if self.changes.andand.include?(:prefs)
+      if !self.changes[:prefs][0].andand.keys.andand.any?
+        profile_notification_address = Rails.configuration.user_profile_notification_address
+        ProfileNotifier.profile_created(self, profile_notification_address).deliver if profile_notification_address
+      end
+    end
+  end
+
 end
diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml
index c32900c..ddcaa57 100644
--- a/services/api/config/application.default.yml
+++ b/services/api/config/application.default.yml
@@ -43,6 +43,9 @@ test:
   secret_token: <%= rand(2**512).to_s(36) %>
   blob_signing_key: zfhgfenhffzltr9dixws36j1yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc
 
+  # email address to which mail should be sent when the user creates profile for the first time
+  user_profile_notification_address: arvados at example.com
+
 common:
   uuid_prefix: <%= Digest::MD5.hexdigest(`hostname`).to_i(16).to_s(36)[0..4] %>
 
@@ -173,3 +176,6 @@ common:
   # to sign session tokens. IMPORTANT: This is a site secret. It
   # should be at least 50 characters.
   secret_token: ~
+
+  # email address to which mail should be sent when the user creates profile for the first time
+  user_profile_notification_address: false
diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb
index 2836783..299ae9e 100644
--- a/services/api/test/functional/arvados/v1/users_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/users_controller_test.rb
@@ -842,6 +842,49 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase
     check_active_users_index
   end
 
+  test "update inactive user profile and expect notification email" do
+    authorize_with :admin
+
+    put :update, {
+      id: users(:inactive).uuid,
+      user: {
+        prefs: {:profile => {'organization' => 'Curoverse'}}
+      }
+    }
+    assert_response :success
+
+    found_email = false
+    ActionMailer::Base.deliveries.andand.each do |email|
+      if email.subject == "Profile created by #{users(:inactive).email}"
+        found_email = true
+        break
+      end
+    end
+    assert_equal true, found_email, 'Expected email after creating profile'
+  end
+
+  test "update active user profile and expect no notification email" do
+    authorize_with :admin
+
+    put :update, {
+      id: users(:active).uuid,
+      user: {
+        prefs: {:profile => {'organization' => 'Curoverse'}}
+      }
+    }
+    assert_response :success
+
+    found_email = false
+    ActionMailer::Base.deliveries.andand.each do |email|
+      if email.subject == "Profile created by #{users(:active).email}"
+        found_email = true
+        break
+      end
+    end
+    assert_equal false, found_email, 'Expected no email after updating profile'
+  end
+
+
   NON_ADMIN_USER_DATA = ["uuid", "kind", "is_active", "email", "first_name",
                          "last_name"].sort
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list