~singpolyma/dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 3

[PATCH 1/2] add parent_customer_id when exists to admin customer info command

Details
Message ID
<20240401172934.35575-1-sourcehut@lazytapir.com>
DKIM signature
pass
Download raw message
Patch: +12 -2
---
 forms/admin_plan_info.rb | 8 ++++++++
 lib/customer.rb          | 2 +-
 lib/customer_info.rb     | 4 +++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/forms/admin_plan_info.rb b/forms/admin_plan_info.rb
index 21c2a3e..4769bca 100644
--- a/forms/admin_plan_info.rb
+++ b/forms/admin_plan_info.rb
@@ -4,3 +4,11 @@ field(
	description: @plan_info.relative_start_date,
	value: @plan_info.formatted_start_date
)

if @plan_info.parent_customer_id
	field(
		var: "parent_customer_id",
		label: "Parent customer id",
		value: @plan_info.parent_customer_id
	)
end
diff --git a/lib/customer.rb b/lib/customer.rb
index ea288d8..2d5194b 100644
--- a/lib/customer.rb
+++ b/lib/customer.rb
@@ -18,7 +18,7 @@ require_relative "./trivial_backend_sgx_repo"
class Customer
	extend Forwardable

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

	def_delegators :@plan, :active?, :activate_plan_starting_now, :bill_plan,
diff --git a/lib/customer_info.rb b/lib/customer_info.rb
index 2369e39..faba4a3 100644
--- a/lib/customer_info.rb
+++ b/lib/customer_info.rb
@@ -24,7 +24,8 @@ class PlanInfo
		PromiseHash.all(
			customer: customer,
			start_date: customer.activation_date,
			calling_charges_this_month: customer.calling_charges_this_month
			calling_charges_this_month: customer.calling_charges_this_month,
			parent_customer_id: customer.plan.parent_customer_id
		).then(method(:new))
	end

@@ -46,6 +47,7 @@ class PlanInfo
		method_missing :customer, Customer
		start_date Time
		calling_charges_this_month BigDecimal
		parent_customer_id Either(String, nil)
	end

	def template
-- 
2.44.0

[PATCH 2/2] get subaccounts in admin customer info command

Details
Message ID
<20240401172934.35575-2-sourcehut@lazytapir.com>
In-Reply-To
<20240401172934.35575-1-sourcehut@lazytapir.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +44 -3
---
 lib/customer_info.rb       |  7 +++++--
 lib/parent_code_repo.rb    | 17 +++++++++++++++++
 test/test_customer_info.rb | 20 ++++++++++++++++++++
 test/test_porting_step.rb  |  3 ++-
 4 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/lib/customer_info.rb b/lib/customer_info.rb
index faba4a3..1481e14 100644
--- a/lib/customer_info.rb
+++ b/lib/customer_info.rb
@@ -115,13 +115,15 @@ class AdminInfo
		call_info String
		trust_level String
		backend_jid String
		subaccounts Either(ArrayOf(ParentCodeRepo::Subaccount), nil)
	end

	def self.for(
		customer,
		trust_level_repo: TrustLevelRepo.new,
		call_attempt_repo: CallAttemptRepo.new,
		backend_repo: TrivialBackendSgxRepo.new
		backend_repo: TrivialBackendSgxRepo.new,
		parent_code_repo: ParentCodeRepo.new(redis: REDIS, db: DB)
	)
		PromiseHash.all(
			jid: customer.jid,
@@ -131,7 +133,8 @@ class AdminInfo
			api: API.for(customer),
			call_info: call_info(customer, call_attempt_repo),
			trust_level: trust_level_repo.find(customer).then(&:to_s),
			backend_jid: backend_repo.get(customer.customer_id).from_jid.to_s
			backend_jid: backend_repo.get(customer.customer_id).from_jid.to_s,
			subaccounts: parent_code_repo.get_subaccounts(customer.customer_id)
		).then(&method(:new))
	end

diff --git a/lib/parent_code_repo.rb b/lib/parent_code_repo.rb
index 4d348ae..5e171ee 100644
--- a/lib/parent_code_repo.rb
+++ b/lib/parent_code_repo.rb
@@ -43,6 +43,13 @@ class ParentCodeRepo
		SQL
	end

	def get_subaccounts(parent_id)
		@db.query_one(<<~SQL, parent_id)
			SELECT customer_id FROM customer_plans WHERE parent_customer_id=$1
		SQL
		.then { |rows| rows.map { |customer_id| Subaccount.new(customer_id) } }
	end

	def trust_level_guard(parent_id)
		return unless parent_id

@@ -54,4 +61,14 @@ class ParentCodeRepo
			end
		end
	end

	class Subaccount
		value_semantics do
			customer_id String
		end

		def initialize(customer_id)
			@customer_id = customer_id
		end
	end
end
diff --git a/test/test_customer_info.rb b/test/test_customer_info.rb
index 5d30722..edde19e 100644
--- a/test/test_customer_info.rb
+++ b/test/test_customer_info.rb
@@ -17,6 +17,8 @@ PlanInfo::DB = FakeDB.new(
		}
	]
)
AdminInfo::REDIS = Minitest::Mock.new
AdminInfo::DB = Minitest::Mock.new

class CustomerInfoTest < Minitest::Test
	def test_info_does_not_crash
@@ -118,6 +120,12 @@ class CustomerInfoTest < Minitest::Test
			[String, "test"]
		)

		AdminInfo::DB.expect(
			:query_one,
			EMPromise.resolve({ customer_id: "012345678" }),
			[String, "test"]
		)

		cust = customer(sgx: sgx, plan_name: "test_usd")

		trust_repo = Minitest::Mock.new
@@ -147,6 +155,12 @@ class CustomerInfoTest < Minitest::Test
			[String, "test"]
		)

		AdminInfo::DB.expect(
			:query_one,
			EMPromise.resolve({ customer_id: "012345678" }),
			[String, "test"]
		)

		cust = customer(sgx: sgx, plan_name: "test_usd")

		call_attempt_repo = Minitest::Mock.new
@@ -200,6 +214,12 @@ class CustomerInfoTest < Minitest::Test
			sgx: sgx
		)

		AdminInfo::DB.expect(
			:query_one,
			EMPromise.resolve({ customer_id: "012345678" }),
			[String, "test"]
		)

		trust_repo = Minitest::Mock.new
		trust_repo.expect(:find, TrustLevel::Basement, [cust])

diff --git a/test/test_porting_step.rb b/test/test_porting_step.rb
index 940110d..eb51fd9 100644
--- a/test/test_porting_step.rb
+++ b/test/test_porting_step.rb
@@ -70,7 +70,8 @@ def admin_info(customer_id, tel)
		api: API::V2.new,
		call_info: "",
		trust_level: "",
		backend_jid: "customer_#{customer_id}@example.com"
		backend_jid: "customer_#{customer_id}@example.com",
		subaccounts: nil
	)
end

-- 
2.44.0

Re: [PATCH 2/2] get subaccounts in admin customer info command

BloomingFlower <sourcehut@lazytapir.com>
Details
Message ID
<22701a35-777c-4606-90ed-f09517e12ba5@lazytapir.com>
In-Reply-To
<20240401172934.35575-2-sourcehut@lazytapir.com> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
I think the first patch will work. Second I'm less sure I'm going down the right path for a couple reasons. I don't like that I had to modify test/test_porting_step.rb, but I couldn't find another instance of AdminInfo.new(...) so maybe that's fine. Second I'm getting an error with rake test


/home/peanut/jmp/sgx-jmp/lib/customer_info.rb:118:in `block in <class:AdminInfo>': uninitialized constant ParentCodeRepo (NameError)
Did you mean?  AreaCodeRepo
rake aborted!


financial_info.rb does

value_semanticsdo
transactionsArrayOf(CustomerFinancials::TransactionInfo)
declinesInteger
btc_addressesArrayOf(String)
payment_methodsPaymentMethods
end

without issue and I'm not sure what I'm doing different.
Details
Message ID
<Zg1vMATHGec3QIsw@singpolyma-beefy.lan>
In-Reply-To
<20240401172934.35575-1-sourcehut@lazytapir.com> (view parent)
DKIM signature
pass
Download raw message
Somebody claiming to be SavagePeanut wrote:
>---
> forms/admin_plan_info.rb | 8 ++++++++
> lib/customer.rb          | 2 +-
> lib/customer_info.rb     | 4 +++-
> 3 files changed, 12 insertions(+), 2 deletions(-)
>
>diff --git a/forms/admin_plan_info.rb b/forms/admin_plan_info.rb
>index 21c2a3e..4769bca 100644
>--- a/forms/admin_plan_info.rb
>+++ b/forms/admin_plan_info.rb
>@@ -4,3 +4,11 @@ field(
> 	description: @plan_info.relative_start_date,
> 	value: @plan_info.formatted_start_date
> )
>+
>+if @plan_info.parent_customer_id
>+	field(
>+		var: "parent_customer_id",
>+		label: "Parent customer id",
>+		value: @plan_info.parent_customer_id
>+	)
>+end
>diff --git a/lib/customer.rb b/lib/customer.rb
>index ea288d8..2d5194b 100644
>--- a/lib/customer.rb
>+++ b/lib/customer.rb
>@@ -18,7 +18,7 @@ require_relative "./trivial_backend_sgx_repo"
> class Customer
> 	extend Forwardable
>
>-	attr_reader :customer_id, :balance, :jid, :tndetails, :feature_flags
>+	attr_reader :customer_id, :balance, :jid, :tndetails, :feature_flags, :plan

An idea, instead of exposing plan like this, use billing_customer_id which 
is never nil but will give us as admins effectively the same info.

Re: [PATCH 2/2] get subaccounts in admin customer info command

Details
Message ID
<Zg1+HWnkm++Hmv3v@singpolyma-beefy.lan>
In-Reply-To
<20240401172934.35575-2-sourcehut@lazytapir.com> (view parent)
DKIM signature
pass
Download raw message
>---
> lib/customer_info.rb       |  7 +++++--
> lib/parent_code_repo.rb    | 17 +++++++++++++++++
> test/test_customer_info.rb | 20 ++++++++++++++++++++
> test/test_porting_step.rb  |  3 ++-
> 4 files changed, 44 insertions(+), 3 deletions(-)
>
>diff --git a/lib/customer_info.rb b/lib/customer_info.rb
>index faba4a3..1481e14 100644
>--- a/lib/customer_info.rb
>+++ b/lib/customer_info.rb
>@@ -115,13 +115,15 @@ class AdminInfo
> 		call_info String
> 		trust_level String
> 		backend_jid String
>+		subaccounts Either(ArrayOf(ParentCodeRepo::Subaccount), nil)

I think probably no reason to allow nil here? Empty array would be correct, 
right?

>diff --git a/lib/parent_code_repo.rb b/lib/parent_code_repo.rb
>index 4d348ae..5e171ee 100644
>--- a/lib/parent_code_repo.rb
>+++ b/lib/parent_code_repo.rb
>@@ -43,6 +43,13 @@ class ParentCodeRepo
> 		SQL
> 	end
>
>+	def get_subaccounts(parent_id)
>+		@db.query_one(<<~SQL, parent_id)
>+			SELECT customer_id FROM customer_plans WHERE parent_customer_id=$1
>+		SQL
>+		.then { |rows| rows.map { |customer_id| Subaccount.new(customer_id) } }
>+	end
>+

I don't see that this really belongs in parent_code_repo, which is a repo 
for getting your special referral code to make a new subaccount.

I think it could be a wholly new repo honestly, I don't think any part of 
the code knows about subaccounts right now.

>diff --git a/test/test_porting_step.rb b/test/test_porting_step.rb
>index 940110d..eb51fd9 100644
>--- a/test/test_porting_step.rb
>+++ b/test/test_porting_step.rb
>@@ -70,7 +70,8 @@ def admin_info(customer_id, tel)
> 		api: API::V2.new,
> 		call_info: "",
> 		trust_level: "",
>-		backend_jid: "customer_#{customer_id}@example.com"
>+		backend_jid: "customer_#{customer_id}@example.com",
>+		subaccounts: nil

Could avoid this by doing above:

	subaccounts ArrayOf(Subaccount), default: []
Reply to thread Export thread (mbox)