send the current user

This commit is contained in:
Rimian Perkins 2019-09-13 12:35:38 +10:00
parent 32bf78fa9a
commit cb9af7c258
4 changed files with 21 additions and 3 deletions

View File

@ -1,11 +1,16 @@
# frozen_string_literal: true # frozen_string_literal: true
module DiscoursePatrons module DiscoursePatrons
class PatronsController < ApplicationController class PatronsController < ::ApplicationController
skip_before_action :verify_authenticity_token, only: [:create] skip_before_action :verify_authenticity_token, only: [:create]
def index def index
result = {} result = {}
if current_user
result[:email] = current_user.email
end
render json: result render json: result
end end

View File

@ -48,7 +48,7 @@ export default Ember.Component.extend({
billing.set(key, undefined); billing.set(key, undefined);
} }
}; };
["name", "phone", "email"].forEach(key => deleteEmpty(key)); ["name", "phone"].forEach(key => deleteEmpty(key));
}, },
actions: { actions: {

View File

@ -69,7 +69,6 @@
</div> </div>
<div class="value"> <div class="value">
{{input type="email" value=billing.email}} {{input type="email" value=billing.email}}
<div class="desc">{{i18n 'discourse_patrons.payment.optional'}}</div>
</div> </div>
</div> </div>
<div class="display-row"> <div class="display-row">

View File

@ -11,6 +11,20 @@ module DiscoursePatrons
get :index, format: :json get :index, format: :json
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end 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 end
describe 'create' do describe 'create' do