diff --git a/app/components/footer/copyright_component.html.erb b/app/components/footer/copyright_component.html.erb index acde5a71..5364acb4 100644 --- a/app/components/footer/copyright_component.html.erb +++ b/app/components/footer/copyright_component.html.erb @@ -1,10 +1,10 @@

Made with ♥️ by - <%= link_to "pil0u", "slack://user?team=T02NE0241&id=URZ0F4TEF", class: "text-white font-semibold hover:text-aoc-atmospheric" %>, - <%= link_to "Aquaj", "slack://user?team=T02NE0241&id=U0J5GUEAW", class: "text-white font-semibold hover:text-aoc-atmospheric" %> & - <%= link_to "Joenn", "slack://user?team=T02NE0241&id=U045Z0313UP", class: "text-white font-semibold hover:text-aoc-atmospheric" %> + <%= link_to "pil0u", "slack://user?team=T02NE0241&id=URZ0F4TEF", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %>, + <%= link_to "Aquaj", "slack://user?team=T02NE0241&id=U0J5GUEAW", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %> & + <%= link_to "Joenn", "slack://user?team=T02NE0241&id=U045Z0313UP", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %> → - <%= link_to "https://github.com/pil0u/lewagon-aoc", target: :_blank, rel: "noopener", class: "text-other-green hover:link-external" do %> + <%= link_to "https://github.com/pil0u/lewagon-aoc", target: :_blank, rel: :noopener, class: "text-other-green hover:link-external" do %> <% end %>

diff --git a/app/components/footer/nav_component.html.erb b/app/components/footer/nav_component.html.erb index f0447721..a9d47c00 100644 --- a/app/components/footer/nav_component.html.erb +++ b/app/components/footer/nav_component.html.erb @@ -1,6 +1,7 @@ diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index db0a76e6..8bac637d 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -2,7 +2,7 @@ class PagesController < ApplicationController skip_before_action :authenticate_user!, only: %i[admin code_of_conduct faq participation stats welcome] - before_action :render_countdown, only: %i[code_of_conduct faq participation setup stats welcome], if: :render_countdown? + before_action :render_countdown, only: %i[code_of_conduct faq participation patrons setup stats welcome], if: :render_countdown? def admin; end @@ -52,6 +52,15 @@ def participation @cities.sort_by! { |city| [city[:participation_ratio] * -1, city[:vanity_name]] } end + def patrons + @users = User + .select("users.uid, users.username, COUNT(referees.id) AS referrals") + .select("CEIL(100 * LN(COUNT(referees.id) + 1)) AS aura") + .joins("LEFT JOIN users referees ON users.id = referees.referrer_id") + .group("users.id") + .order(aura: :desc) + end + def setup @private_leaderboard = ENV.fetch("AOC_ROOMS").split(",").last diff --git a/app/models/user.rb b/app/models/user.rb index 7df970fd..fea54f11 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -120,6 +120,10 @@ def referral_code "R#{uid.to_s.rjust(5, '0')}" end + def referral_link(request) + "#{request.base_url}/?referral_code=#{referral_code}" + end + def referrer_code referrer&.referral_code end diff --git a/app/views/days/show.html.erb b/app/views/days/show.html.erb index a17a39f7..b5b1d58b 100644 --- a/app/views/days/show.html.erb +++ b/app/views/days/show.html.erb @@ -4,7 +4,7 @@ <% if @day <= Aoc.latest_day %> · - <%= link_to "link to puzzle", Aoc.url(@day), target: :_blank, rel: "noopener", class: "link-explicit link-external" %> + <%= link_to "link to puzzle", Aoc.url(@day), target: :_blank, rel: :noopener, class: "link-explicit link-external" %> <% end %> diff --git a/app/views/pages/admin.html.erb b/app/views/pages/admin.html.erb index 193b6e6e..3f4aaada 100644 --- a/app/views/pages/admin.html.erb +++ b/app/views/pages/admin.html.erb @@ -1,8 +1,8 @@ <% if user_signed_in? %>
- <%= link_to "Blazer", blazer_path, class: "button" %> - <%= link_to "GoodJob", good_job_path, class: "button" %> + <%= link_to "Blazer", blazer_path, target: :_blank, rel: :noopener, class: "button" %> + <%= link_to "GoodJob", good_job_path, target: :_blank, rel: :noopener, class: "button" %> <%= link_to "/participation", participation_path, class: "button" %>
diff --git a/app/views/pages/code_of_conduct.html.erb b/app/views/pages/code_of_conduct.html.erb index 63d942c2..65796238 100644 --- a/app/views/pages/code_of_conduct.html.erb +++ b/app/views/pages/code_of_conduct.html.erb @@ -19,7 +19,8 @@
  • Be respectful and empathetic towards all community members

    - This event and the <%= link_to "#aoc Slack channel", Aoc.slack_channel, class: "link-explicit link-slack" %> + This event and the + <%= link_to "#aoc Slack channel", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %> should be a safe place for everyone. Always assume positive intent, be positive, friendly and helpful to others. Focus on good vibes; we do not tolerate any form of derogatory comments or personal attacks.

    @@ -46,7 +47,8 @@

    Please, don't try to break in

    Attempting to access the platform in unauthorized ways is not permitted and is not fun for the community or the - Admins. The platform's code is <%= link_to "open", "https://github.com/pil0u/lewagon-aoc/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %> + Admins. The platform's code is + <%= link_to "open", "https://github.com/pil0u/lewagon-aoc/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %> and all the data you can find here is available upon request. Also, scores are computed from AoC's data, so they cannot be changed by breaking in here anyway.

    diff --git a/app/views/pages/faq.html.erb b/app/views/pages/faq.html.erb index 9f57d330..e6c7a100 100644 --- a/app/views/pages/faq.html.erb +++ b/app/views/pages/faq.html.erb @@ -42,7 +42,7 @@

    - <%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %> + <%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %> is an Advent calendar of small programming puzzles that you can solve in any programming language.

    @@ -72,7 +72,7 @@

    Puzzles from past editions are available - <%= link_to "here", "https://adventofcode.com/events", target: :ext, class: "link-explicit link-external" %>. + <%= link_to "here", "https://adventofcode.com/events", target: :_blank, rel: :noopener, class: "link-explicit link-external" %>.

    @@ -92,8 +92,8 @@

    If you get stuck on a puzzle, you can always - <%= link_to "discuss with other Wagoners", Aoc.slack_channel, class: "link-explicit link-slack" %>! This event - is about sharing, learning, and mutual help, irrespective of your skill level. + <%= link_to "discuss with other Wagoners", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>! + This event is about sharing, learning, and mutual help, irrespective of your skill level. It's also a perfect time to reconnect with your campus/batch 🤙

    @@ -109,7 +109,7 @@

    You build your squad by assembling your dream team (find people - <%= link_to "on Slack", Aoc.slack_channel, class: "link-explicit link-slack" %>) and create a squad in your + <%= link_to "on Slack", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>) and create a squad in your <%= link_to "settings", settings_path, class: "link-explicit link-internal" %>(*) in 1 click.

    diff --git a/app/views/pages/patrons.html.erb b/app/views/pages/patrons.html.erb new file mode 100644 index 00000000..60574965 --- /dev/null +++ b/app/views/pages/patrons.html.erb @@ -0,0 +1,68 @@ +<%= render PageTitleComponent.new(title: "Patrons") %> + +

    +

    + Influencers of Le Wagon, this is your moment. +

    + +

    + Your referral code + <%= current_user.referral_code %> + is your fame booster. Share it everywhere to your fellow Wagoners: your batch channel + <%= link_to "on Slack", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>, + your WhatsApp groups, by mail or pigeon, whatever feels right. You even have a personal link you can share: +

    + + + <%= current_user.referral_link(request) %> + + +

    + Every time someone signs up using your code, you will increase your aura. Finding people + who solve a few puzzles can only help your aura as well. +

    + +

    + One more thing. The top referrer by December 8th wins a 100€ Amazon voucher 💸 +

    + +

    + Good luck! +

    +
    + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + <% end %> + +
    ReferralsAura
    + <%= link_to user[:username], profile_path(user[:uid]), class: "hover:text-gold" %> + + <%= user[:referrals] %> + + <%= user[:aura].to_i %> +
    diff --git a/app/views/pages/setup.html.erb b/app/views/pages/setup.html.erb index 61bb2227..e5392c64 100644 --- a/app/views/pages/setup.html.erb +++ b/app/views/pages/setup.html.erb @@ -30,7 +30,7 @@ "Log in to Advent of Code", "https://adventofcode.com/auth/login", target: :_blank, - rel: "noopener", + rel: :noopener, class: "link-explicit link-external" ) %>, using either your GitHub account or another OAuth option.
  • @@ -42,7 +42,7 @@ "Go to this page", "https://adventofcode.com/leaderboard/private", target: :_blank, - rel: "noopener", + rel: :noopener, class: "link-explicit link-external" ) %>, enter the following code <%= current_user.private_leaderboard %> and click [Join].

    @@ -57,7 +57,7 @@ "your settings", "https://adventofcode.com/settings", target: :_blank, - rel: "noopener", + rel: :noopener, class: "link-explicit link-external" ) %>. It's the number next to anonymous user #XXXXXXX. @@ -124,7 +124,7 @@

    If you have completed all these steps, waited 10 minutes, and your status remains Pending, please send a message in this - <%= link_to "Slack thread", "https://lewagon-alumni.slack.com/archives/C02PN711H09/p1700598449505399", class: "link-explicit link-slack" %> + <%= link_to "Slack thread", "https://lewagon-alumni.slack.com/archives/C02PN711H09/p1700598449505399", target: :_blank, rel: :noopener, class: "link-explicit link-slack" %> with the following details: id:<%= current_user.id %>;aoc_id:<%= current_user.aoc_id %>

    diff --git a/app/views/pages/welcome.html.erb b/app/views/pages/welcome.html.erb index 8ff82734..9b565f54 100644 --- a/app/views/pages/welcome.html.erb +++ b/app/views/pages/welcome.html.erb @@ -1,6 +1,6 @@

    - <%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %> + <%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %> is an Advent calendar of small programming puzzles that can be solved in any programming language you like.

    diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 39fdc87a..b56b5c85 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -77,14 +77,15 @@ <%= render PageTitleComponent.new(title: "Referral") %>

    - When you share the event to your friends, ask them to add this referral code during the setup. This will boost your aura. + When you share the event to your friends, ask them to add this referral code during the setup. This will boost your + <%= link_to "aura", patrons_path, class: "strong hover:text-gold" %>.

    diff --git a/config/routes.rb b/config/routes.rb index aa7c175d..e76f8081 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,7 @@ def omniauth_callbacks(provider) authenticated :user, ->(user) { user.confirmed? } do get "/", to: "pages#calendar", as: :calendar get "/countdown", to: "pages#countdown" + get "/patrons", to: "pages#patrons" get "/campus/:slug", to: "campuses#show", as: :campus get "/city/:slug", to: "campuses#show", as: :city # Retrocompat in case of old links get "/day/:day", to: "days#show", as: :day, day: /[1-9]|1\d|2[0-5]/ diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb new file mode 100644 index 00000000..1916a372 --- /dev/null +++ b/spec/controllers/pages_controller_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe PagesController do + let!(:referrer) { create :user, uid: "1" } + let!(:referee_one) { create :user, username: "Aquaj", uid: "2", referrer: } + let!(:referee_two) { create :user, username: "wJoenn", uid: "3", referrer: } + let!(:referee_three) { create :user, username: "Aurrou", uid: "4", referrer: referee_one } + + describe "#patrons" do + it "requires to be authenticated", :logged_out do + get :patrons + + expect(response).to have_http_status :redirect + end + + it "queries the username, the amount of referees and the aura for every User" do + sign_in(referrer) + get :patrons + + expect(@controller.instance_variable_get(:@users).map(&:as_json)).to contain_exactly( + hash_including("uid" => "1", "username" => "pil0u", "referrals" => 2, "aura" => 110.0), + hash_including("uid" => "2", "username" => "Aquaj", "referrals" => 1, "aura" => 70.0), + hash_including("uid" => "3", "username" => "wJoenn", "referrals" => 0, "aura" => 0.0), + hash_including("uid" => "4", "username" => "Aurrou", "referrals" => 0, "aura" => 0.0) + ) + end + end +end