Skip to content
Permalink
Browse files

Add trust level setting to levels

  • Loading branch information...
joebuhlig committed Mar 12, 2018
1 parent d008ce2 commit f6fb75d16725a3a4f159205e8cafc98016a4ffdd
@@ -30,6 +30,7 @@ def create
name: params[:league_level][:name],
enabled: params[:league_level][:enabled],
group: params[:league_level][:group],
trust_level: params[:league_level][:trust_level] || 0,
initial_payment: params[:league_level][:initial_payment],
recurring: params[:league_level][:recurring],
recurring_payment: params[:league_level][:recurring_payment],
@@ -58,6 +59,7 @@ def update
league_level[0][:name] = params[:league_level][:name] if !params[:league_level][:name].nil?
league_level[0][:enabled] = params[:league_level][:enabled] if !params[:league_level][:enabled].nil?
league_level[0][:group] = params[:league_level][:group] if !params[:league_level][:group].nil?
league_level[0][:trust_level] = params[:league_level][:trust_level] if !params[:league_level][:trust_level].nil?
league_level[0][:initial_payment] = params[:league_level][:initial_payment] if !params[:league_level][:initial_payment].nil?
league_level[0][:recurring] = params[:league_level][:recurring] if !params[:league_level][:recurring].nil?
league_level[0][:recurring_payment] = params[:league_level][:recurring_payment] if !params[:league_level][:recurring_payment].nil?
@@ -93,7 +95,7 @@ def show
private

def league_level_params
params.permit(league_level: [:enabled, :name, :group, :initial_payment, :recurring, :recurring_payment, :recurring_payment_period, :trial, :trial_payment, :description_raw, :description_cooked, :welcome_message])[:league_level]
params.permit(league_level: [:enabled, :name, :group, :trust_level, :initial_payment, :recurring, :recurring_payment, :recurring_payment_period, :trial, :trial_payment, :description_raw, :description_cooked, :welcome_message])[:league_level]
end
end
end
@@ -17,6 +17,11 @@ def show
level[0][:user_subscribed] = true
level[0][:subscription_id] = user_subscription[0][:id]
end
if current_user.trust_level >= level[0]["trust_level"]
level[0][:user_insufficient_tl] = false
else
level[0][:user_insufficient_tl] = true
end
else
level[0][:user_subscribed] = false
end
@@ -9,6 +9,7 @@ export default Ember.Controller.extend({
var a = [];
a.set('name', I18n.t('admin.league.levels.new_name'));
a.set('enabled', false);
a.set('trust_level', 0);
return a;
}.property('model.@each.id'),

@@ -21,6 +22,7 @@ export default Ember.Controller.extend({
if (!this.get('originals') || !this.get('selectedItem')) {this.set('disableSave', true); return;}
if (((this.get('originals').name == this.get('selectedItem').name) &&
(this.get('originals').group == this.get('selectedItem').group) &&
(this.get('originals').trust_level == this.get('selectedItem').trust_level) &&
(this.get('originals').initial_payment == this.get('selectedItem').initial_payment) &&
(this.get('originals').recurring == this.get('selectedItem').recurring) &&
(this.get('originals').recurring_payment == this.get('selectedItem').recurring_payment) &&
@@ -41,7 +43,7 @@ export default Ember.Controller.extend({
else{
this.set('disableSave', false);
}
}.observes('selectedItem.name', 'selectedItem.group', 'selectedItem.initial_payment',
}.observes('selectedItem.name', 'selectedItem.group', 'selectedItem.trust_level', 'selectedItem.initial_payment',
'selectedItem.recurring', 'selectedItem.recurring_payment', 'selectedItem.recurring_payment_period',
'selectedItem.trial', 'selectedItem.trial_period', 'selectedItem.description_raw', 'selectedItem.description_cooked',
'selectedItem.welcome_message', 'selectedItem.braintree_plan_id'),
@@ -51,6 +53,7 @@ export default Ember.Controller.extend({
if (gateway == "Braintree"){
this.set('braintree', true);
};
this.set('trustLevels', Discourse.Site.current().get('trustLevels'));
}.on('init'),

actions: {
@@ -62,6 +65,7 @@ export default Ember.Controller.extend({
name: leagueLevel.name,
enabled: leagueLevel.enabled,
group: leagueLevel.group,
trust_level: leagueLevel.trust_level,
initial_payment: leagueLevel.initial_payment,
recurring: leagueLevel.recurring,
recurring_payment: leagueLevel.recurring_payment,
@@ -45,6 +45,7 @@ LeagueLevel.reopenClass({
name: leagueLevel.name,
enabled: leagueLevel.enabled,
group: leagueLevel.group,
trust_level: leagueLevel.trust_level,
initial_payment: leagueLevel.initial_payment,
recurring: leagueLevel.recurring,
recurring_payment: leagueLevel.recurring_payment,
@@ -80,6 +81,7 @@ LeagueLevel.reopenClass({
var cooked = new Handlebars.SafeString(new PrettyText(getOpts()).cook(object.description_raw));
data.name = self.name;
data.group = self.group;
data.trust_level = self.trust_level || 0;
data.initial_payment = self.initial_payment;
data.recurring = self.recurring;
data.recurring_payment = self.recurring_payment;
@@ -39,6 +39,15 @@ export default Discourse.Route.extend({
else{
var showPayment = false;
};
controller.setProperties({ model, memberExists: memberExists, memberSubscription: memberSubscription, showPayment: showPayment });

if (model[0].user_insufficient_tl){
var memberInsufficientTL = true;
var showPayment = false;
}
else{
var memberInsufficientTL = false;
}

controller.setProperties({ model, memberExists: memberExists, memberSubscription: memberSubscription, memberInsufficientTL: memberInsufficientTL, showPayment: showPayment });
}
});
@@ -45,6 +45,9 @@
<div>
{{combo-box content=customGroups valueAttribute="id" value=selectedItem.group none="admin.groups.bulk_select"}}
</div>
<div>
{{combo-box content=trustLevels valueAttribute="id" value=selectedItem.trust_level}}
</div>
<div>
<label for="initial-payment">{{i18n 'admin.league.levels.initial_payment'}}</label>
<span>{{currency-symbol}}</span>{{input type="text" name="initial-payment" value=selectedItem.initial_payment}}
@@ -7,6 +7,9 @@
<div>{{i18n 'league.member_exists'}}</div>
{{/if}} {{!-- memberSubscription --}}
{{/if}} {{!-- memberExists --}}
{{#if memberInsufficientTL}}
<div>{{i18n 'league.member_insufficient_tl'}}</div>
{{/if}} {{!-- memberInsufficientTL --}}
{{#if showPayment}}
{{checkout-progress state=checkoutState}}
<div class="billing-section">
@@ -18,6 +18,8 @@ en:
new_name: "New League Level"
id: "ID"
membership_page: "Public membership page"
trust_level: "Users must be at or below this Trust Level in order to purchase this membership."
trust_level_option: "(trust level)"
initial_payment: "Initial Payment"
initial_payment_description: "The amount charged at the beginning of membership."
recurring: "Recurring"
@@ -42,6 +44,7 @@ en:
league:
title: "Discourse League"
member_exists: "Looks like you're already a member of the group that this membership level grants. If you feel this is a mistake, please contact one of our admins."
member_insufficient_tl: "You currently do not have a sufficient trust level to purchase this membership. If you feel this is a mistake, please contact one of our admins."
dashboard_default: "TODO"
billing: "Billing"
subscriptions_title: "Subscriptions"

0 comments on commit f6fb75d

Please sign in to comment.
You can’t perform that action at this time.