3296: profile config edge cases
authorradhika <radhika@curoverse.com>
Thu, 7 Aug 2014 03:52:10 +0000 (23:52 -0400)
committerradhika <radhika@curoverse.com>
Thu, 7 Aug 2014 03:52:10 +0000 (23:52 -0400)
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/users/profile.html.erb

index fd3a000ecf0980d4b4f430dcd762e0f609f64517..c488023487c93c955bc0fd1016b337ed213f2bb4 100644 (file)
@@ -515,7 +515,9 @@ class ApplicationController < ActionController::Base
   def check_user_profile
     profile_config = Rails.configuration.user_profile_form_fields
 
-    if request.method.downcase != 'get' || params[:partials]
+    if request.method.downcase != 'get' || params[:partial] ||
+       params[:tab_pane] || params[:action_method] ||
+       params[:action] == 'setup_popup'
       return true
     end
 
@@ -525,7 +527,7 @@ class ApplicationController < ActionController::Base
       user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
       current_user_profile = user_prefs[:profile] if user_prefs
 
-      profile_config.andand.each do |entry|
+      profile_config.kind_of?(Array) && profile_config.andand.each do |entry|
         if entry['required']
           if !current_user_profile || !current_user_profile[entry['key'].to_sym]
             missing_required_profile = true
index d4b917b4dc1655d6e79146fb5429071bede6df16..eb26d40d176468bdc5e534799dc46cdf6aeb1897 100644 (file)
@@ -278,8 +278,6 @@ class UsersController < ApplicationController
   end
 
   def update_profile
-    user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
-
     profile_keys = []
     profile_config = Rails.configuration.user_profile_form_fields
     profile_config.andand.each do |entry|
@@ -295,14 +293,18 @@ class UsersController < ApplicationController
       end
     end
 
-    # Inform server to send mail if this is the first time profile is being created and notification is configured
-    profile_notification_address = Rails.configuration.user_profile_notification_address
-    current_user_profile = user_prefs[:profile] if user_prefs
-    if !current_user_profile && profile_notification_address
-      updated_profile[:send_profile_notification_email] = profile_notification_address
+    if updated_profile.size > 0
+      # Inform server to send mail if this is the first time profile is being created and notification is configured
+      profile_notification_address = Rails.configuration.user_profile_notification_address
+      user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
+      current_user_profile = user_prefs[:profile] if user_prefs
+      if !current_user_profile && profile_notification_address
+        updated_profile[:send_profile_notification_email] = profile_notification_address
+      end
+
+      current_user.update_profile updated_profile
     end
 
-    current_user.update_profile updated_profile
     respond_to do |format|
       format.js {render inline: "location.reload();"}
     end
index 6af3662626e815535b32c4110d71b599c0a801aa..69c71dce24d2a14fba02d165befedffc476553ad 100644 (file)
@@ -1,9 +1,11 @@
-<% 
+<%
     profile_config = Rails.configuration.user_profile_form_fields
     this_user = User.limit(1).where(uuid: current_user.uuid).first
     user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
     current_user_profile = user_prefs[:profile] if user_prefs
+    show_save_button = false
 %>
+
 <div>
     <div class="panel panel-default">
         <div class="panel-heading">
@@ -15,7 +17,7 @@
           <div>
             <% profile_message = 'You can manage your profile using this page. Any feilds in red are required and missing.
                   Please fill in those fields before you can accesse Arvados Workbench.'
-                profile_config.andand.each do |entry| 
+                  profile_config.kind_of?(Array) && profile_config.andand.each do |entry| 
                   if entry['message']
                     profile_message = entry['message']
                     break
                   </div>
               </div>
 
-              <% profile_config.andand.each do |entry| %>
+              <% profile_config.kind_of?(Array) && profile_config.andand.each do |entry| %>
                 <% if entry['key'] %>
                   <%
+                      show_save_button = true
                       label = entry['required'] ? '* ' : ''
                       label += entry['form_field_title']
                       value = current_user_profile[entry['key'].to_sym] if current_user_profile
                 <% end %>
               <% end %>
 
-              <div class="form-group">
-                <div class="col-sm-offset-3 col-sm-9">
-                  <button type="submit" class="btn btn-primary">Save profile</button>
+              <% if show_save_button %>
+                <div class="form-group">
+                  <div class="col-sm-offset-3 col-sm-9">
+                    <button type="submit" class="btn btn-primary">Save profile</button>
+                  </div>
                 </div>
-              </div>
+              <% end %>
             <% end %>
           </div>
         </div>