Skip to content

Commit a59fe6c

Browse files
authored
Merge branch 'main' into 1839
2 parents 1599e83 + 754871d commit a59fe6c

File tree

67 files changed

+2553
-751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2553
-751
lines changed

.env.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ HELPER_TOOLS_TOKEN=test-helper-tools-token
3131
GRMC_WEBHOOK_SECRET=test-grmc-webhook-secret
3232
STRIPE_PUBLIC_KEY_TEST=pk_test_51SNEgsIBOqvOFDrfzBydwy0Ca4j1Xgs7pQsbp2zsyWqHezN7yu3TRignvBqDEc6gn8y98bX8HRv8gKJ8Q45w2t6N00ofXBsMBF
3333
STRIPE_API_KEY=sk_test_51SNEgsIBOqvOFDrffrs0bKw6Qy174HAkRi4aj9UfzMhPymwCYj6A55u9JahmBn4WJeL8FbawjBmUqUUW6mA1NodU008jShUz2J
34+
SECURE_ENCRYPT_KEY=1aa983f09f099c052970bc251c1cd5a3
35+
SECURE_EXTERNAL_ID__PRIMARY_KEY_VERSION=1
36+
SECURE_EXTERNAL_ID__KEYS__1=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
37+
MOBILE_TOKEN=test-mobile-token
38+
CLOUDFRONT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIBPAIBAAJBAJ1ooRTziOuIODeLg+aGiLGXP1Qb31LMgzxHmzfgUEVq5RmV8/NY\nYPjfIZ+yDjsZTfP/2H5sgYm4u1PUAiyOqSkCAwEAAQJBAJK+nRU0KNwzRP17Yj8C\nAuNU9mQKC/tbz6jdtLW1t//NvjRRpxZNm9iBIq2CfiWxYTF9anZEjD3Xwv6JIbb4\n8XUCIQDQbE9SP3OY0Y4zjZ0YOEIfKFMc3qtGc9j/3IGbgkGG1wIhAMFXLMxZbFeZ\niYY5yC8MsYCIGEzfraTzJ7W1LMxkG0//AiA4u3Kv8aOWklwBvmdng1DESGavMhEv\nATOtGamR2dfaSwIhAJ+PGDOVYSpyVeLmcOUTbrIKnzNiLeZBnfYCDXSo8Tl1AiEA\nqXZXTJtNlK4SQgnwHXEd+ZmYSGoLb0080MKuh99IOlY=\n-----END RSA PRIVATE KEY-----\n"
39+
CLOUDFRONT_KEYPAIR_ID=APKAISH5PKOS7WQUJ6SA
40+
MOBILE_API_OAUTH_APPLICATION_UID=test-mobile-api-oauth-app-uid
3441

3542
# MinIO
3643
AWS_S3_ENDPOINT=http://localhost:9000
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class Admin::Affiliates::BaseController < Admin::BaseController
4+
before_action :set_affiliate_user
5+
6+
private
7+
def set_affiliate_user
8+
@affiliate_user = User.find(params[:affiliate_id])
9+
end
10+
end

app/controllers/admin/affiliates/products/base_controller.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
# frozen_string_literal: true
22

3-
class Admin::Affiliates::Products::BaseController < Admin::Users::BaseController
4-
before_action :set_affiliate_user
3+
class Admin::Affiliates::Products::BaseController < Admin::Affiliates::BaseController
54
before_action :set_product
65

76
private
8-
def set_affiliate_user
9-
@affiliate_user = User.find(params[:affiliate_id])
10-
end
11-
127
def set_product
138
@product = Link.find(params[:product_id])
149
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class Admin::Affiliates::ProductsController < Admin::Affiliates::BaseController
4+
include Admin::Users::ListPaginatedProducts
5+
6+
def index
7+
@title = "#{@affiliate_user.display_name} products on Gumroad"
8+
9+
list_paginated_products user: @affiliate_user,
10+
products: @affiliate_user.directly_affiliated_products.unscope(where: :purchase_disabled_at).order(Admin::Users::ListPaginatedProducts::PRODUCTS_ORDER),
11+
inertia_template: "Admin/Affiliates/Products/Index"
12+
end
13+
end

app/controllers/admin/affiliates_controller.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ def index
2020

2121
def show
2222
@title = "#{@affiliate_user.display_name} affiliate on Gumroad"
23-
products_scope = @affiliate_user.directly_affiliated_products.unscope(where: :purchase_disabled_at).order(Arel.sql(Admin::UsersController::PRODUCTS_ORDER))
24-
@pagy, @products = pagy(products_scope, limit: Admin::UsersController::PRODUCTS_PER_PAGE)
2523
respond_to do |format|
26-
format.html
27-
format.json { render json: @affiliate }
24+
format.html do
25+
render inertia: "Admin/Affiliates/Show",
26+
props: {
27+
user: Admin::UserPresenter::Card.new(user: @affiliate_user, pundit_user:).props,
28+
}
29+
end
30+
format.json { render json: @affiliate_user }
2831
end
2932
end
3033

app/controllers/admin/links_controller.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,8 @@ def show
2323
@title = @product.name
2424
render inertia: "Admin/Products/Show", legacy_template: "admin/links/show", props: {
2525
title: @product.name,
26-
product: Admin::ProductPresenter::Card.new(
27-
product: @product,
28-
admins_can_mark_as_staff_picked: ->(product) { policy([:admin, :products, :staff_picked, product]).create? },
29-
admins_can_unmark_as_staff_picked: ->(product) { policy([:admin, :products, :staff_picked, product]).destroy? }
30-
).props,
31-
user: Admin::UserPresenter::Card.new(
32-
user: @product.user,
33-
impersonatable: policy([:admin, :impersonators, @product.user]).create?
34-
).props
26+
product: Admin::ProductPresenter::Card.new(product: @product, pundit_user:).props,
27+
user: Admin::UserPresenter::Card.new(user: @product.user, pundit_user:).props
3528
}
3629
end
3730

app/controllers/admin/merchant_accounts_controller.rb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,6 @@ class Admin::MerchantAccountsController < Admin::BaseController
44
def show
55
@merchant_account = MerchantAccount.find_by(id: params[:id]) || MerchantAccount.find_by(charge_processor_merchant_id: params[:id]) || e404
66
@title = "Merchant Account #{@merchant_account.id}"
7-
load_live_attributes
7+
render inertia: "Admin/MerchantAccounts/Show", props: { merchant_account: Admin::MerchantAccountPresenter.new(merchant_account: @merchant_account).props }
88
end
9-
10-
private
11-
def load_live_attributes
12-
return unless @merchant_account.charge_processor_merchant_id.present?
13-
14-
if @merchant_account.stripe_charge_processor?
15-
stripe_account = Stripe::Account.retrieve(@merchant_account.charge_processor_merchant_id)
16-
@live_attributes = {
17-
"Charges enabled" => stripe_account.charges_enabled,
18-
"Payout enabled" => stripe_account.payouts_enabled,
19-
"Disabled reason" => stripe_account.requirements.disabled_reason,
20-
"Fields needed" => stripe_account.requirements.as_json
21-
}
22-
elsif @merchant_account.paypal_charge_processor?
23-
paypal_account_details = @merchant_account.paypal_account_details
24-
if paypal_account_details.present?
25-
@live_attributes = {
26-
"Email" => paypal_account_details["primary_email"]
27-
}
28-
end
29-
end
30-
end
319
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class Admin::Purchases::CommentsController < Admin::BaseController
4+
include Admin::Commentable
5+
6+
private
7+
def commentable
8+
Purchase.find(params[:purchase_id])
9+
end
10+
end

app/controllers/admin/purchases_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def show
6060
e404 if @purchase.nil?
6161
@product = @purchase.link
6262
@title = "Purchase #{@purchase.id}"
63+
purchase = Admin::PurchasePresenter.new(@purchase).props
64+
render(
65+
inertia: "Admin/Purchases/Show",
66+
props: {
67+
purchase:,
68+
product: Admin::ProductPresenter::Card.new(product: @product, pundit_user:).props,
69+
user: Admin::UserPresenter::Card.new(user: @product.user, pundit_user:).props
70+
},
71+
)
6372
end
6473

6574
def sync_status_with_charge_processor

app/controllers/admin/users_controller.rb

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# frozen_string_literal: true
22

33
class Admin::UsersController < Admin::BaseController
4-
include Pagy::Backend
4+
include Admin::FetchUser
55
include MassTransferPurchases
66

77
skip_before_action :require_admin!, if: :request_from_iffy?, only: %i[suspend_for_fraud_from_iffy mark_compliant_from_iffy flag_for_explicit_nsfw_tos_violation_from_iffy]
88

9-
before_action :fetch_user, except: %i[refund_queue block_ip_address]
10-
11-
helper Pagy::UrlHelpers
12-
13-
PRODUCTS_ORDER = Arel.sql("ISNULL(COALESCE(purchase_disabled_at, banned_at, links.deleted_at)) DESC, created_at DESC")
14-
PRODUCTS_PER_PAGE = 10
9+
before_action :fetch_user, except: %i[block_ip_address]
1510

1611
def show
1712
@title = "#{@user.display_name} on Gumroad"
18-
@pagy, @products = pagy(@user.links.order(PRODUCTS_ORDER), limit: PRODUCTS_PER_PAGE)
13+
1914
respond_to do |format|
20-
format.html
15+
format.html do
16+
render inertia: "Admin/Users/Show",
17+
props: {
18+
user: Admin::UserPresenter::Card.new(user: @user, pundit_user:).props,
19+
}
20+
end
2121
format.json { render json: @user }
2222
end
2323
end
@@ -193,10 +193,9 @@ def add_credit
193193
def set_custom_fee
194194
custom_fee_per_thousand = params[:custom_fee_percent].present? ? (params[:custom_fee_percent].to_f * 10).round : nil
195195
@user.update!(custom_fee_per_thousand:)
196-
197196
render json: { success: true }
198-
rescue => e
199-
render json: { success: false, message: e.message }
197+
rescue ActiveRecord::RecordInvalid => e
198+
render json: { success: false, message: e.message }, status: :unprocessable_content
200199
end
201200

202201
def toggle_adult_products
@@ -208,17 +207,6 @@ def toggle_adult_products
208207
end
209208

210209
private
211-
def fetch_user
212-
if params[:id].include?("@")
213-
@user = User.find_by(email: params[:id])
214-
else
215-
@user = User.find_by(username: params[:id]) ||
216-
User.find_by(id: params[:id])
217-
end
218-
219-
e404 unless @user
220-
end
221-
222210
def mass_transfer_purchases_params
223211
params.require(:mass_transfer_purchases).permit(:new_email)
224212
end

0 commit comments

Comments
 (0)