Skip to content

Commit

Permalink
Merge pull request #658 from simonv3/fix-648-ambigious-buttons
Browse files Browse the repository at this point in the history
Fix 648 ambigious buttons
  • Loading branch information
simonv3 committed Jul 7, 2015
2 parents 9ef43ee + f67f694 commit c1601f4
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/users/finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def index
@users = policy_scope(User)
end

def edit
authorize current_user
end

def finish
authorize current_user
end
Expand Down
4 changes: 4 additions & 0 deletions app/policies/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 105 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<% content_for(:start_js) do %>
<%= javascript_include_tag '//maps.google.com/maps/api/js?sensor=false' %>
<% end %>

<div class="finish"
ng-controller="finishCtrl">
<div class="row title">
<div class="large-12 columns">
<h2><%= t('.edit_profile') %></h2>
</div>
</div>
<%# form_for :user, controller: 'users', action: 'finish', method: 'put' do |f| %>
<form>
<div class="row">
<div class="large-4 columns">
<label for="location">
<%= t('users.finish.where_do_you_farm') %>
</label>
<small><%= t('users.finish.city_or_zip') %></small>
</div>
<div class="large-8 columns">
<span location
ng-model="user.user_setting.location"
loading-text="<%= t('application.loading_locations') %>">
</span>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<label for="units_preference">
<%= t('users.finish.units_preference') %>
</label>
</div>
<div class="large-8 columns">
<input type="radio" id="units-imperial" value="imperial" name="units" ng-model="user.user_setting.units"><label for="units-imperial">Imperial</label>

<input id="units-metric" type="radio" value="metric" name="units" ng-model="user.user_setting.units" checked><label for="units-metric">Metric</label>
</div>
</div>

<div class="row">
<div class="columns large-4">
<label for="user[images]">Choose a profile image!</label>
</div>
<div class="columns large-8">
<div id="user_image_upload"
name="user[images]"
s3-upload
bucket="'<%= ENV['S3_BUCKET_NAME'] %>'"
ng-model="s3upload"
s3-upload-existing-pictures="user.user_setting.picture"
s3-upload-place-pic="placeUserUpload(image)"
s3-upload-options="{getOptionsUri: '/api/aws/s3_access_token', folder: 'temp/'}">
</div>
</div>
</div>


<div class="row">
<div class="large-4 columns">
<label for="location">
<%= t('users.finish.email_sign_up') %>
</label>
</div>
<div class="large-8 columns">
<input type="radio" id="yes-email" value="true" name="mailing_list" ng-checked="user.mailing_list" ><label for="yes-email">Yes</label>
<input id="no-email" type="radio" value="false" name="mailing_list" checked ng-checked="!user.mailing_list"><label for="no-email">No</label>
</div>
</div>

<div class="row">
<div class="large-4 columns">
<label for="help_sign_up">
<%= t('.help_sign_up') %>
<br/><small><%= t('users.finish.help_description') %></small>
</label>

</div>
<div class="large-8 columns">
<input type="radio" id="yes-help" value="true" name="help_list" ng-checked="user.help_list" ><label for="yes-help">Yes</label>
<input id="no-help" type="radio" value="false" name="help_list" ng-checked="!user.help_list" checked><label for="no-help">No</label>
</div>
</div>

<div class="row submit">
<div class="large-12 columns">
<span class="right">
<input class="button small"
ng-disabled="user.sending"
data-disable-with="Saving..."
name="commit"
type="submit"
ng-click="submitForm()"
value="<%= t('.save') %>"/>
</span>
</div>
</div>
</form>
<%# end %>
</div>

<% content_for(:end_js) do %>
<%= javascript_tag "var USER_ID = '#{current_user ? current_user._id : nil}';" %>
<%= javascript_include_tag 'users/finish' %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<!-- Sidebar for medium and up screens -->
<div class="medium-4 large-3 show-for-medium-up columns profile-sidebar">
<% 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' %>
<button class="button tiny secondary" ng-click="editing = !editing"><%= t('.edit_favorite_crop') %></button>

<p class="member ">
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/policies/user_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1601f4

Please sign in to comment.