Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate production CDN to new bucket #53

Merged
merged 9 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/businesses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def update

if @business.update(permitted_attributes(@business))
Analytics::Event.business_profile_updated(current_user, cookies, @business)
redirect_to developers_path, notice: t(".updated")
redirect_to edit_business_path(current_user.business), notice: t(".updated")
else
render :edit, status: :unprocessable_entity
end
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/cold_messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ColdMessagesController < ApplicationController
before_action :require_new_conversation!
before_action :require_active_subscription!
before_action :require_signed_hiring_agreement!
before_action :require_business_phone_number!

def new
message = Message.new(conversation:)
Expand Down Expand Up @@ -52,6 +53,13 @@ def require_signed_hiring_agreement!
end
end

def require_business_phone_number!
if current_user.needs_to_provide_phone_number?
store_location!
redirect_to edit_business_path(current_user.business), alert: t("errors.business_no_phone_number")
end
end

def permissions
@permissions = current_user.permissions
end
Expand Down
17 changes: 17 additions & 0 deletions app/models/business.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Business < ApplicationRecord
include PersonName
include Analytics::Profile

before_save :normalize_phone_number, if: -> { phone_number_present? }

enum :developer_notifications, %i[no daily weekly], default: :no, suffix: true

belongs_to :user
Expand All @@ -16,6 +18,11 @@ class Business < ApplicationRecord
validates :contact_name, presence: true
validates :company, presence: true
validates :bio, presence: true

validates :phone_number,
format: {with: /\A(?:\D*\d){10}\D*\z/,
message: "must be 10 digits"}, presence: true

validates :developer_notifications, inclusion: {in: developer_notifications.keys}

alias_attribute :name, :contact_name
Expand All @@ -25,4 +32,14 @@ class Business < ApplicationRecord
def visible?
!invisible?
end

private

def phone_number_present?
phone_number.present?
end

def normalize_phone_number
phone_number.delete!("^0-9")
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def needs_to_sign_hiring_agreement?
!HiringAgreements::Term.signed_by?(self)
end

def needs_to_provide_phone_number?
!business.phone_number.present?
end

def permissions
Businesses::Permission.new(subscriptions)
end
Expand Down
1 change: 1 addition & 0 deletions app/policies/business_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def default_attributes
:bio,
:avatar,
:website,
:phone_number,
:contact_role,
:survey_request_notifications
]
Expand Down
7 changes: 7 additions & 0 deletions app/views/businesses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
<%= form.text_field :contact_role, class: field_classes(form, :contact_role) %>
</div>
</div>

<div class="sm:col-span-3">
<%= form.label :phone_number, class: "block text-sm font-medium text-blue-950" %>
<div class="mt-1">
<%= form.text_field :phone_number, class: field_classes(form, :phone_number), value: number_to_phone(form.object.phone_number, pattern: /(\d{1,3})(\d{3})(\d{4})$/, area_code: true) %>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9N+Y5OCkoacvxgKG3Mt2W9aHW8dNhVQ4uek0tyDDaj9p0gkBuCBqjq9XFMBl4LMwPS6E7/naUjTwKIOYKhOiCcdjV2RqWiYB1ubkAhs4y0naScGf879XSX1kl2j0rTCmdkJujKNYjrYS0COSSHmut5XuLYnRpQAGb0bjIGyXVC4dt+wrhVGKPn9fGluIC0UbZz2vdyCr8CE2/5+bW1/b2AktfDaxdSjLlYslZMMW3I2W0iv/QK0HHDv+YZVlQNeZWPX0rp/e09BlG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fCzxFF03fpJhvH5V9htO8SY0rCFasRhJq+lz83w7YhlzXmb8bglXVCMJ5dQBsD7xjfUFnGtZsAUsjdqY0GMgaKsRuOnlhR4Bvpqs0wv6bGiEEKDYu0ZvYEWksdzkuq6x3WMKI0G8YUCGOx8dSSnBFiWKY1jdFdxbfOK8ZsgEIv+SFZuM5HMdc1cGRyYMWtKW0i+yd7B8JOad0h6d89abPxyIXbLhv9SOZ95sHBZenSQwF9tx8kgMj16U8OEbrQ7fobS7uUUcYWoILiWZAK3phNtHRtVYlmKxNEBtVKUF3qLa134vP8c6hDZ7wk2sDY+uHhiOmZJCr5Ls5dyYEV5EB8vml/wtCXvQmmDb25CZGkeAmBRnF4hcUO1w47Ai1hbHkjqLq4wljhzfSQVlRKeXDW5UZtbIknOLvqd0gQWl6U1Rs4Y9ZizhRnm/74SaeNQLzbVkX8jo7TrOZY/WAS0NGarvvNOD3H/LaIO7l3m6s/3aJxCLwz3rhOBhJxgk17PA/roSiFq/IQHQxrJCzrz5SL056EiFhP06wTRautiQLP45yb4w2Qjd5ZDt5q2z3NXeDzeg5OThLtPC2lH+gXIRv3UCqELMLYGOETdlGDZaTaENX+CqdQeMBht2wNWtqfKhp+5pl+tbB0C5FPIRw2IQJrSH07DeJ4YszzKu9tj9gSuLtE63gpYgY4yaOi3GGg==--ZKkvH0jZwurBKjYy--lwKSU5+ZcoCDTlht+pbSkA==
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ en:
contact_name: Your name
contact_role: Your job title or role
name: Your name
phone_number: Your phone number
developer:
email: E-mail
github: Github
Expand Down Expand Up @@ -548,6 +549,7 @@ en:
dir: ltr
errors:
business_blank: Fill out your business profile to message developers.
business_no_phone_number: Please provide your business phone number.
business_subscription_inactive: Sign up for a business subscription to message developers.
business_subscription_no_profile: Before subscribing, fill out your business profile.
developer_blank: Please create a developer profile first.
Expand Down
3 changes: 2 additions & 1 deletion config/sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
Rails.application.credentials.dig(:aws, :sitemaps_bucket),
aws_access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
aws_secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
aws_region: Rails.application.credentials.dig(:aws, :region)
aws_region: Rails.application.credentials.dig(:aws, :region),
virtual_host: false
)
end

Expand Down
1 change: 1 addition & 0 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ amazon:
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: <%= Rails.application.credentials.dig(:aws, :region) %>
bucket: <%= Rails.application.credentials.dig(:aws, :bucket) %>
virtual_host: true
5 changes: 5 additions & 0 deletions db/migrate/20240312161157_add_phone_number_to_businesses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhoneNumberToBusinesses < ActiveRecord::Migration[7.0]
def change
add_column :businesses, :phone_number, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create_business!(name, attributes = {})
attributes.merge!({
user: create_user!(name),
contact_name: Faker::Name.name,
phone_number: rand.to_s[2..11],
company:,
bio: Faker::Lorem.paragraph(sentence_count: 10)
})
Expand Down
10 changes: 5 additions & 5 deletions lib/tasks/sendgrid_sync.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace :users do
}

if u.developer
contact[:custom_fields]["e16_T"] = u.developer.linkedin
contact[:custom_fields]["e18_T"] = u.developer.github
contact[:custom_fields]["e53_T"] = u.developer.codeboxx_student
contact[:custom_fields]["e15_T"] = u.developer.website
contact[:custom_fields]["e16_T"] = u.developer.linkedin || ""
contact[:custom_fields]["e18_T"] = u.developer.github || ""
contact[:custom_fields]["e53_T"] = "1" if u.developer.codeboxx_student
contact[:custom_fields]["e15_T"] = u.developer.website || ""
end

contacts << contact
Expand All @@ -30,7 +30,7 @@ namespace :users do

response = sg.client._("marketing/contacts").put(request_body: {contacts: contacts})

if response.status_code != 202
if response.status_code != "202"
Rails.logger.error "Failed to update SendGrid contacts with error #{response.status_code} #{response.body}"
else
Rails.logger.info "Updated #{contacts.length} contacts(s)"
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/businesses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ one:
contact_name: Business Owner One
company: Company One
bio: We are Company One.
phone_number: "1111111111"

subscriber:
user: subscribed_business
contact_name: Business Owner with Conversation
company: Conversation Business
bio: We are Conversation Business.
phone_number: "2222222222"
5 changes: 3 additions & 2 deletions test/integration/businesses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class BusinessesTest < ActionDispatch::IntegrationTest
website: "http://www.newwebsite.com"
}
}
assert_redirected_to developers_path
assert_redirected_to edit_business_path(business)
follow_redirect!

assert_equal "New Owner Name", business.reload.name
Expand Down Expand Up @@ -123,7 +123,7 @@ class BusinessesTest < ActionDispatch::IntegrationTest
website: "http://www.newwebsite.com"
}
}
assert_redirected_to developers_path
assert_redirected_to edit_business_path(business)
assert_equal "New Name", business.reload.name
end

Expand Down Expand Up @@ -198,6 +198,7 @@ def valid_business_params
contact_role: "Director",
company: "Business, LLC",
bio: "We're in the business for business.",
phone_number: "1234567890",
avatar: fixture_file_upload("basecamp.png", "image/png"),
website: "http://www.example.com"
}
Expand Down
19 changes: 19 additions & 0 deletions test/models/business_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,23 @@ class BusinessTest < ActiveSupport::TestCase

assert business.no_developer_notifications?
end

test "should require a phone number" do
business = Business.new(business_attributes.merge(phone_number: nil))
assert_not business.valid?, "Business should not be valid without a phone number"
assert_includes business.errors[:phone_number], "can't be blank"
end

test "phone number must be 10 digits" do
valid_phone_number = "1234567890"
business = Business.new(business_attributes.merge(phone_number: valid_phone_number))
assert business.valid?, "Business with valid phone number format should be valid"

invalid_phone_numbers = ["12345", "abcdefghij", "123-456-78900", "12345678901"]
invalid_phone_numbers.each do |invalid_phone_number|
business.phone_number = invalid_phone_number
assert_not business.valid?, "#{invalid_phone_number} should be an invalid phone number format"
assert_includes business.errors[:phone_number], "must be 10 digits", "#{invalid_phone_number} should fail the 10 digits format validation"
end
end
end
1 change: 1 addition & 0 deletions test/support/helpers/businesses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def business_attributes
name: "Name",
company: "Company",
bio: "Bio",
phone_number: "1234567890",
avatar: active_storage_blobs(:basecamp),
developer_notifications: :no
}
Expand Down
Loading