From effa6b0f84cfe954cc9dd73f592663b743b0d857 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 16 Oct 2012 20:50:20 -0700 Subject: Some changes to INSTALL file. --- INSTALL.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 18d9c6d..31a3492 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,8 +28,8 @@ Run `bundle install` to install all the required gems. We currently use a git submodule to include srp-js. This will soon be replaced by a ruby gem. but for now you need to run ``` - git submodules init - git submodules update + git submodule init + git submodule update ``` ### Cert Distribution ### @@ -40,5 +40,5 @@ We also ship provider information through the webapp. For now please add your ei ## Running ## -Run `rails server` or whatever rack server you prefer. +Run `rails server`, `bundle exec rails server` or whatever rack server you prefer. -- cgit v1.2.3 From 0b23df922336289b6f8062653b4d3e852ed927ec Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 3 Dec 2012 08:55:49 +0100 Subject: make tests pass on an empty db --- help/app/controllers/tickets_controller.rb | 8 ++++---- help/test/functional/tickets_controller_test.rb | 2 +- users/test/support/stub_record_helper.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 4c7415b..b5f3a63 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -14,7 +14,7 @@ class TicketsController < ApplicationController @ticket.created_by = current_user.id @ticket.email = current_user.email if current_user.email @ticket.comments.last.posted_by = current_user.id - else + else @ticket.comments.last.posted_by = nil #hacky, but protecting this attribute doesn't work right, so this should make sure it isn't set. end @@ -36,11 +36,11 @@ class TicketsController < ApplicationController # @ticket.comments.build # build ticket comments? end - + def update @ticket = Ticket.find(params[:id]) @ticket.attributes = params[:ticket] - + @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) #protecting posted_by isn't working, so this should protect it. if @ticket.save @@ -60,7 +60,7 @@ class TicketsController < ApplicationController end private - + # not using now, as we are using comment_attributes= from the Ticket model =begin def add_comment diff --git a/help/test/functional/tickets_controller_test.rb b/help/test/functional/tickets_controller_test.rb index 6bdb6c7..b9e03ac 100644 --- a/help/test/functional/tickets_controller_test.rb +++ b/help/test/functional/tickets_controller_test.rb @@ -35,7 +35,7 @@ class TicketsControllerTest < ActionController::TestCase params = {:title => "ticket test title", :comments_attributes => {"0" => {"body" =>"body of test ticket"}}} - login User.last + login :email => "test@email.net" assert_difference('Ticket.count') do post :create, :ticket => params diff --git a/users/test/support/stub_record_helper.rb b/users/test/support/stub_record_helper.rb index e744ad7..ede21cf 100644 --- a/users/test/support/stub_record_helper.rb +++ b/users/test/support/stub_record_helper.rb @@ -7,7 +7,7 @@ module StubRecordHelper params.reverse_merge!(klass.valid_attributes_hash) end params[:params] = params.stringify_keys - params.reverse_merge! :id => 123, + params.reverse_merge! :id => "A123", :class => klass, :to_key => ['123'], :to_json => %Q({"stub":"#{klass.name}"}), -- cgit v1.2.3 From 1de597b338f0622a7732676907365de673c34dfb Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 3 Dec 2012 10:24:49 +0100 Subject: enable admin to edit users --- users/app/views/users/_user.html.haml | 3 +++ users/test/functional/users_controller_test.rb | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/users/app/views/users/_user.html.haml b/users/app/views/users/_user.html.haml index 5eb7941..7db0041 100644 --- a/users/app/views/users/_user.html.haml +++ b/users/app/views/users/_user.html.haml @@ -2,6 +2,9 @@ %td= user.login %td= time_ago_in_words(user.created_at) + " ago" %td + = link_to edit_user_path(user), :class => "btn btn-mini btn-primary" do + %i.icon-edit.icon-white + Edit = link_to user_path(user), :method => :delete, :class => "btn btn-danger btn-mini" do %i.icon-remove.icon-white Remove diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index ab29845..f008cda 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -44,8 +44,19 @@ class UsersControllerTest < ActionController::TestCase login user put :update, :user => user.params, :id => user.id, :format => :json assert_equal user, assigns[:user] + assert_response 204 assert_equal " ", @response.body + end + + test "admin can edit user" do + user = stub_record User + user.expects(:update_attributes).with(user.params).returns(true) + User.expects(:find_by_param).with(user.id.to_s).returns(user) + login :is_admin? => true + put :update, :user => user.params, :id => user.id, :format => :json + assert_equal user, assigns[:user] assert_response 204 + assert_equal " ", @response.body end test "admin can destroy user" do -- cgit v1.2.3 From 2a928455f9dcefa465b80b79768ba1d1a423e6e9 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 3 Dec 2012 10:52:01 +0100 Subject: enable users to cancel their account --- users/app/controllers/users_controller.rb | 2 +- users/app/views/users/edit.html.haml | 7 +++++++ users/test/functional/users_controller_test.rb | 13 +++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 3407191..cffc8c6 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -36,7 +36,7 @@ class UsersController < ApplicationController def destroy @user.destroy - redirect_to users_path + redirect_to admin? ? users_path : login_path end protected diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index 8298443..cfcf220 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -1,3 +1,10 @@ .span8.offset2 %h2=t :settings = render 'form' + - if @user == current_user + %legend + =t :cancel_account + %small You will not be able to login anymore. + = link_to user_path(@user), :method => :delete, :class => "btn btn-danger" do + %i.icon-remove.icon-white + Remove my Account diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index f008cda..44b6768 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -63,10 +63,19 @@ class UsersControllerTest < ActionController::TestCase login :is_admin? => true user = stub_record User user.expects(:destroy) - User.expects(:find_by_param).with(user.id.to_s).returns(user) + User.expects(:find_by_param).with(user.id).returns(user) delete :destroy, :id => user.id assert_response :redirect - # assert_redirected_to users_path + assert_redirected_to users_path + end + + test "user can cancel account" do + login + @current_user.expects(:destroy) + User.expects(:find_by_param).with(@current_user.id).returns(@current_user) + delete :destroy, :id => @current_user.id + assert_response :redirect + assert_redirected_to login_path end test "non-admin can't destroy user" do -- cgit v1.2.3 From 1b411de39f38eb0925cf255e941545933f227759 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 3 Dec 2012 14:02:16 +0100 Subject: refactored tests with new find_record helper find_record User will return a stubbed user record and make sure User.find_by_id(user.id) returns the same so it can be used in controllers. --- users/test/functional/users_controller_test.rb | 45 ++++++++++++++++++-------- users/test/support/auth_test_helper.rb | 17 ++-------- users/test/support/stub_record_helper.rb | 26 +++++++++++++-- 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 44b6768..939d105 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -5,6 +5,7 @@ class UsersControllerTest < ActionController::TestCase test "should get new" do get :new + assert_equal User, assigns(:user).class assert_response :success end @@ -12,7 +13,9 @@ class UsersControllerTest < ActionController::TestCase test "should create new user" do user = stub_record User User.expects(:create).with(user.params).returns(user) + post :create, :user => user.params, :format => :json + assert_nil session[:user_id] assert_json_response user assert_response :success @@ -24,70 +27,81 @@ class UsersControllerTest < ActionController::TestCase params.stringify_keys! assert !user.valid? User.expects(:create).with(params).returns(user) + post :create, :user => params, :format => :json + assert_json_error user.errors.messages assert_response 422 end test "should get edit view" do - user = stub_record User - User.expects(:find_by_param).with(user.id.to_s).returns(user) + user = find_record User + login user get :edit, :id => user.id + assert_equal user, assigns[:user] end test "should process updated params" do - user = stub_record User + user = find_record User user.expects(:update_attributes).with(user.params).returns(true) - User.expects(:find_by_param).with(user.id.to_s).returns(user) + login user put :update, :user => user.params, :id => user.id, :format => :json + assert_equal user, assigns[:user] assert_response 204 assert_equal " ", @response.body end - test "admin can edit user" do - user = stub_record User + test "admin can update user" do + user = find_record User user.expects(:update_attributes).with(user.params).returns(true) - User.expects(:find_by_param).with(user.id.to_s).returns(user) + login :is_admin? => true put :update, :user => user.params, :id => user.id, :format => :json + assert_equal user, assigns[:user] assert_response 204 assert_equal " ", @response.body end test "admin can destroy user" do - login :is_admin? => true - user = stub_record User + user = find_record User user.expects(:destroy) - User.expects(:find_by_param).with(user.id).returns(user) + + login :is_admin? => true delete :destroy, :id => user.id + assert_response :redirect assert_redirected_to users_path end test "user can cancel account" do - login - @current_user.expects(:destroy) - User.expects(:find_by_param).with(@current_user.id).returns(@current_user) + user = find_record User + user.expects(:destroy) + + login user delete :destroy, :id => @current_user.id + assert_response :redirect assert_redirected_to login_path end test "non-admin can't destroy user" do - login user = stub_record User + + login delete :destroy, :id => user.id + assert_access_denied end test "admin can list users" do login :is_admin? => true get :index + assert_response :success assert assigns(:users) end @@ -95,12 +109,14 @@ class UsersControllerTest < ActionController::TestCase test "non-admin can't list users" do login get :index + assert_access_denied end test "admin can autocomplete users" do login :is_admin? => true get :index, :format => :json + assert_response :success assert assigns(:users) end @@ -108,6 +124,7 @@ class UsersControllerTest < ActionController::TestCase test "admin can search users" do login :is_admin? => true get :index, :query => "a" + assert_response :success assert assigns(:users) end diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb index e0b673a..f3506ae 100644 --- a/users/test/support/auth_test_helper.rb +++ b/users/test/support/auth_test_helper.rb @@ -10,8 +10,8 @@ module AuthTestHelper end end - def login(user_or_method_hash = nil) - @current_user = stub_user(user_or_method_hash) + def login(user_or_method_hash = {}) + @current_user = stub_record(User, user_or_method_hash) unless @current_user.respond_to? :is_admin? @current_user.stubs(:is_admin?).returns(false) end @@ -28,19 +28,6 @@ module AuthTestHelper end end - protected - - # Will create a stub user for logging in from either - # * a hash of methods to stub - # * a user record - # * nil -> create a user record stub - def stub_user(user_or_method_hash) - if user_or_method_hash.is_a?(Hash) - stub_record User, user_or_method_hash - else - user_or_method_hash || stub_record(User) - end - end end class ActionController::TestCase diff --git a/users/test/support/stub_record_helper.rb b/users/test/support/stub_record_helper.rb index ede21cf..2e1a533 100644 --- a/users/test/support/stub_record_helper.rb +++ b/users/test/support/stub_record_helper.rb @@ -1,19 +1,41 @@ module StubRecordHelper + # Will expect find_by_param or find_by_id to be called on klass and + # return the record given. + # If no record is given but a hash or nil will create a stub based on + # that instead and returns the stub. + def find_record(klass, record_or_method_hash = {}) + record = stub_record(klass, record_or_method_hash) + finder = klass.respond_to?(:find_by_param) ? :find_by_param : :find_by_id + klass.expects(finder).with(record.to_param).returns(record) + return record + end + # Create a stub that has the usual functions of a database record. # It won't fail on rendering a form for example. - def stub_record(klass, params = {}, persisted = true) + # + # If the second parameter is a record we return the record itself. + # This way you can build functions that either take a record or a + # method hash to stub from. See find_record for an example. + def stub_record(klass, record_or_method_hash = {}, persisted = true) + if record_or_method_hash && !record_or_method_hash.is_a?(Hash) + return record_or_method_hash + end + stub record_params_for(klass, record_or_method_hash, persisted) + end + + def record_params_for(klass, params = {}, persisted = true) if klass.respond_to?(:valid_attributes_hash) params.reverse_merge!(klass.valid_attributes_hash) end params[:params] = params.stringify_keys params.reverse_merge! :id => "A123", + :to_param => "A123", :class => klass, :to_key => ['123'], :to_json => %Q({"stub":"#{klass.name}"}), :new_record? => !persisted, :persisted? => persisted - stub params end end -- cgit v1.2.3 From 8730beef827aedd5aa12d25f9ed9690d4898ac47 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 4 Dec 2012 11:11:54 -0800 Subject: Requiring libv8 gem so therubyracer gem will work. --- ui_dependencies.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui_dependencies.rb b/ui_dependencies.rb index 44f8f32..d6636e7 100644 --- a/ui_dependencies.rb +++ b/ui_dependencies.rb @@ -11,6 +11,8 @@ group :assets do gem "coffee-rails", "~> 3.2.2" gem "uglifier", "~> 1.2.7" + # seems to be required for therubyracer: + gem 'libv8', '~> 3.11.8' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'therubyracer', :platforms => :ruby -- cgit v1.2.3 From ea3718c34cccd294865c0dd533db0b4aa18015cc Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 5 Dec 2012 18:04:00 +0100 Subject: trying to work around a gem issue with the ruby racer 0.11.n --- ui_dependencies.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ui_dependencies.rb b/ui_dependencies.rb index d6636e7..454e9a8 100644 --- a/ui_dependencies.rb +++ b/ui_dependencies.rb @@ -11,10 +11,8 @@ group :assets do gem "coffee-rails", "~> 3.2.2" gem "uglifier", "~> 1.2.7" - # seems to be required for therubyracer: - gem 'libv8', '~> 3.11.8' # See https://github.com/sstephenson/execjs#readme for more supported runtimes - gem 'therubyracer', :platforms => :ruby + gem 'therubyracer', "~> 0.10.2", :platforms => :ruby end -- cgit v1.2.3 From 059b6fca8468e7b9a2507f24b84e09ce4b8c3ddd Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Dec 2012 16:03:59 +0100 Subject: seperated login and password changes in settings --- users/app/views/users/_form.html.haml | 18 ++++++++++++------ users/app/views/users/edit.html.haml | 11 +++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/users/app/views/users/_form.html.haml b/users/app/views/users/_form.html.haml index fc835af..39e26a6 100644 --- a/users/app/views/users/_form.html.haml +++ b/users/app/views/users/_form.html.haml @@ -1,9 +1,15 @@ +- only = local_assigns[:only] - html = {:class => 'form-horizontal user form ' + (@user.new_record? ? 'new' : 'edit')} = simple_form_for @user, :validate => true, :format => :json, :html => html do |f| %legend - = @user.new_record? ? t(:signup_message) : t(:edit_settings) - = f.input :login, :input_html => { :id => :srp_username } - = f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } - = f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } - = f.button :submit, :class => 'btn-primary' - = link_to t(:cancel), root_url, :class => :btn + = t(only || :signup_message) + - if !only || only == :change_login + = f.input :login, :input_html => { :id => :srp_username } + - if !only || only == :change_password + = f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } + = f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } + .pull-right + = f.button :submit, :class => 'btn-primary' + - unless only + = link_to t(:cancel), root_url, :class => :btn + .clearfix diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index cfcf220..25da71a 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -1,10 +1,5 @@ .span8.offset2 %h2=t :settings - = render 'form' - - if @user == current_user - %legend - =t :cancel_account - %small You will not be able to login anymore. - = link_to user_path(@user), :method => :delete, :class => "btn btn-danger" do - %i.icon-remove.icon-white - Remove my Account + = render :partial => 'form', :locals => {:only => :change_login} + = render :partial => 'form', :locals => {:only => :change_password} + = render 'cancel_account' if @user == current_user -- cgit v1.2.3 From f65b0bc32fd2785458d4076faf89683effca5031 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 6 Dec 2012 17:00:53 +0100 Subject: forgot to add new partial --- users/app/views/users/_cancel_account.html.haml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 users/app/views/users/_cancel_account.html.haml diff --git a/users/app/views/users/_cancel_account.html.haml b/users/app/views/users/_cancel_account.html.haml new file mode 100644 index 0000000..41580b0 --- /dev/null +++ b/users/app/views/users/_cancel_account.html.haml @@ -0,0 +1,6 @@ +%legend + =t :cancel_account + %small You will not be able to login anymore. += link_to user_path(@user), :method => :delete, :class => "btn btn-danger" do + %i.icon-remove.icon-white + Remove my Account -- cgit v1.2.3 From bc2ead40468f0d9372372f73260d83d30e93bc9a Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 08:30:47 +0100 Subject: bumping version to 0.1.1 This version has basic user and help tickets management --- lib/leap_web/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/leap_web/version.rb b/lib/leap_web/version.rb index 6a74082..ea13457 100644 --- a/lib/leap_web/version.rb +++ b/lib/leap_web/version.rb @@ -1,3 +1,3 @@ module LeapWeb - VERSION = "0.1.0" unless defined?(LeapWeb::VERSION) + VERSION = "0.1.1" unless defined?(LeapWeb::VERSION) end -- cgit v1.2.3 From af101adb7c66201e175642ff0ef99988b42d2df2 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 10:00:21 +0100 Subject: refactored views to ease adding of email form --- users/app/helpers/users_helper.rb | 20 ++++++++++++++++++++ users/app/models/user.rb | 1 + users/app/views/users/_email_field.html.haml | 1 + users/app/views/users/_email_forward_field.html.haml | 1 + users/app/views/users/_form.html.haml | 8 ++------ users/app/views/users/_legend_and_submit.html.haml | 10 ++++++++++ users/app/views/users/_login_field.html.haml | 1 + users/app/views/users/_password_fields.html.haml | 2 ++ users/app/views/users/_signup.html.haml | 2 ++ users/app/views/users/edit.html.haml | 17 ++++++++++++++--- users/app/views/users/new.html.haml | 2 +- 11 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 users/app/views/users/_email_field.html.haml create mode 100644 users/app/views/users/_email_forward_field.html.haml create mode 100644 users/app/views/users/_legend_and_submit.html.haml create mode 100644 users/app/views/users/_login_field.html.haml create mode 100644 users/app/views/users/_password_fields.html.haml create mode 100644 users/app/views/users/_signup.html.haml diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb index 2310a24..dec8904 100644 --- a/users/app/helpers/users_helper.rb +++ b/users/app/helpers/users_helper.rb @@ -1,2 +1,22 @@ module UsersHelper + + def user_form_with(partial, legend, locals) + user_form do |f| + locals.reverse_merge! :legend => legend, :f => f + render :partial => partial, + :layout => 'legend_and_submit', + :locals => locals + end + end + + def user_form + html_class = 'form-horizontal user form ' + html_class += (@user.new_record? ? 'new' : 'edit') + simple_form_for @user, + :validate => true, + :format => :json, + :html => {:class => html_class} do |f| + yield f + end + end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 325c981..ae271ce 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -2,6 +2,7 @@ class User < CouchRest::Model::Base property :login, String, :accessible => true property :email, String, :accessible => true + property :email_forward, String, :accessible => true property :password_verifier, String, :accessible => true property :password_salt, String, :accessible => true diff --git a/users/app/views/users/_email_field.html.haml b/users/app/views/users/_email_field.html.haml new file mode 100644 index 0000000..36bbeca --- /dev/null +++ b/users/app/views/users/_email_field.html.haml @@ -0,0 +1 @@ += f.input :email diff --git a/users/app/views/users/_email_forward_field.html.haml b/users/app/views/users/_email_forward_field.html.haml new file mode 100644 index 0000000..049428f --- /dev/null +++ b/users/app/views/users/_email_forward_field.html.haml @@ -0,0 +1 @@ += f.input :email_forward diff --git a/users/app/views/users/_form.html.haml b/users/app/views/users/_form.html.haml index 39e26a6..cb51175 100644 --- a/users/app/views/users/_form.html.haml +++ b/users/app/views/users/_form.html.haml @@ -3,13 +3,9 @@ = simple_form_for @user, :validate => true, :format => :json, :html => html do |f| %legend = t(only || :signup_message) - - if !only || only == :change_login - = f.input :login, :input_html => { :id => :srp_username } - - if !only || only == :change_password - = f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } - = f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } + = yield .pull-right - = f.button :submit, :class => 'btn-primary' + = f.button :submit - unless only = link_to t(:cancel), root_url, :class => :btn .clearfix diff --git a/users/app/views/users/_legend_and_submit.html.haml b/users/app/views/users/_legend_and_submit.html.haml new file mode 100644 index 0000000..cc172e9 --- /dev/null +++ b/users/app/views/users/_legend_and_submit.html.haml @@ -0,0 +1,10 @@ +%legend + = t(legend) += yield +.pull-right + - if local_assigns[:with_cancel] + = f.button :submit, :class => 'btn-primary' + = link_to t(:cancel), root_url, :class => :btn + - else + = f.button :submit +.clearfix diff --git a/users/app/views/users/_login_field.html.haml b/users/app/views/users/_login_field.html.haml new file mode 100644 index 0000000..8ab36c3 --- /dev/null +++ b/users/app/views/users/_login_field.html.haml @@ -0,0 +1 @@ += f.input :login, :input_html => { :id => :srp_username } diff --git a/users/app/views/users/_password_fields.html.haml b/users/app/views/users/_password_fields.html.haml new file mode 100644 index 0000000..c2e6a69 --- /dev/null +++ b/users/app/views/users/_password_fields.html.haml @@ -0,0 +1,2 @@ += f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } += f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } diff --git a/users/app/views/users/_signup.html.haml b/users/app/views/users/_signup.html.haml new file mode 100644 index 0000000..51bfaef --- /dev/null +++ b/users/app/views/users/_signup.html.haml @@ -0,0 +1,2 @@ += render :partial => 'login_field', :locals => local_assigns += render :partial => 'password_fields', :locals => local_assigns diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index 25da71a..4192959 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -1,5 +1,16 @@ .span8.offset2 %h2=t :settings - = render :partial => 'form', :locals => {:only => :change_login} - = render :partial => 'form', :locals => {:only => :change_password} - = render 'cancel_account' if @user == current_user + %ul.nav.nav-tabs + %li.active + %a{:href => '#account', 'data-toggle' => 'tab'}Account + %li + %a{:href => '#email', 'data-toggle' => 'tab'}Email + + .tab-content + .tab-pane.active#account + = user_form_with 'login_field', :change_login + = user_form_with 'password_fields', :change_password + = render 'cancel_account' if @user == current_user + .tab-pane#email + = user_form_with 'email_field', :set_email_address + = user_form_with 'email_forward_field', :forward_email diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml index c1c4208..81588b1 100644 --- a/users/app/views/users/new.html.haml +++ b/users/app/views/users/new.html.haml @@ -1,3 +1,3 @@ .span8.offset2 %h2=t :signup - = render 'form' + = user_form_with 'signup', :signup_message, :with_cancel => true -- cgit v1.2.3 From a2d343619e752f62cb7e3445803e4491696af391 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 12:30:15 +0100 Subject: using normal requests for user updates except password password requires ajax for secure remote password to work --- users/app/assets/javascripts/users.js.coffee | 5 ++--- users/app/controllers/users_controller.rb | 2 +- users/app/helpers/users_helper.rb | 30 ++++++++++++++++++---------- users/app/views/users/edit.html.haml | 8 ++++---- users/app/views/users/new.html.haml | 2 +- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 76a6d79..9a2af7a 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -29,7 +29,6 @@ $(document).ready -> $('#new_user').submit srp.signup $('#new_session').submit preventDefault $('#new_session').submit srp.login - $('.user.form.edit').submit srp.update - $('.user.form.edit').submit preventDefault + $('.user.form.change_password').submit srp.update + $('.user.form.change_password').submit preventDefault $('.user.typeahead').typeahead({source: pollUsers}); - diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index cffc8c6..320ed96 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -31,7 +31,7 @@ class UsersController < ApplicationController def update @user.update_attributes(params[:user]) - respond_with @user + respond_with @user, :location => edit_user_path(@user) end def destroy diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb index dec8904..5d9eff7 100644 --- a/users/app/helpers/users_helper.rb +++ b/users/app/helpers/users_helper.rb @@ -1,22 +1,32 @@ module UsersHelper - def user_form_with(partial, legend, locals) - user_form do |f| - locals.reverse_merge! :legend => legend, :f => f + def user_form_with(partial, options = {}) + user_form(options) do |f| + options[:f] = f render :partial => partial, :layout => 'legend_and_submit', - :locals => locals + :locals => options end end - def user_form - html_class = 'form-horizontal user form ' - html_class += (@user.new_record? ? 'new' : 'edit') + def user_form(options) simple_form_for @user, - :validate => true, - :format => :json, - :html => {:class => html_class} do |f| + :html => user_form_html_options(options), + :validate => true do |f| yield f end end + + def user_form_html_options(options) + { :class => user_form_html_classes(options).join(" "), + :id => dom_id(@user, options[:legend]) + } + end + + def user_form_html_classes(options) + classes = %W/form-horizontal user form/ + classes << options[:legend] + classes << (@user.new_record? ? 'new' : 'edit') + classes.compact + end end diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index 4192959..b33c19b 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -8,9 +8,9 @@ .tab-content .tab-pane.active#account - = user_form_with 'login_field', :change_login - = user_form_with 'password_fields', :change_password + = user_form_with 'login_field', :legend => :change_login + = user_form_with 'password_fields', :legend => :change_password = render 'cancel_account' if @user == current_user .tab-pane#email - = user_form_with 'email_field', :set_email_address - = user_form_with 'email_forward_field', :forward_email + = user_form_with 'email_field', :legend => :set_email_address + = user_form_with 'email_forward_field', :legend => :forward_email diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml index 81588b1..1814847 100644 --- a/users/app/views/users/new.html.haml +++ b/users/app/views/users/new.html.haml @@ -1,3 +1,3 @@ .span8.offset2 %h2=t :signup - = user_form_with 'signup', :signup_message, :with_cancel => true + = user_form_with 'signup', :legend => :signup_message, :with_cancel => true -- cgit v1.2.3 From 4aff08fe9696d2f6b92f8a8c2bbb2f96a26277e7 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 12:48:04 +0100 Subject: refactor: use seperate form for signup creating and editing users differ so much now it's not worth reusing the complex user_form_with for the signup. --- users/app/helpers/users_helper.rb | 2 +- users/app/views/users/_legend_and_submit.html.haml | 12 +++--------- users/app/views/users/_signup.html.haml | 2 -- users/app/views/users/new.html.haml | 10 +++++++++- 4 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 users/app/views/users/_signup.html.haml diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb index 5d9eff7..b017bca 100644 --- a/users/app/helpers/users_helper.rb +++ b/users/app/helpers/users_helper.rb @@ -9,7 +9,7 @@ module UsersHelper end end - def user_form(options) + def user_form(options = {}) simple_form_for @user, :html => user_form_html_options(options), :validate => true do |f| diff --git a/users/app/views/users/_legend_and_submit.html.haml b/users/app/views/users/_legend_and_submit.html.haml index cc172e9..c20a226 100644 --- a/users/app/views/users/_legend_and_submit.html.haml +++ b/users/app/views/users/_legend_and_submit.html.haml @@ -1,10 +1,4 @@ -%legend - = t(legend) -= yield -.pull-right - - if local_assigns[:with_cancel] - = f.button :submit, :class => 'btn-primary' - = link_to t(:cancel), root_url, :class => :btn - - else - = f.button :submit +%legend= t(legend) +=yield +.pull-right= f.button :submit .clearfix diff --git a/users/app/views/users/_signup.html.haml b/users/app/views/users/_signup.html.haml deleted file mode 100644 index 51bfaef..0000000 --- a/users/app/views/users/_signup.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -= render :partial => 'login_field', :locals => local_assigns -= render :partial => 'password_fields', :locals => local_assigns diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml index 1814847..98cccb0 100644 --- a/users/app/views/users/new.html.haml +++ b/users/app/views/users/new.html.haml @@ -1,3 +1,11 @@ .span8.offset2 %h2=t :signup - = user_form_with 'signup', :legend => :signup_message, :with_cancel => true + = user_form do |f| + %legend= t(:signup_message) + = render :partial => 'login_field', :locals => {:f => f} + = render :partial => 'password_fields', :locals => {:f => f} + .pull-right + = f.button :submit, :class => 'btn-primary' + = link_to t(:cancel), root_url, :class => :btn + .clearfix + -- cgit v1.2.3 From 85be030a434cfab4b7728e4883624d362ec7afbd Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 13:00:44 +0100 Subject: first stub at displaying success messages --- app/views/layouts/_messages.html.haml | 5 +++++ app/views/layouts/application.html.haml | 2 +- users/app/controllers/users_controller.rb | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 app/views/layouts/_messages.html.haml diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml new file mode 100644 index 0000000..80e34d4 --- /dev/null +++ b/app/views/layouts/_messages.html.haml @@ -0,0 +1,5 @@ +- flash.each do |name, msg| + - if msg.is_a?(String) + %div{:class => "alert alert-#{name == :notice ? "success" : "error"}"} + %a.close{"data-dismiss" => "alert"} × + = content_tag :div, msg, :id => "flash_#{name}" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a57d65e..e6d22f0 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -18,6 +18,6 @@ .content .row .span12 - //= render 'layouts/messages' + = render 'layouts/messages' = yield %footer diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 320ed96..24db13b 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -22,7 +22,9 @@ class UsersController < ApplicationController end def create - @user = User.create(params[:user]) + if @user = User.create(params[:user]) + flash[:notice] = t(:user_created_successfully) + end respond_with @user end @@ -30,7 +32,9 @@ class UsersController < ApplicationController end def update - @user.update_attributes(params[:user]) + if @user.update_attributes(params[:user]) + flash[:notice] = t(:user_updated_successfully) + end respond_with @user, :location => edit_user_path(@user) end -- cgit v1.2.3 From b6c32177efa351e6550840ad508b59c4e722fbb6 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 14:17:57 +0100 Subject: adding a bunch of translation --- users/app/views/users/_legend_and_submit.html.haml | 2 +- users/config/locales/en.yml | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/users/app/views/users/_legend_and_submit.html.haml b/users/app/views/users/_legend_and_submit.html.haml index c20a226..6fc0e4a 100644 --- a/users/app/views/users/_legend_and_submit.html.haml +++ b/users/app/views/users/_legend_and_submit.html.haml @@ -1,4 +1,4 @@ %legend= t(legend) =yield -.pull-right= f.button :submit +.pull-right= f.button :submit, :value => t(legend) .clearfix diff --git a/users/config/locales/en.yml b/users/config/locales/en.yml index 1260494..fe7e824 100644 --- a/users/config/locales/en.yml +++ b/users/config/locales/en.yml @@ -6,9 +6,29 @@ en: login_message: "Please login with your account." wrong_password: "wrong password" user_not_found: "could not be found" + change_login: "Change Login" + change_password: "Change Password" + cancel_account: "Cancel your account" + set_email_address: "Set email address" + forward_email: "Forward email" + email_aliases: "Email aliases" + user_updated_successfully: "Settings have been updated successfully." + user_created_successfully: "Successfully created your account." activemodel: models: user: one: User other: "%{count} Users" + simple_form: + labels: + user: + email_forward: "Email forward" + hints: + user: + email_forward: "Forward all emails to this address" + email: "Your leap web email address" + placeholders: + user: + email_forward: "my_other_email@domain.net" + -- cgit v1.2.3 From 7273dab05b68f033de26bb68cca4b72c17b9908a Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 14:24:10 +0100 Subject: fixed signup and removed flash that was not getting displayed I also tried flash.keep(:notice) but that did not help - not sure how to keep the flash until the root url has rendered. --- users/app/assets/javascripts/users.js.coffee | 2 +- users/app/controllers/users_controller.rb | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/users/app/assets/javascripts/users.js.coffee b/users/app/assets/javascripts/users.js.coffee index 9a2af7a..0595292 100644 --- a/users/app/assets/javascripts/users.js.coffee +++ b/users/app/assets/javascripts/users.js.coffee @@ -3,7 +3,7 @@ preventDefault = (event) -> srp.session = new srp.Session() srp.signedUp = -> - srp.login + srp.login() srp.loggedIn = -> window.location = '/' diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 24db13b..4921a4a 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -22,9 +22,7 @@ class UsersController < ApplicationController end def create - if @user = User.create(params[:user]) - flash[:notice] = t(:user_created_successfully) - end + @user = User.create(params[:user]) respond_with @user end -- cgit v1.2.3 From bfe61e5132b379461425ce868e980e3a1ea0260a Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 7 Dec 2012 14:32:25 +0100 Subject: fixed test to work with edit view that includes email and email forward. --- users/test/functional/users_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index 939d105..1840a72 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -35,7 +35,7 @@ class UsersControllerTest < ActionController::TestCase end test "should get edit view" do - user = find_record User + user = find_record User, :email => nil, :email_forward => nil login user get :edit, :id => user.id -- cgit v1.2.3