From 65d60e2551b6a5341c55e704629ccbe047847b6c Mon Sep 17 00:00:00 2001 From: Luke Oldenburg <87272260+Luke-Oldenburg@users.noreply.github.com> Date: Sun, 7 Dec 2025 02:30:13 +0000 Subject: [PATCH 1/4] Add migration --- app/models/referral/program.rb | 1 + .../20251207022849_add_redirect_to_to_referral_programs.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20251207022849_add_redirect_to_to_referral_programs.rb diff --git a/app/models/referral/program.rb b/app/models/referral/program.rb index 4362971937..f4a33b717d 100644 --- a/app/models/referral/program.rb +++ b/app/models/referral/program.rb @@ -10,6 +10,7 @@ # login_header_text :string # login_text_color :string # name :string not null +# redirect_to :string # created_at :datetime not null # updated_at :datetime not null # creator_id :bigint diff --git a/db/migrate/20251207022849_add_redirect_to_to_referral_programs.rb b/db/migrate/20251207022849_add_redirect_to_to_referral_programs.rb new file mode 100644 index 0000000000..3b4f2b5507 --- /dev/null +++ b/db/migrate/20251207022849_add_redirect_to_to_referral_programs.rb @@ -0,0 +1,5 @@ +class AddRedirectToToReferralPrograms < ActiveRecord::Migration[8.0] + def change + add_column :referral_programs, :redirect_to, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 4b44024cc9..2c342585d6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_12_05_035167) do +ActiveRecord::Schema[8.0].define(version: 2025_12_07_022849) do create_schema "google_sheets" # These are extensions that must be enabled in order to support this database @@ -2010,6 +2010,7 @@ t.string "login_header_text" t.string "login_text_color" t.string "name", null: false + t.string "redirect_to" t.datetime "updated_at", null: false t.index ["creator_id"], name: "index_referral_programs_on_creator_id" end From f20346ebff8eb183d437b96e7dead8aec52f55ba Mon Sep 17 00:00:00 2001 From: Luke Oldenburg <87272260+Luke-Oldenburg@users.noreply.github.com> Date: Sun, 7 Dec 2025 02:39:22 +0000 Subject: [PATCH 2/4] Add UI and controller --- app/controllers/admin_controller.rb | 2 +- app/controllers/referral/links_controller.rb | 2 +- app/views/admin/referral_programs.html.erb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 86085a4246..147f82e041 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1407,7 +1407,7 @@ def referral_programs end def referral_program_create - @referral_program = Referral::Program.new(name: params[:name], creator: current_user) + @referral_program = Referral::Program.new(name: params[:name], redirect_to: params[:redirect_to], creator: current_user) if @referral_program.save flash[:success] = "Referral program created successfully." diff --git a/app/controllers/referral/links_controller.rb b/app/controllers/referral/links_controller.rb index 5d886033fd..b3aa339c3b 100644 --- a/app/controllers/referral/links_controller.rb +++ b/app/controllers/referral/links_controller.rb @@ -21,7 +21,7 @@ def show skip_authorization end - redirect_to params[:return_to] || root_path + redirect_to @link.program.redirect_to.presence || root_path, allow_other_host: true end private diff --git a/app/views/admin/referral_programs.html.erb b/app/views/admin/referral_programs.html.erb index 07ebd95794..6a5f3e0830 100644 --- a/app/views/admin/referral_programs.html.erb +++ b/app/views/admin/referral_programs.html.erb @@ -8,6 +8,7 @@
<%= program.name %>
<%= program.created_at.strftime("%Y-%m-%d") %> • Created by <%= program.creator.name %> + Redirects to: <%= link_to(program.redirect_to.presence || root_url, program.redirect_to.presence || root_url) %>
<%= pluralize(program.users.size, "user") %> • <%= pluralize(program.new_users.size, "new user") %> @@ -65,7 +66,8 @@ Create a referral program <%= form.label :name, "Program name" %> <%= form.text_field :name, placeholder: "Program Name", required: true, class: "w-100" %> -
+ <%= form.label :redirect_to, "Redirect to (optional)" %> + <%= form.text_field :redirect_to, placeholder: "https://hcb.hackclub.com/", class: "w-100" %> <%= form.submit "Create", class: "btn bg-success" %> <% end %> From 181dee99d33a69e8e1658d3c83b564cf9fae9871 Mon Sep 17 00:00:00 2001 From: Luke Oldenburg <87272260+Luke-Oldenburg@users.noreply.github.com> Date: Sun, 7 Dec 2025 02:47:12 +0000 Subject: [PATCH 3/4] Move redirect --- app/controllers/referral/links_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/referral/links_controller.rb b/app/controllers/referral/links_controller.rb index b3aa339c3b..30ea6ea153 100644 --- a/app/controllers/referral/links_controller.rb +++ b/app/controllers/referral/links_controller.rb @@ -17,11 +17,13 @@ def show Rails.error.handle do Referral::Attribution.create!(user: current_user, program: @link.program, link: @link) end + + redirect_to @link.program.redirect_to.presence || root_path, allow_other_host: true else skip_authorization - end - redirect_to @link.program.redirect_to.presence || root_path, allow_other_host: true + redirect_to params[:return_to] || root_path + end end private From 59dc88ca1ff1798cbbb249c5425ce8ccdcb37ac5 Mon Sep 17 00:00:00 2001 From: Luke Oldenburg <87272260+Luke-Oldenburg@users.noreply.github.com> Date: Sat, 6 Dec 2025 23:20:36 -0500 Subject: [PATCH 4/4] Update referral_programs.html.erb Co-authored-by: Samuel Fernandez --- app/views/admin/referral_programs.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/referral_programs.html.erb b/app/views/admin/referral_programs.html.erb index 6a5f3e0830..cf9e84f46c 100644 --- a/app/views/admin/referral_programs.html.erb +++ b/app/views/admin/referral_programs.html.erb @@ -8,7 +8,7 @@
<%= program.name %>
<%= program.created_at.strftime("%Y-%m-%d") %> • Created by <%= program.creator.name %> - Redirects to: <%= link_to(program.redirect_to.presence || root_url, program.redirect_to.presence || root_url) %> + Redirects to: <%= link_to(program.redirect_to.presence || root_url) %>
<%= pluralize(program.users.size, "user") %> • <%= pluralize(program.new_users.size, "new user") %>