add link to user

This commit is contained in:
Rimian Perkins 2019-11-13 14:21:21 +11:00
parent 91d9d12371
commit 8aed6b8d30
5 changed files with 30 additions and 3 deletions

View File

@ -31,7 +31,7 @@ module DiscoursePatrons
@subscription = ::Stripe::Subscription.create(
customer: params[:customer],
items: [ { plan: params[:plan] } ],
metadata: { username_lower: current_user.username_lower },
metadata: metadata_user,
)
group = plan_group(plan)
@ -53,6 +53,10 @@ module DiscoursePatrons
private
def metadata_user
{ user_id: current_user.id, username: current_user.username_lower }
end
def plan_group(plan)
Group.find_by_name(plan[:metadata][:group_name])
end

View File

@ -1,6 +1,20 @@
import EmberObject from "@ember/object";
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const AdminSubscription = Discourse.Model.extend({});
const AdminSubscription = Discourse.Model.extend({
@computed("metadata")
user(metadata) {
console.log(metadata);
if (metadata.user_id && metadata.username) {
return EmberObject.create({
id: metadata.user_id,
username: metadata.username
});
}
return false;
}
});
AdminSubscription.reopenClass({
find() {

View File

@ -2,6 +2,7 @@
<table class="table discourse-patrons-table">
<thead>
<tr>
<th>{{i18n 'discourse_patrons.admin.subscriptions.subscription.user'}}</th>
<th>{{i18n 'discourse_patrons.admin.subscriptions.subscription.customer'}}</th>
<th>{{i18n 'discourse_patrons.admin.subscriptions.subscription.plan'}}</th>
<th>{{i18n 'discourse_patrons.admin.subscriptions.subscription.status'}}</th>
@ -10,6 +11,13 @@
</thead>
{{#each model as |subscription|}}
<tr>
<td>
{{#if subscription.user}}
{{#link-to 'adminUser' subscription.user}}
{{subscription.user.username}}
{{/link-to}}
{{/if}}
</td>
<td>{{subscription.customer}}</td>
<td>{{subscription.plan.id}}</td>
<td>{{subscription.status}}</td>

View File

@ -123,6 +123,7 @@ en:
subscriptions:
title: Subscriptions
subscription:
user: User
subscription_id: Subscription ID
customer: Customer
plan: Plan

View File

@ -25,7 +25,7 @@ module DiscoursePatrons
::Stripe::Subscription.expects(:create).with(
customer: 'cus_1234',
items: [ plan: 'plan_1234' ],
metadata: { username_lower: user.username_lower },
metadata: { user_id: user.id, username: user.username_lower },
)
post "/patrons/subscriptions.json", params: { plan: 'plan_1234', customer: 'cus_1234' }
end