From 18cf0e7f269851096dd02d00c1ccdcae80e1fb89 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Sun, 15 Sep 2019 21:44:10 +1000 Subject: [PATCH] FIX: ordering * Fix broken user id * ascending/descending --- app/controllers/admin_controller.rb | 12 ++++++++++-- app/controllers/patrons_controller.rb | 2 +- .../admin-plugins-discourse-patrons.js.es6 | 7 ++++++- .../routes/admin-plugins-discourse-patrons.js.es6 | 8 +++++++- .../discourse/templates/patrons/show.hbs | 13 ++++++------- .../discourse_patrons/admin_controller_spec.rb | 4 ++++ .../discourse_patrons/patrons_controller_spec.rb | 10 +++++----- 7 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 8f3db55..c798c5c 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -12,9 +12,17 @@ module DiscoursePatrons def payments_order if %w(created_at amount).include?(params[:order]) - params[:order].to_sym + { params[:order] => ascending } else - :created_at + { created_at: :asc } + end + end + + def ascending + if params[:ascending] == 'false' + :desc + else + :asc end end end diff --git a/app/controllers/patrons_controller.rb b/app/controllers/patrons_controller.rb index b31d649..b5f16f9 100644 --- a/app/controllers/patrons_controller.rb +++ b/app/controllers/patrons_controller.rb @@ -38,7 +38,7 @@ module DiscoursePatrons description: SiteSetting.discourse_patrons_payment_description, receipt_email: params[:receipt_email], confirm: true, - customer: user_id + metadata: { user_id: user_id } ) Payment.create( diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 index 2d1ddde..e15a169 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-patrons.js.es6 @@ -1,11 +1,16 @@ export default Ember.Controller.extend({ - queryParams: ["order"], + queryParams: ["order", "ascending"], order: null, + ascending: true, actions: { loadMore() {}, orderPayments(order) { + if (order === this.get("order")) { + this.toggleProperty("ascending"); + } + this.set("order", order); } } diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 index 257b954..0b1b1f3 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-patrons.js.es6 @@ -4,13 +4,19 @@ export default Discourse.Route.extend({ queryParams: { order: { refreshModel: true + }, + ascending: { + refreshModel: true } }, model(params) { return ajax("/patrons/admin", { method: "get", - data: { order: params.order } + data: { + order: params.order, + ascending: params.ascending + } }).then(results => results); } }); diff --git a/assets/javascripts/discourse/templates/patrons/show.hbs b/assets/javascripts/discourse/templates/patrons/show.hbs index 21e881c..96632be 100644 --- a/assets/javascripts/discourse/templates/patrons/show.hbs +++ b/assets/javascripts/discourse/templates/patrons/show.hbs @@ -1,12 +1,11 @@ +{{#unless model.error}} +

{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}

-

{{i18n 'discourse_patrons.heading.success' site_name=siteSettings.title}}

+

+ {{cook-text siteSettings.discourse_patrons_success_page}} +

-

- {{cook-text siteSettings.discourse_patrons_success_page}} -

- -{{#if model}} @@ -17,4 +16,4 @@
{{i18n 'discourse_patrons.payment_intent_id'}}{{model.amount}}
-{{/if}} +{{/unless}} diff --git a/spec/controllers/discourse_patrons/admin_controller_spec.rb b/spec/controllers/discourse_patrons/admin_controller_spec.rb index b22c212..ca478d0 100644 --- a/spec/controllers/discourse_patrons/admin_controller_spec.rb +++ b/spec/controllers/discourse_patrons/admin_controller_spec.rb @@ -9,5 +9,9 @@ module DiscoursePatrons it 'is a subclass of AdminController' do expect(DiscoursePatrons::AdminController < Admin::AdminController).to eq(true) end + + # TODO: authenticate to test these + it "is ascending" + it "is has ordered by" end end diff --git a/spec/controllers/discourse_patrons/patrons_controller_spec.rb b/spec/controllers/discourse_patrons/patrons_controller_spec.rb index 7a326d2..d02c137 100644 --- a/spec/controllers/discourse_patrons/patrons_controller_spec.rb +++ b/spec/controllers/discourse_patrons/patrons_controller_spec.rb @@ -49,13 +49,13 @@ module DiscoursePatrons it 'allows admin to see receipts' do controller.expects(:current_user).returns(admin) - ::Stripe::PaymentIntent.expects(:retrieve).returns(customer: user.id) + ::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: user.id }) get :show, params: { pid: '123' }, format: :json expect(response).to have_http_status(200) end it 'does not allow another the user to see receipts' do - ::Stripe::PaymentIntent.expects(:retrieve).returns(customer: 9999) + ::Stripe::PaymentIntent.expects(:retrieve).returns(metadata: { user_id: 9999 }) get :show, params: { pid: '123' }, format: :json aggregate_failures do @@ -85,7 +85,7 @@ module DiscoursePatrons amount: 9000, receipt_email: 'hello@example.com', currency: 'aud', - customer: current_user.id + metadata: { user_id: current_user.id } } end @@ -134,8 +134,8 @@ module DiscoursePatrons expect(response).to have_http_status(200) end - it 'has the customer id' do - ::Stripe::PaymentIntent.expects(:create).with(has_entry(:customer, current_user.id)).returns(payment) + it 'has the user id' do + ::Stripe::PaymentIntent.expects(:create).with(has_entry(:metadata, { user_id: current_user.id })).returns(payment) post :create, params: {}, format: :json expect(response).to have_http_status(200) end