fix eslint and rubocop
This commit is contained in:
parent
570ef2fbb4
commit
1f7549060d
|
@ -3,7 +3,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
actions: {
|
actions: {
|
||||||
createPlan() {
|
createPlan() {
|
||||||
if(this.get("model.plan.product_id") === undefined) {
|
if (this.get("model.plan.product_id") === undefined) {
|
||||||
const productID = this.get("model.products.firstObject.id");
|
const productID = this.get("model.products.firstObject.id");
|
||||||
this.set("model.plan.product_id", productID);
|
this.set("model.plan.product_id", productID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,9 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
redirect(product_id) {
|
redirect(product_id) {
|
||||||
DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/products/${product_id}`);
|
DiscourseURL.redirectTo(
|
||||||
|
`/admin/plugins/discourse-patrons/products/${product_id}`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -24,17 +26,20 @@ export default Ember.Controller.extend({
|
||||||
createPlan() {
|
createPlan() {
|
||||||
// TODO: set default group name beforehand
|
// TODO: set default group name beforehand
|
||||||
if (this.get("model.plan.metadata.group_name") === undefined) {
|
if (this.get("model.plan.metadata.group_name") === undefined) {
|
||||||
this.set(
|
this.set("model.plan.metadata", {
|
||||||
"model.plan.metadata",
|
group_name: this.get("model.groups.firstObject.name")
|
||||||
{ group_name: this.get("model.groups.firstObject.name") }
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.get('model.plan').save().then(() => this.redirect(this.productId));
|
this.get("model.plan")
|
||||||
|
.save()
|
||||||
|
.then(() => this.redirect(this.productId));
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePlan() {
|
updatePlan() {
|
||||||
this.get('model.plan').update().then(() => this.redirect(this.productId));
|
this.get("model.plan")
|
||||||
|
.update()
|
||||||
|
.then(() => this.redirect(this.productId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,10 @@ export default Ember.Controller.extend({
|
||||||
this.get("model.product")
|
this.get("model.product")
|
||||||
.save()
|
.save()
|
||||||
.then(product => {
|
.then(product => {
|
||||||
this.transitionToRoute("adminPlugins.discourse-patrons.products.show", product.id);
|
this.transitionToRoute(
|
||||||
|
"adminPlugins.discourse-patrons.products.show",
|
||||||
|
product.id
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,10 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
paymentSuccessHandler(paymentIntentId) {
|
paymentSuccessHandler(paymentIntentId) {
|
||||||
bootbox.alert("ok payment good... some kind of message");
|
bootbox.alert("ok payment good... some kind of message");
|
||||||
this.transitionToRoute("user.billing", Discourse.User.current().username.toLowerCase());
|
this.transitionToRoute(
|
||||||
|
"user.billing",
|
||||||
|
Discourse.User.current().username.toLowerCase()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default Ember.Controller.extend({
|
||||||
}).then(customer => {
|
}).then(customer => {
|
||||||
const subscription = this.get("model.subscription");
|
const subscription = this.get("model.subscription");
|
||||||
|
|
||||||
subscription.set('customer', customer.id);
|
subscription.set("customer", customer.id);
|
||||||
|
|
||||||
if (subscription.get("plan") === undefined) {
|
if (subscription.get("plan") === undefined) {
|
||||||
subscription.set("plan", this.get("model.plans.firstObject.id"));
|
subscription.set("plan", this.get("model.plans.firstObject.id"));
|
||||||
|
@ -35,7 +35,10 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
subscription.save().then(() => {
|
subscription.save().then(() => {
|
||||||
bootbox.alert("ok payment good... some kind of message");
|
bootbox.alert("ok payment good... some kind of message");
|
||||||
this.transitionToRoute("user.billing", Discourse.User.current().username.toLowerCase());
|
this.transitionToRoute(
|
||||||
|
"user.billing",
|
||||||
|
Discourse.User.current().username.toLowerCase()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
resource: 'user',
|
resource: "user",
|
||||||
path: 'users/:username',
|
path: "users/:username",
|
||||||
map() {
|
map() {
|
||||||
this.route('billing');
|
this.route("billing");
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,8 +1,11 @@
|
||||||
import { registerUnbound } from 'discourse-common/lib/helpers';
|
import { registerUnbound } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
export default registerUnbound('user-viewing-self', function(model) {
|
export default registerUnbound("user-viewing-self", function(model) {
|
||||||
if (Discourse.User.current()){
|
if (Discourse.User.current()) {
|
||||||
return Discourse.User.current().username.toLowerCase() === model.username.toLowerCase();
|
return (
|
||||||
|
Discourse.User.current().username.toLowerCase() ===
|
||||||
|
model.username.toLowerCase()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,10 +16,9 @@ const AdminPlan = Discourse.Model.extend({
|
||||||
|
|
||||||
@computed("trial_period_days")
|
@computed("trial_period_days")
|
||||||
parseTrialPeriodDays(trial_period_days) {
|
parseTrialPeriodDays(trial_period_days) {
|
||||||
if(trial_period_days) {
|
if (trial_period_days) {
|
||||||
return parseInt(0 + trial_period_days);
|
return parseInt(0 + trial_period_days);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,8 +22,8 @@ const AdminProduct = Discourse.Model.extend({
|
||||||
active: this.active
|
active: this.active
|
||||||
};
|
};
|
||||||
|
|
||||||
return ajax("/patrons/admin/products", { method: "post", data }).then(product =>
|
return ajax("/patrons/admin/products", { method: "post", data }).then(
|
||||||
AdminProduct.create(product)
|
product => AdminProduct.create(product)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -35,7 +35,10 @@ const AdminProduct = Discourse.Model.extend({
|
||||||
active: this.active
|
active: this.active
|
||||||
};
|
};
|
||||||
|
|
||||||
return ajax(`/patrons/admin/products/${this.id}`, { method: "patch", data });
|
return ajax(`/patrons/admin/products/${this.id}`, {
|
||||||
|
method: "patch",
|
||||||
|
data
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -47,10 +50,10 @@ AdminProduct.reopenClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
find(id) {
|
find(id) {
|
||||||
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(product =>
|
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(
|
||||||
AdminProduct.create(product)
|
product => AdminProduct.create(product)
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default AdminProduct;
|
export default AdminProduct;
|
||||||
|
|
|
@ -13,12 +13,16 @@ export default Discourse.Route.extend({
|
||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
confirmed => {
|
confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
product.destroy().then(() => {
|
product
|
||||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
.destroy()
|
||||||
.get("model")
|
.then(() => {
|
||||||
.removeObject(product);
|
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||||
})
|
.get("model")
|
||||||
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
.removeObject(product);
|
||||||
|
})
|
||||||
|
.catch(data =>
|
||||||
|
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,14 +3,19 @@ import Group from "discourse/models/group";
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model(params) {
|
model(params) {
|
||||||
const id = params['plan-id'];
|
const id = params["plan-id"];
|
||||||
const product = this.modelFor('adminPlugins.discourse-patrons.products.show').product;
|
const product = this.modelFor(
|
||||||
|
"adminPlugins.discourse-patrons.products.show"
|
||||||
|
).product;
|
||||||
let plan;
|
let plan;
|
||||||
|
|
||||||
if(id === 'new') {
|
if (id === "new") {
|
||||||
plan = AdminPlan.create({ active: true, isNew: true, product: product.get('id') });
|
plan = AdminPlan.create({
|
||||||
}
|
active: true,
|
||||||
else {
|
isNew: true,
|
||||||
|
product: product.get("id")
|
||||||
|
});
|
||||||
|
} else {
|
||||||
plan = AdminPlan.find(id);
|
plan = AdminPlan.find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,10 +25,10 @@ export default Discourse.Route.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderTemplate() {
|
renderTemplate() {
|
||||||
this.render('adminPlugins.discourse-patrons.products.show.plans.show', {
|
this.render("adminPlugins.discourse-patrons.products.show.plans.show", {
|
||||||
into: 'adminPlugins.discourse-patrons.products',
|
into: "adminPlugins.discourse-patrons.products",
|
||||||
outlet: 'main',
|
outlet: "main",
|
||||||
controller: 'adminPlugins.discourse-patrons.products.show.plans.show',
|
controller: "adminPlugins.discourse-patrons.products.show.plans.show"
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,14 +3,13 @@ import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admi
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model(params) {
|
model(params) {
|
||||||
const product_id = params['product-id'];
|
const product_id = params["product-id"];
|
||||||
let product;
|
let product;
|
||||||
let plans = [];
|
let plans = [];
|
||||||
|
|
||||||
if(product_id === 'new') {
|
if (product_id === "new") {
|
||||||
product = AdminProduct.create({ active: true, isNew: true });
|
product = AdminProduct.create({ active: true, isNew: true });
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
product = AdminProduct.find(product_id);
|
product = AdminProduct.find(product_id);
|
||||||
plans = AdminPlan.findAll({ product_id });
|
plans = AdminPlan.findAll({ product_id });
|
||||||
}
|
}
|
||||||
|
@ -26,12 +25,16 @@ export default Discourse.Route.extend({
|
||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
confirmed => {
|
confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
plan.destroy().then(() => {
|
plan
|
||||||
this.controllerFor("adminPluginsDiscoursePatronsProductsShow")
|
.destroy()
|
||||||
.get("model.plans")
|
.then(() => {
|
||||||
.removeObject(plan);
|
this.controllerFor("adminPluginsDiscoursePatronsProductsShow")
|
||||||
})
|
.get("model.plans")
|
||||||
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
.removeObject(plan);
|
||||||
|
})
|
||||||
|
.catch(data =>
|
||||||
|
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,13 +4,17 @@ import Subscription from "discourse/plugins/discourse-patrons/discourse/models/s
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model() {
|
model() {
|
||||||
const toCurrency = (cents) => parseFloat(cents/100).toFixed(2);
|
const toCurrency = cents => parseFloat(cents / 100).toFixed(2);
|
||||||
|
|
||||||
const planSelectText = (plan) => {
|
const planSelectText = plan => {
|
||||||
return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${plan.interval}`;
|
return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${
|
||||||
|
plan.interval
|
||||||
|
}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const plans = Plan.findAll().then(results => results.map(p => planSelectText(p)));
|
const plans = Plan.findAll().then(results =>
|
||||||
|
results.map(p => planSelectText(p))
|
||||||
|
);
|
||||||
const subscription = Subscription.create();
|
const subscription = Subscription.create();
|
||||||
|
|
||||||
return Ember.RSVP.hash({ plans, subscription });
|
return Ember.RSVP.hash({ plans, subscription });
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model() {
|
model() {
|
||||||
return {};
|
return {};
|
||||||
|
@ -7,9 +6,8 @@ export default Discourse.Route.extend({
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
if (this.currentUser.id !== this.modelFor("user").id) {
|
if (this.currentUser.id !== this.modelFor("user").id) {
|
||||||
this.replaceWith("userActivity");
|
this.replaceWith("userActivity");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
controller.setProperties({ model });
|
controller.setProperties({ model });
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
// TODO: This gets overridden somewhere. It is defined in common/base/discourse.scss
|
// TODO: This gets overridden somewhere. It is defined in common/base/discourse.scss
|
||||||
input[disabled], input[readonly], select[disabled], select[readonly], textarea[disabled], textarea[readonly] {
|
input[disabled],
|
||||||
cursor: not-allowed;
|
input[readonly],
|
||||||
background-color: #e9e9e9;
|
select[disabled],
|
||||||
border-color: #e9e9e9;
|
select[readonly],
|
||||||
|
textarea[disabled],
|
||||||
|
textarea[readonly] {
|
||||||
|
cursor: not-allowed;
|
||||||
|
background-color: #e9e9e9;
|
||||||
|
border-color: #e9e9e9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.discourse-patrons-section-columns {
|
.discourse-patrons-section-columns {
|
||||||
|
|
|
@ -34,7 +34,7 @@ Discourse::Application.routes.append do
|
||||||
get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index'
|
get '/admin/plugins/discourse-patrons/subscriptions' => 'admin/plugins#index'
|
||||||
get '/admin/plugins/discourse-patrons/plans' => 'admin/plugins#index'
|
get '/admin/plugins/discourse-patrons/plans' => 'admin/plugins#index'
|
||||||
get '/admin/plugins/discourse-patrons/plans/:plan_id' => 'admin/plugins#index'
|
get '/admin/plugins/discourse-patrons/plans/:plan_id' => 'admin/plugins#index'
|
||||||
get 'u/:username/billing' => 'users#show', constraints: {username: USERNAME_ROUTE_FORMAT}
|
get 'u/:username/billing' => 'users#show', constraints: { username: USERNAME_ROUTE_FORMAT }
|
||||||
end
|
end
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
|
@ -27,54 +27,6 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'show' do
|
|
||||||
let!(:admin) { Fabricate(:admin) }
|
|
||||||
let!(:user) { Fabricate(:user) }
|
|
||||||
let(:payment_intent) { { customer: user.id } }
|
|
||||||
|
|
||||||
before do
|
|
||||||
controller.stubs(:current_user).returns(user)
|
|
||||||
::Stripe::PaymentIntent.stubs(:retrieve).returns(payment_intent)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'responds ok' do
|
|
||||||
get :show, params: { pid: '123' }, format: :json
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'requests the payment intent' do
|
|
||||||
::Stripe::PaymentIntent.expects(:retrieve).with('abc-1234').returns(payment_intent)
|
|
||||||
get :show, params: { pid: 'abc-1234' }, format: :json
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'allows admin to see receipts' do
|
|
||||||
controller.expects(:current_user).returns(admin)
|
|
||||||
::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(metadata: { user_id: 9999 })
|
|
||||||
get :show, params: { pid: '123' }, format: :json
|
|
||||||
|
|
||||||
aggregate_failures do
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
expect(JSON.parse(response.body)).to eq("error" => "Not found")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not allow anon user to see receipts' do
|
|
||||||
controller.stubs(:current_user).returns(nil)
|
|
||||||
get :show, params: { pid: '123' }, format: :json
|
|
||||||
|
|
||||||
aggregate_failures do
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
expect(JSON.parse(response.body)).to eq("error" => "Not found")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'create' do
|
describe 'create' do
|
||||||
let!(:current_user) { Fabricate(:user) }
|
let!(:current_user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue