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({
|
||||
actions: {
|
||||
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");
|
||||
this.set("model.plan.product_id", productID);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ export default Ember.Controller.extend({
|
|||
},
|
||||
|
||||
redirect(product_id) {
|
||||
DiscourseURL.redirectTo(`/admin/plugins/discourse-patrons/products/${product_id}`);
|
||||
DiscourseURL.redirectTo(
|
||||
`/admin/plugins/discourse-patrons/products/${product_id}`
|
||||
);
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
@ -24,17 +26,20 @@ export default Ember.Controller.extend({
|
|||
createPlan() {
|
||||
// TODO: set default group name beforehand
|
||||
if (this.get("model.plan.metadata.group_name") === undefined) {
|
||||
this.set(
|
||||
"model.plan.metadata",
|
||||
{ group_name: this.get("model.groups.firstObject.name") }
|
||||
);
|
||||
this.set("model.plan.metadata", {
|
||||
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() {
|
||||
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")
|
||||
.save()
|
||||
.then(product => {
|
||||
this.transitionToRoute("adminPlugins.discourse-patrons.products.show", product.id);
|
||||
this.transitionToRoute(
|
||||
"adminPlugins.discourse-patrons.products.show",
|
||||
product.id
|
||||
);
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
},
|
||||
|
|
|
@ -13,7 +13,10 @@ export default Ember.Controller.extend({
|
|||
|
||||
paymentSuccessHandler(paymentIntentId) {
|
||||
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 => {
|
||||
const subscription = this.get("model.subscription");
|
||||
|
||||
subscription.set('customer', customer.id);
|
||||
subscription.set("customer", customer.id);
|
||||
|
||||
if (subscription.get("plan") === undefined) {
|
||||
subscription.set("plan", this.get("model.plans.firstObject.id"));
|
||||
|
@ -35,7 +35,10 @@ export default Ember.Controller.extend({
|
|||
|
||||
subscription.save().then(() => {
|
||||
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 {
|
||||
resource: 'user',
|
||||
path: 'users/:username',
|
||||
resource: "user",
|
||||
path: "users/:username",
|
||||
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) {
|
||||
if (Discourse.User.current()){
|
||||
return Discourse.User.current().username.toLowerCase() === model.username.toLowerCase();
|
||||
export default registerUnbound("user-viewing-self", function(model) {
|
||||
if (Discourse.User.current()) {
|
||||
return (
|
||||
Discourse.User.current().username.toLowerCase() ===
|
||||
model.username.toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -16,10 +16,9 @@ const AdminPlan = Discourse.Model.extend({
|
|||
|
||||
@computed("trial_period_days")
|
||||
parseTrialPeriodDays(trial_period_days) {
|
||||
if(trial_period_days) {
|
||||
if (trial_period_days) {
|
||||
return parseInt(0 + trial_period_days);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -22,8 +22,8 @@ const AdminProduct = Discourse.Model.extend({
|
|||
active: this.active
|
||||
};
|
||||
|
||||
return ajax("/patrons/admin/products", { method: "post", data }).then(product =>
|
||||
AdminProduct.create(product)
|
||||
return ajax("/patrons/admin/products", { method: "post", data }).then(
|
||||
product => AdminProduct.create(product)
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -35,7 +35,10 @@ const AdminProduct = Discourse.Model.extend({
|
|||
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) {
|
||||
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(product =>
|
||||
AdminProduct.create(product)
|
||||
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(
|
||||
product => AdminProduct.create(product)
|
||||
);
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
export default AdminProduct;
|
||||
|
|
|
@ -13,12 +13,16 @@ export default Discourse.Route.extend({
|
|||
I18n.t("yes_value"),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
product.destroy().then(() => {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||
.get("model")
|
||||
.removeObject(product);
|
||||
})
|
||||
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
||||
product
|
||||
.destroy()
|
||||
.then(() => {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsIndex")
|
||||
.get("model")
|
||||
.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({
|
||||
model(params) {
|
||||
const id = params['plan-id'];
|
||||
const product = this.modelFor('adminPlugins.discourse-patrons.products.show').product;
|
||||
const id = params["plan-id"];
|
||||
const product = this.modelFor(
|
||||
"adminPlugins.discourse-patrons.products.show"
|
||||
).product;
|
||||
let plan;
|
||||
|
||||
if(id === 'new') {
|
||||
plan = AdminPlan.create({ active: true, isNew: true, product: product.get('id') });
|
||||
}
|
||||
else {
|
||||
if (id === "new") {
|
||||
plan = AdminPlan.create({
|
||||
active: true,
|
||||
isNew: true,
|
||||
product: product.get("id")
|
||||
});
|
||||
} else {
|
||||
plan = AdminPlan.find(id);
|
||||
}
|
||||
|
||||
|
@ -20,10 +25,10 @@ export default Discourse.Route.extend({
|
|||
},
|
||||
|
||||
renderTemplate() {
|
||||
this.render('adminPlugins.discourse-patrons.products.show.plans.show', {
|
||||
into: 'adminPlugins.discourse-patrons.products',
|
||||
outlet: 'main',
|
||||
controller: 'adminPlugins.discourse-patrons.products.show.plans.show',
|
||||
this.render("adminPlugins.discourse-patrons.products.show.plans.show", {
|
||||
into: "adminPlugins.discourse-patrons.products",
|
||||
outlet: "main",
|
||||
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({
|
||||
model(params) {
|
||||
const product_id = params['product-id'];
|
||||
const product_id = params["product-id"];
|
||||
let product;
|
||||
let plans = [];
|
||||
|
||||
if(product_id === 'new') {
|
||||
if (product_id === "new") {
|
||||
product = AdminProduct.create({ active: true, isNew: true });
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
product = AdminProduct.find(product_id);
|
||||
plans = AdminPlan.findAll({ product_id });
|
||||
}
|
||||
|
@ -26,12 +25,16 @@ export default Discourse.Route.extend({
|
|||
I18n.t("yes_value"),
|
||||
confirmed => {
|
||||
if (confirmed) {
|
||||
plan.destroy().then(() => {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsShow")
|
||||
.get("model.plans")
|
||||
.removeObject(plan);
|
||||
})
|
||||
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
|
||||
plan
|
||||
.destroy()
|
||||
.then(() => {
|
||||
this.controllerFor("adminPluginsDiscoursePatronsProductsShow")
|
||||
.get("model.plans")
|
||||
.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({
|
||||
model() {
|
||||
const toCurrency = (cents) => parseFloat(cents/100).toFixed(2);
|
||||
const toCurrency = cents => parseFloat(cents / 100).toFixed(2);
|
||||
|
||||
const planSelectText = (plan) => {
|
||||
return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${plan.interval}`;
|
||||
const planSelectText = plan => {
|
||||
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();
|
||||
|
||||
return Ember.RSVP.hash({ plans, subscription });
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
return {};
|
||||
|
@ -7,9 +6,8 @@ export default Discourse.Route.extend({
|
|||
setupController(controller, model) {
|
||||
if (this.currentUser.id !== this.modelFor("user").id) {
|
||||
this.replaceWith("userActivity");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
controller.setProperties({ model });
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
// 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] {
|
||||
cursor: not-allowed;
|
||||
background-color: #e9e9e9;
|
||||
border-color: #e9e9e9;
|
||||
input[disabled],
|
||||
input[readonly],
|
||||
select[disabled],
|
||||
select[readonly],
|
||||
textarea[disabled],
|
||||
textarea[readonly] {
|
||||
cursor: not-allowed;
|
||||
background-color: #e9e9e9;
|
||||
border-color: #e9e9e9;
|
||||
}
|
||||
|
||||
.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/plans' => '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
|
||||
|
||||
after_initialize do
|
||||
|
|
|
@ -27,54 +27,6 @@ module DiscoursePatrons
|
|||
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
|
||||
let!(:current_user) { Fabricate(:user) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue