~singpolyma/sgx-jmp

d1dc3e7d279f9bf76a89369b62f76571832255af — Stephen Paul Weber 9 months ago 82ac670
Store feature flags on user for limiting commands, etc
5 files changed, 17 insertions(+), 7 deletions(-)

M .rubocop.yml
M lib/command_list.rb
M lib/customer.rb
M lib/customer_repo.rb
M test/test_helper.rb
M .rubocop.yml => .rubocop.yml +1 -1
@@ 24,7 24,7 @@ Metrics/AbcSize:
    - test/*

Metrics/ParameterLists:
  Max: 6
  Max: 7

Naming/MethodParameterName:
  AllowNamesEndingInNumbers: false

M lib/command_list.rb => lib/command_list.rb +1 -1
@@ 18,7 18,7 @@ class CommandList
		args = {
			from_jid: from_jid, customer: customer,
			tel: customer&.registered? ? customer&.registered?&.phone : nil,
			fwd: customer&.fwd,
			fwd: customer&.fwd, feature_flags: customer&.feature_flags || [],
			payment_methods: []
		}
		return EMPromise.resolve(args) unless customer&.plan_name

M lib/customer.rb => lib/customer.rb +3 -1
@@ 18,7 18,7 @@ require_relative "./trivial_backend_sgx_repo"
class Customer
	extend Forwardable

	attr_reader :customer_id, :balance, :jid, :tndetails
	attr_reader :customer_id, :balance, :jid, :tndetails, :feature_flags
	alias billing_customer_id customer_id

	def_delegators :@plan, :active?, :activate_plan_starting_now, :bill_plan,


@@ 53,6 53,7 @@ class Customer
		plan: CustomerPlan.new(customer_id),
		balance: BigDecimal(0),
		tndetails: {},
		feature_flags: [],
		sgx: TrivialBackendSgxRepo.new.get(customer_id)
	)
		@plan = plan


@@ 62,6 63,7 @@ class Customer
		@jid = jid
		@balance = balance
		@tndetails = tndetails
		@feature_flags = feature_flags
		@sgx = sgx
	end


M lib/customer_repo.rb => lib/customer_repo.rb +8 -4
@@ 164,11 164,15 @@ protected
	end

	def fetch_redis(customer_id)
		mget(
			"jmp_customer_auto_top_up_amount-#{customer_id}",
			"jmp_customer_monthly_overage_limit-#{customer_id}"
		).then { |r|
		EMPromise.all([
			mget(
				"jmp_customer_auto_top_up_amount-#{customer_id}",
				"jmp_customer_monthly_overage_limit-#{customer_id}"
			),
			@redis.smembers("jmp_customer_feature_flags-#{customer_id}")
		]).then { |r, flags|
			r.transform_keys { |k| k.match(/^jmp_customer_([^-]+)/)[1].to_sym }
			 .merge(feature_flags: flags.map(&:to_sym))
		}
	end


M test/test_helper.rb => test/test_helper.rb +4 -0
@@ 258,6 258,10 @@ class FakeRedis
		@values[key]&.size || 0
	end

	def smembers(key)
		@values[key]&.to_a || []
	end

	def expire(_, _); end

	def exists(*keys)