diff --git a/app/assets/javascripts/users/finish.js b/app/assets/javascripts/users/finish.js index c977b8703..7ac4fb9d5 100644 --- a/app/assets/javascripts/users/finish.js +++ b/app/assets/javascripts/users/finish.js @@ -43,6 +43,7 @@ openFarmApp.controller('finishCtrl', ['$scope', '$http', 'userService', } var userCallback = function(success, user){ + console.log(success, user) $scope.user.sending = false; if (success) { $scope.user = user; diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 78d2886f0..07c9b1ed3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -34,6 +34,10 @@ def index @users = policy_scope(User) end + def edit + authorize current_user + end + def finish authorize current_user end diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index db07e06f0..22c288591 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -20,6 +20,10 @@ def update? @viewed_user == @current_user || @current_user.admin? end + def edit? + @viewed_user == @current_user || @current_user.admin? + end + def finish? @viewed_user == @current_user || @current_user.admin? end diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb new file mode 100644 index 000000000..be74f7112 --- /dev/null +++ b/app/views/users/edit.html.erb @@ -0,0 +1,105 @@ +<% content_for(:start_js) do %> +<%= javascript_include_tag '//maps.google.com/maps/api/js?sensor=false' %> +<% end %> + +
+
+
+

<%= t('.edit_profile') %>

+
+
+<%# form_for :user, controller: 'users', action: 'finish', method: 'put' do |f| %> +
+
+
+ + <%= t('users.finish.city_or_zip') %> +
+
+ + +
+
+
+
+ +
+
+ + + +
+
+ +
+
+ +
+
+
+
+
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + + +
+
+
+<%# end %> +
+ +<% content_for(:end_js) do %> + <%= javascript_tag "var USER_ID = '#{current_user ? current_user._id : nil}';" %> + <%= javascript_include_tag 'users/finish' %> +<% end %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 0999de03c..009be022c 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -90,7 +90,7 @@
<% if current_user == @user %> - <%= link_to t('.application.edit_profile'), users_finish_path, class: 'tiny button secondary' %> + <%= link_to t('.application.edit_profile'), users_edit_path, class: 'tiny button secondary' %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 34d42aa52..70be40129 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -211,6 +211,11 @@ en: Some examples of ways we might ask you to help: organizing community events, translation, etc. next_step: "Next: View Profile" + edit: + edit_profile: "Edit your member profile" + location_placeholder: "Portland, OR, USA" + help_sign_up: "Do you want to help build OpenFarm?" + save: "Save Changes" crops: edit_crop: "Edit crop" add_this_information: "Add this information" diff --git a/config/routes.rb b/config/routes.rb index f9e415ce1..b6615ec26 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,7 @@ devise_scope :users do get 'users/gardens' => 'users#gardens' get 'users/finish' => 'users#finish' + get 'users/edit' => 'users#edit' put 'users' => 'users#update' end resources :users diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 1ee1b4439..b0420f7ed 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -26,6 +26,12 @@ expect(response).to redirect_to root_path(locale: 'en') end + it 'should show the user the edit page' do + sign_in user + get 'edit' + expect(response).to render_template(:edit) + end + it 'should only show public users on index' do private_user = FactoryGirl.create(:user, is_private: true) public_user = FactoryGirl.create(:user) diff --git a/spec/policies/user_policy_spec.rb b/spec/policies/user_policy_spec.rb index 8f540dfe3..513a9d245 100644 --- a/spec/policies/user_policy_spec.rb +++ b/spec/policies/user_policy_spec.rb @@ -34,6 +34,18 @@ end end + permissions :edit? do + it 'denies edit if viewed user is not current user' do + expect(UserPolicy).not_to permit(current_user, other_user) + end + it 'grants edit if user is current user' do + expect(UserPolicy).to permit(current_user, current_user) + end + it 'grants edit if user is admin user' do + expect(UserPolicy).to permit(admin, other_user) + end + end + context "for a user" do it "should only return users on index that are public" do @p = UserPolicy::Scope.new(current_user, User).resolve