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..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 params[:return_to] || root_path + redirect_to params[:return_to] || root_path + end end private 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/app/views/admin/referral_programs.html.erb b/app/views/admin/referral_programs.html.erb index 07ebd95794..cf9e84f46c 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) %>
<%= 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 %> 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