Skip to content
Open
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: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ ENV HOME=/home/docuseal
ENV WORKDIR=/data/docuseal

EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD wget -qO /dev/null http://localhost:3000/up || exit 1
CMD ["/app/bin/bundle", "exec", "puma", "-C", "/app/config/puma.rb", "--dir", "/app"]
5 changes: 5 additions & 0 deletions app/controllers/submitters_send_sms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class SubmittersSendSmsController < ApplicationController
load_and_authorize_resource :submitter, id_param: :submitter_slug, find_by: :slug

def create
RateLimit.call("sms_send:#{current_user.id}", limit: 10, ttl: 1.hour, enabled: true)

if SubmissionEvent.exists?(submitter: @submitter,
event_type: 'send_sms',
created_at: 10.hours.ago..Time.current)
Expand All @@ -17,5 +19,8 @@ def create
@submitter.save!

redirect_back(fallback_location: submission_path(@submitter.submission), notice: I18n.t('sms_has_been_sent'))
rescue RateLimit::LimitApproached
redirect_back(fallback_location: submission_path(@submitter.submission),
alert: I18n.t('too_many_requests_try_again_later'))
end
end
2 changes: 1 addition & 1 deletion config/initializers/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def delete
end

LoadActiveStorageConfigs.call
rescue StandardError => e
rescue StandardError, LoadError => e
Rails.logger.error(e) unless Rails.env.production?

nil
Expand Down
11 changes: 9 additions & 2 deletions lib/rate_limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ module RateLimit
STORE = begin
redis_url = ENV.fetch('REDIS_URL', nil)
if redis_url.present?
ActiveSupport::Cache::RedisCacheStore.new(url: redis_url, namespace: 'rate_limit')
ActiveSupport::Cache::RedisCacheStore.new(
url: redis_url,
namespace: 'rate_limit',
connect_timeout: 2,
read_timeout: 1,
write_timeout: 1,
reconnect_attempts: 1
)
else
ActiveSupport::Cache::MemoryStore.new
end
rescue StandardError
rescue StandardError, LoadError
ActiveSupport::Cache::MemoryStore.new
end

Expand Down
7 changes: 7 additions & 0 deletions lib/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def create_from_oauth(oauth, email)

role = ENV.fetch('GOOGLE_AUTO_CREATE_ROLE', User::ADMIN_ROLE)

unless role.in?(User::ROLES)
Rails.logger.warn("OAuth auto-create: unknown role '#{role}', falling back to '#{User::ADMIN_ROLE}'")
role = User::ADMIN_ROLE
end

Rails.logger.info("OAuth auto-create: creating user #{email} with role '#{role}'")

account.users.create!(
email:,
first_name: oauth.info.first_name.to_s,
Expand Down
Loading