~singpolyma/sgx-jmp

282fb206dc3ee4438e77f63271668ff370606ed9 — Stephen Paul Weber 1 year, 2 months ago 0026530
Command list UX improvements
1 files changed, 92 insertions(+), 92 deletions(-)

M sgx_jmp.rb
M sgx_jmp.rb => sgx_jmp.rb +92 -92
@@ 420,6 420,37 @@ Command.new(
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"info",
	"Show Account Info",
	list_for: ->(*) { true },
	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
) {
	Command.customer.then(&:info).then do |info|
		Command.finish do |reply|
			form = Blather::Stanza::X.new(:result)
			form.title = "Account Info"
			form.fields = info.fields
			reply.command << form
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"usage",
	"Show Monthly Usage"
) {
	report_for = (Date.today..(Date.today << 1))

	Command.customer.then { |customer|
		customer.usage_report(report_for)
	}.then do |usage_report|
		Command.finish do |reply|
			reply.command << usage_report.form
		end
	end
}.register(self).then(&CommandList.method(:register))

# Commands that just pass through to the SGX
{
	"configure-calls" => ["Configure Calls"]


@@ 452,6 483,35 @@ Command.new(
}.register(self).then(&CommandList.method(:register))

Command.new(
	"migrate billing",
	"Switch from PayPal or expired trial to new billing",
	list_for: ->(tel:, customer:, **) { tel && !customer&.currency },
	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
) {
	EMPromise.all([
		Command.customer,
		Command.reply do |reply|
			reply.allowed_actions = [:next]
			reply.command << FormTemplate.render("migrate_billing")
		end
	]).then do |(customer, iq)|
		Registration::Payment.for(
			iq, customer, customer.registered?.phone,
			final_message: PaypalDone::MESSAGE,
			finish: PaypalDone
		).then(&:write).catch_only(Command::Execution::FinalStanza) do |s|
			BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
			BLATHER.say(
				CONFIG[:notify_admin],
				"#{customer.customer_id} migrated to #{customer.currency}",
				:groupchat
			)
			EMPromise.reject(s)
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"credit cards",
	"Credit Card Settings and Management"
) {


@@ 511,33 571,7 @@ Command.new(
}.register(self).then(&CommandList.method(:register))

Command.new(
	"reset sip account",
	"Create or Reset SIP Account"
) {
	Command.customer.then(&:reset_sip_account).then do |sip_account|
		Command.finish do |reply|
			reply.command << sip_account.form
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"usage",
	"Show Monthly Usage"
) {
	report_for = (Date.today..(Date.today << 1))

	Command.customer.then { |customer|
		customer.usage_report(report_for)
	}.then do |usage_report|
		Command.finish do |reply|
			reply.command << usage_report.form
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"invite codes",
	"referral codes",
	"Refer a friend for free credit"
) {
	Command.customer.then(&:unused_invites).then do |invites|


@@ 562,73 596,12 @@ Command.new(
}.register(self).then(&CommandList.method(:register))

Command.new(
	"info",
	"Show Account Info",
	list_for: ->(*) { true },
	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
	"reset sip account",
	"Create or Reset SIP Account"
) {
	Command.customer.then(&:info).then do |info|
	Command.customer.then(&:reset_sip_account).then do |sip_account|
		Command.finish do |reply|
			form = Blather::Stanza::X.new(:result)
			form.title = "Account Info"
			form.fields = info.fields
			reply.command << form
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"customer info",
	"Show Customer Info",
	list_for: ->(customer: nil, **) { customer&.admin? }
) {
	Command.customer.then do |customer|
		raise AuthError, "You are not an admin" unless customer&.admin?

		customer_info = CustomerInfoForm.new
		Command.reply { |reply|
			reply.allowed_actions = [:next]
			reply.command << customer_info.picker_form
		}.then { |response|
			customer_info.find_customer(response)
		}.then do |target_customer|
			target_customer.admin_info.then do |info|
				Command.finish do |reply|
					form = Blather::Stanza::X.new(:result)
					form.title = "Customer Info"
					form.fields = info.fields
					reply.command << form
				end
			end
		end
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"migrate billing",
	"Switch from PayPal or expired trial to new billing",
	list_for: ->(tel:, customer:, **) { tel && !customer&.currency },
	customer_repo: CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
) {
	EMPromise.all([
		Command.customer,
		Command.reply do |reply|
			reply.allowed_actions = [:next]
			reply.command << FormTemplate.render("migrate_billing")
		end
	]).then do |(customer, iq)|
		Registration::Payment.for(
			iq, customer, customer.registered?.phone,
			final_message: PaypalDone::MESSAGE,
			finish: PaypalDone
		).then(&:write).catch_only(Command::Execution::FinalStanza) do |s|
			BLATHER.join(CONFIG[:notify_admin], "sgx-jmp")
			BLATHER.say(
				CONFIG[:notify_admin],
				"#{customer.customer_id} migrated to #{customer.currency}",
				:groupchat
			)
			EMPromise.reject(s)
			reply.command << sip_account.form
		end
	end
}.register(self).then(&CommandList.method(:register))


@@ 666,6 639,33 @@ Command.new(
	end
}.register(self).then(&CommandList.method(:register))

Command.new(
	"customer info",
	"Show Customer Info",
	list_for: ->(customer: nil, **) { customer&.admin? }
) {
	Command.customer.then do |customer|
		raise AuthError, "You are not an admin" unless customer&.admin?

		customer_info = CustomerInfoForm.new
		Command.reply { |reply|
			reply.allowed_actions = [:next]
			reply.command << customer_info.picker_form
		}.then { |response|
			customer_info.find_customer(response)
		}.then do |target_customer|
			target_customer.admin_info.then do |info|
				Command.finish do |reply|
					form = Blather::Stanza::X.new(:result)
					form.title = "Customer Info"
					form.fields = info.fields
					reply.command << form
				end
			end
		end
	end
}.register(self).then(&CommandList.method(:register))

command :execute?, node: "web-register" do |iq|
	StatsD.increment("command", tags: ["node:#{iq.node}"])