products admin route and basic pages
This commit is contained in:
parent
b727347b6c
commit
e51aa5f6f0
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscoursePatrons
|
||||
module Admin
|
||||
class ProductsController < ::Admin::AdminController
|
||||
include DiscoursePatrons::Stripe
|
||||
|
||||
before_action :set_api_key
|
||||
|
||||
def index
|
||||
products = ::Stripe::Product.list
|
||||
render_json_dump products.data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,14 +2,6 @@ import DiscourseURL from "discourse/lib/url";
|
|||
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
destroyPlan(plan) {
|
||||
plan.destroy().then(() =>
|
||||
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
|
||||
.get("model")
|
||||
.removeObject(plan)
|
||||
);
|
||||
},
|
||||
|
||||
editPlan(id) {
|
||||
return DiscourseURL.redirectTo(
|
||||
`/admin/plugins/discourse-patrons/plans/${id}`
|
||||
|
|
|
@ -39,7 +39,7 @@ export default Ember.Controller.extend({
|
|||
};
|
||||
|
||||
return ajax("/patrons/subscriptions", { method: "post", data: subscriptionData }).then(
|
||||
subscription => {
|
||||
() => {
|
||||
return DiscourseURL.redirectTo(Discourse.SiteSettings.discourse_patrons_subscription_group_landing_page);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import AdminProduct from "discourse/plugins/discourse-patrons/discourse/models/admin-product";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return AdminProduct.find();
|
||||
},
|
||||
|
||||
actions: {
|
||||
destroyProduct(product) {
|
||||
bootbox.confirm(
|
||||
I18n.t("discourse_patrons.admin.products.operations.destroy.confirm"),
|
||||
I18n.t("no_value"),
|
||||
I18n.t("yes_value"),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||
.get("model")
|
||||
.removeObject(product);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
<table class="table discourse-patrons-admin">
|
||||
<thead>
|
||||
<th></th>
|
||||
<th>{{i18n 'discourse_patrons.admin.products.product.product_id'}}</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
{{#each model as |product|}}
|
||||
|
|
|
@ -9,6 +9,7 @@ DiscoursePatrons::Engine.routes.draw do
|
|||
namespace :admin do
|
||||
resources :plans
|
||||
resources :subscriptions, only: [:index]
|
||||
resources :products, only: [:index]
|
||||
end
|
||||
|
||||
resources :customers, only: [:create]
|
||||
|
|
|
@ -42,6 +42,7 @@ after_initialize do
|
|||
"../app/controllers/concerns/stripe",
|
||||
"../app/controllers/admin_controller",
|
||||
"../app/controllers/admin/plans_controller",
|
||||
"../app/controllers/admin/products_controller",
|
||||
"../app/controllers/admin/subscriptions_controller",
|
||||
"../app/controllers/customers_controller",
|
||||
"../app/controllers/patrons_controller",
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
module DiscoursePatrons
|
||||
module Admin
|
||||
RSpec.describe ProductsController do
|
||||
it 'is a subclass of AdminController' do
|
||||
expect(DiscoursePatrons::Admin::ProductsController < ::Admin::AdminController).to eq(true)
|
||||
end
|
||||
|
||||
context 'unauthenticated' do
|
||||
it "does nothing" do
|
||||
::Stripe::Product.expects(:list).never
|
||||
get "/patrons/admin/products.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
context 'authenticated' do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
it "gets the empty products" do
|
||||
::Stripe::Product.expects(:list)
|
||||
get "/patrons/admin/products.json"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,19 +4,28 @@ require 'rails_helper'
|
|||
|
||||
module DiscoursePatrons
|
||||
RSpec.describe Admin::SubscriptionsController do
|
||||
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
it 'is a subclass of AdminController' do
|
||||
expect(DiscoursePatrons::Admin::SubscriptionsController < ::Admin::AdminController).to eq(true)
|
||||
end
|
||||
|
||||
it "gets the empty subscriptions" do
|
||||
::Stripe::Subscription.expects(:list)
|
||||
get "/patrons/admin/subscriptions.json"
|
||||
expect(response.status).to eq(204)
|
||||
context 'unauthenticated' do
|
||||
it "does nothing" do
|
||||
::Stripe::Subscription.expects(:list).never
|
||||
get "/patrons/admin/subscriptions.json"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
|
||||
context 'authenticated' do
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
it "gets the empty subscriptions" do
|
||||
::Stripe::Subscription.expects(:list)
|
||||
get "/patrons/admin/subscriptions.json"
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue