3296: use update method and remove unnecessary update_profile method
authorradhika <radhika@curoverse.com>
Fri, 8 Aug 2014 22:01:11 +0000 (18:01 -0400)
committerradhika <radhika@curoverse.com>
Fri, 8 Aug 2014 22:01:11 +0000 (18:01 -0400)
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/users/profile.html.erb
apps/workbench/config/routes.rb
services/api/app/controllers/arvados/v1/users_controller.rb
services/api/config/routes.rb

index c488023487c93c955bc0fd1016b337ed213f2bb4..ca35bafe667b8077a692c9191086e6cc40b6aef4 100644 (file)
@@ -525,6 +525,7 @@ class ApplicationController < ActionController::Base
       missing_required_profile = false
 
       user_prefs = User.limit(1).where(uuid: current_user.uuid).first.prefs
+      user_prefs = current_user.prefs if !user_prefs[:profile]
       current_user_profile = user_prefs[:profile] if user_prefs
 
       profile_config.kind_of?(Array) && profile_config.andand.each do |entry|
index eb26d40d176468bdc5e534799dc46cdf6aeb1897..67b51a9bc9d043513c82fb6d8b2145a4f0462e68 100644 (file)
@@ -277,39 +277,6 @@ class UsersController < ApplicationController
     end
   end
 
-  def update_profile
-    profile_keys = []
-    profile_config = Rails.configuration.user_profile_form_fields
-    profile_config.andand.each do |entry|
-      profile_keys << entry['key']
-    end
-
-    updated_profile = {}
-    params.andand.each do |param|
-      if profile_keys.include? param[0]
-        if param[1].andand.size>0
-          updated_profile['profile_'+param[0]] = param[1]
-        end
-      end
-    end
-
-    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
-
-    respond_to do |format|
-      format.js {render inline: "location.reload();"}
-    end
-  end
-
   protected
 
   def find_current_links user
index 69c71dce24d2a14fba02d165befedffc476553ad..620b3ee459b530d1dbeccec61174a8f687c284b6 100644 (file)
@@ -26,7 +26,8 @@
             <p> <%=profile_message%> </p><br/>
           </div>
           <div>
-            <%= form_tag update_profile_path, {method: 'put', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal', remote: true} do %>
+            <%= form_tag "/users/#{current_user.uuid}", {method: 'patch', id: 'save_profile_form', name: 'save_profile_form', class: 'form-horizontal'} do %>
+              <%= hidden_field_tag :return_to, request.url %>
               <div class="form-group">
                   <label for="email" class="col-sm-3 control-label"> Email </label>
                   <div class="col-sm-9">
@@ -67,7 +68,7 @@
                     </label>
                     <% if entry['type'] == 'select' %>
                       <div class="col-sm-9">
-                        <select class="form-control" id="<%=entry['key']%>" name="<%=entry['key']%>">
+                        <select class="form-control" id="user[prefs][:profile][:<%=entry['key']%>]" name="user[prefs][:profile][:<%=entry['key']%>]">
                           <% entry['options'].each do |option| %>
                             <option value="<%=option%>" <%='selected' if option==value%>><%=option%></option>
                           <% end %>
@@ -75,7 +76,7 @@
                       </div>
                     <% else %>
                       <div class="col-sm-9">
-                        <input type="text" class="form-control" id="<%=entry['key']%>" name="<%=entry['key']%>" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
+                        <input type="text" class="form-control" id="user[prefs][:profile][:<%=entry['key']%>]" name="user[prefs][:profile][:<%=entry['key']%>]" placeholder="<%=entry['form_field_description']%>" value="<%=value%>" ></input>
                       </div>
                     <% end %>
                   </div>
index b63e8f6478f2d343c10bd6c9c71fecb0d9cf01f9..4ef26612ab194a2df62eefa3945aa1ab75ab5c4e 100644 (file)
@@ -10,7 +10,6 @@ ArvadosWorkbench::Application.routes.draw do
   get '/user_agreements/signatures' => 'user_agreements#signatures'
   get "users/setup_popup" => 'users#setup_popup', :as => :setup_user_popup
   get "users/setup" => 'users#setup', :as => :setup_user
-  put "users/update_profile" => 'users#update_profile', :as => :update_profile
   resources :nodes
   resources :humans
   resources :traits
index 568dd97a103b5c2f8c6db3a37576b049f714384b..a044fb7bfd3ff325cf9678375af2e551d52f78ae 100644 (file)
@@ -114,22 +114,6 @@ class Arvados::V1::UsersController < ApplicationController
     show
   end
 
-  # update profile for the user
-  def profile
-    reload_object_before_update
-
-    # update profile
-    @object.profile params
-
-    # profile update succeeded. send email if requested by the client
-    profile_notification_address = params[:send_profile_notification_email]
-    if profile_notification_address
-      ProfileNotifier.profile_created(@object, profile_notification_address).deliver
-    end
-
-    show
-  end
-
   protected
 
   def self._setup_requires_parameters
index 85991f30e8fcb16d98db13367e8c3f75f60ed812..74d2aea80a77027197638134647e696cc357d0c0 100644 (file)
@@ -52,7 +52,6 @@ Server::Application.routes.draw do
         post 'activate', on: :member
         post 'setup', on: :collection
         post 'unsetup', on: :member
-        post 'profile', on: :member
       end
       resources :virtual_machines do
         get 'logins', on: :member