diff --git a/app/controllers/patrons_controller.rb b/app/controllers/patrons_controller.rb index 548778c..9417a0d 100644 --- a/app/controllers/patrons_controller.rb +++ b/app/controllers/patrons_controller.rb @@ -1,11 +1,16 @@ # frozen_string_literal: true module DiscoursePatrons - class PatronsController < ApplicationController + class PatronsController < ::ApplicationController skip_before_action :verify_authenticity_token, only: [:create] def index result = {} + + if current_user + result[:email] = current_user.email + end + render json: result end diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index 071812d..63a5a65 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -48,7 +48,7 @@ export default Ember.Component.extend({ billing.set(key, undefined); } }; - ["name", "phone", "email"].forEach(key => deleteEmpty(key)); + ["name", "phone"].forEach(key => deleteEmpty(key)); }, actions: { diff --git a/assets/javascripts/discourse/templates/components/donation-form.hbs b/assets/javascripts/discourse/templates/components/donation-form.hbs index dcfa501..d1c3165 100644 --- a/assets/javascripts/discourse/templates/components/donation-form.hbs +++ b/assets/javascripts/discourse/templates/components/donation-form.hbs @@ -69,7 +69,6 @@
{{input type="email" value=billing.email}} -
{{i18n 'discourse_patrons.payment.optional'}}
diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index f55154c..17e4f9a 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -11,6 +11,20 @@ module DiscoursePatrons get :index, format: :json expect(response).to have_http_status(200) end + + it 'has a current user email' do + user = Fabricate(:user, email: 'hello@example.com') + controller.expects(:current_user).at_least(1).returns(user) + + get :index, format: :json + + expect(JSON.parse(response.body)['email']).to eq 'hello@example.com' + end + + it 'has no current user email' do + get :index, format: :json + expect(JSON.parse(response.body)['email']).to be_nil + end end describe 'create' do