Skip to content

Commit 3a739a6

Browse files
authored
Merge branch 'main' into dependabot/bundler/sidekiq-8.0.1
2 parents 9265891 + 4432ef8 commit 3a739a6

17 files changed

+73
-33
lines changed

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class ApplicationController < ActionController::Base
2929
cookies.permanent[:first_visit] = 1
3030
end
3131

32+
before_action do
33+
# Disallow indexing
34+
response.set_header("X-Robots-Tag", "noindex")
35+
end
36+
3237
# Force usage of Pundit on actions
3338
after_action :verify_authorized, unless: -> { controller_path.starts_with?("doorkeeper/") || controller_path.starts_with?("audits1984/") }
3439

app/controllers/donations_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def refund
172172
end
173173

174174
def export
175-
authorize @event.donations.first
175+
authorize @event.donations.build
176176

177177
respond_to do |format|
178178
format.csv { stream_donations_csv }
@@ -181,7 +181,7 @@ def export
181181
end
182182

183183
def export_donors
184-
authorize @event.donations.first
184+
authorize @event.donations.build
185185

186186
respond_to do |format|
187187
format.csv { stream_donors_csv }

app/controllers/logins_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class LoginsController < ApplicationController
1010

1111
layout "login"
1212

13+
after_action only: [:new] do
14+
# Allow indexing login page
15+
response.delete_header("X-Robots-Tag")
16+
end
17+
1318
# view to log in
1419
def new
1520
render "users/logout" if current_user

app/controllers/static_pages_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class StaticPagesController < ApplicationController
77
skip_before_action :signed_in_user, only: [:branding, :roles]
88
skip_before_action :redirect_to_onboarding, only: [:branding, :roles]
99

10+
after_action only: [:index, :branding] do
11+
# Allow indexing home and branding pages
12+
response.delete_header("X-Robots-Tag")
13+
end
14+
1015
def index
1116
if signed_in?
1217
@service = StaticPageService::Index.new(current_user:)

app/lib/credentials.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
module Credentials
99
NESTING_DELIMITER = "__"
1010

11-
def self.fetch(*key_segments)
11+
def self.fetch(*key_segments, fallback: nil)
1212
key = key_segments.join(NESTING_DELIMITER).upcase
13-
ENV[key] || Rails.application.credentials.dig(*key_segments)
13+
ENV[key] || Rails.application.credentials.dig(*key_segments) || fallback
1414
end
1515

1616
def self.load

app/models/canonical_event_mapping.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
# fk_rails_... (event_id => events.id)
2727
#
2828
class CanonicalEventMapping < ApplicationRecord
29+
include HasBalanceMonitoring
30+
2931
broadcasts_refreshes_to ->(mapping) { [mapping.event, :transactions] }
3032

3133
belongs_to :canonical_transaction

app/models/canonical_pending_event_mapping.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# fk_rails_... (event_id => events.id)
2424
#
2525
class CanonicalPendingEventMapping < ApplicationRecord
26+
include HasBalanceMonitoring
27+
2628
broadcasts_refreshes_to ->(mapping) { [mapping.event, :transactions] }
2729

2830
belongs_to :canonical_pending_transaction
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module HasBalanceMonitoring
4+
extend ActiveSupport::Concern
5+
6+
included do
7+
after_save do
8+
Airbrake.notify("#{event.name} has a negative balance: #{ApplicationController.helpers.render_money event.balance}") if event.balance.negative?
9+
end
10+
end
11+
end

app/services/partners/plaid/transactions/get.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def fetch_transactions(offset: 0)
5555

5656
results
5757
rescue ::Plaid::ApiError => e
58-
Rails.error.report(e, context: { message: "plaid_client.transactions.get failed for bank_account #{bank_account.id} with access token #{access_token}. #{error.message}" })
58+
Rails.error.report(e, context: { message: "plaid_client.transactions.get failed for bank_account #{bank_account.id} with access token #{access_token}." })
5959

6060
mark_plaid_item_failed!
6161

app/services/twilio_verification_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TwilioVerificationService
99
)
1010

1111
# This isn't private/sensitive so it's okay to keep here
12-
VERIFY_SERVICE_ID = Rails.env.production? || ENV["USE_PROD_CREDENTIALS"]&.downcase == "true" ? "VAa06a66dad4c1ca3c199a46334ff11945" : "VAe30d49e92f634419aacdc8648948dc75"
12+
VERIFY_SERVICE_ID = Credentials.fetch(:TWILIO, :SMS_VERIFY, :SERVICE_ID, fallback: "VAe30d49e92f634419aacdc8648948dc75")
1313

1414
def send_verification_request(phone_number)
1515
CLIENT.verify

app/views/users/logout.html.erb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<% title "You’re currently signed in as #{current_user.name}" %>
22
<% @home_size = 50 %>
3-
<div class="flex items-center justify-between">
4-
<%= render partial: "application/logo" %>
5-
</div>
63

74
<div class="flex flex-col flex-1 justify-center max-w-md w-full">
85
<%= render "header", label: "Hack Club" do %>

config/application.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ class Application < Rails::Application
1616

1717
Credentials.load if ENV["DOPPLER_TOKEN"]
1818

19-
if ENV["USE_PROD_CREDENTIALS"]&.downcase == "true"
20-
config.credentials.content_path = Rails.root.join("config/credentials/production.yml.enc")
21-
config.credentials.key_path = Rails.root.join("config/credentials/production.key")
22-
raise StandardError, "USE_PROD_CREDENTIALS is set to true but config/credentials/production.key is missing" unless File.file?(config.credentials.key_path)
23-
end
24-
2519
config.action_mailer.default_url_options = {
2620
host: Credentials.fetch(:LIVE_URL_HOST)
2721
}

config/credentials/production.yml.enc

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/environments/production.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55
Rails.application.configure do
66
# Settings specified here will take precedence over those in config/application.rb.
77

8+
# We don't use Rails' default encrypted credentials in Production. However,
9+
# Rails doesn't provide an explicit way to disable encrypted credentials.
10+
# As a workaround, we set `content_path` and `key_path` to an invalid path.
11+
#
12+
# Without this workaround, Rails will fallback to `config/credentials.yml.enc`
13+
# which is NOT used for production. It will then attempt to decrypt that file,
14+
# resulting in `ActiveSupport::MessageEncryptor::InvalidMessage` on boot.
15+
#
16+
# `content_path` and `key_path` are used to create an
17+
# `ActiveSupport::EncryptedConfiguration` object which is
18+
# `Rails.application.credentials`. When `EncryptedConfiguration`
19+
# (subclass of `EncryptedFile`) has either an invalid key or content path,
20+
# Rails will internally just use an empty string as the decrypted contents of
21+
# the file.
22+
#
23+
# REFERENCES
24+
# * Where `Rails.application.credentials` is set:
25+
# https://github.com/rails/rails/blob/f575fca24a72cf0631c59ed797c575392fbbc527/railties/lib/rails/application.rb#L497-L499
26+
# * `EncryptedFile#read` raises `MissingContentError`
27+
# when missing either a key or content_path.
28+
# https://github.com/rails/rails/blob/f575fca24a72cf0631c59ed797c575392fbbc527/activesupport/lib/active_support/encrypted_file.rb#L70-L76
29+
# * `EncryptedConfiguration#read` (overrides `EncryptedFile#read`) rescues
30+
# `MissingContentError` and returns an empty string.
31+
# https://github.com/rails/rails/blob/f575fca24a72cf0631c59ed797c575392fbbc527/activesupport/lib/active_support/encrypted_configuration.rb#L64-L66
32+
#
33+
# ~ @garyhtou
34+
config.credentials.content_path = "noop"
35+
config.credentials.key_path = "noop"
36+
837
# Prepare the ingress controller used to receive mail
938
config.action_mailbox.ingress = :sendgrid
1039

dev-docs/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ documents.
143143

144144
We've transitioned to using development keys and seed data in development, but historically have used production keys and data on dev machines. It is recommended to not roll back to using production data & keys in development, but if absolutely necessary the following steps can be taken:
145145

146-
- Set environment variable `USE_PROD_CREDENTIALS=true` in your docker container (usually via `.env.development`). N.B. this does not set [`RAILS_ENV=production`](https://guides.rubyonrails.org/configuring.html#rails-environment-settings), which you should **never** do on a development machine.
146+
- Set environment variables `DOPPLER_TOKEN=<a doppler token with production access>`, `DOPPER_PROJECT=hcb`, `DOPPLER_CONFIG=production` in your docker container (usually via `.env.development`). N.B. this does not set [`RAILS_ENV=production`](https://guides.rubyonrails.org/configuring.html#rails-environment-settings), which you should **never** do on a development machine.
147147
- Put the production key in `config/credentials/production.key`. If you have heroku access you can get this from the `RAILS_MASTER_KEY` environment variable. If not then ask a team member (ping `@creds` in Slack). [DO NOT CHECK THIS INTO GIT](https://github.com/hackclub/hcb/blob/99fab73deb27a09a9424847e02080cb3ea5d09cf/.gitignore#L29)
148148
- If you need to edit [`config/credentials/production.yml.enc`](./config/credentials/production.yml.enc), you can now run `bin/rails credentials:edit --environment=production`.
149149
- Run the [docker_setup.sh](https://github.com/hackclub/hcb/docker_setup.sh) script to set up a local environment with Docker using a dump of the production database.

docker_setup.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
# installs all the dependencies for using HCB with Docker
44
# reach out to Max Wofford ([email protected]) if you have any questions or issues
55

6-
echo "
7-
$(tput setaf 9)HCB:$(tput sgr0) Step 0/7: Checking for config/credentials/production.key"
8-
9-
if [ ! -e ./config/credentials/production.key ]; then
10-
echo "No config/credentials/production.key found; please get one from a HCB dev team member."
11-
exit 0
12-
fi
13-
14-
echo "$(tput setaf 9)HCB:$(tput sgr0) $(tput setaf 10)Done$(tput sgr0)"
15-
166
echo "
177
$(tput setaf 9)HCB:$(tput sgr0) Step 1/7: Install Heroku (Quiet)"
188
if ! command -v heroku &> /dev/null

public/robots.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
User-agent: Twitterbot
2-
Disallow:
1+
# To disallow indexing of pages, use the `noindex` <meta/> tag or the
2+
# `X-Robots-Tag` header. Disallowing in Robots.txt does not guarantee no
3+
# indexing and may actually prevent the crawler from seeing the `noindex` meta
4+
# tag/header.
5+
#
6+
# https://support.google.com/webmasters/answer/7440203#indexed_though_blocked_by_robots_txt
37

48
User-agent: *
5-
Disallow: /
6-
Allow: /$
7-
Allow: /users/auth
8-
Allow: /branding
9+
Allow: /

0 commit comments

Comments
 (0)