Skip to content

Commit

Permalink
Add Standard configuration, and update various files for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mpressen committed Nov 22, 2024
1 parent f006e98 commit 4adf075
Show file tree
Hide file tree
Showing 41 changed files with 307 additions and 273 deletions.
56 changes: 30 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,34 @@ on:
branches: [main]

jobs:
lint_ruby:
runs-on: ubuntu-latest
permissions:
checks: write
contents: write
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Set up Ruby
uses: ruby/[email protected]
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Run Standard Ruby
uses: standardrb/standard-ruby-action@v1

scan_ruby:
runs-on: ubuntu-latest
needs: standard_ruby

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v4.2.2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1.202.0
with:
ruby-version: .ruby-version
bundler-cache: true
Expand All @@ -27,16 +46,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4

# - name: Set up Ruby
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: .ruby-version
# bundler-cache: true
uses: actions/[email protected]

- name: Setup node
uses: actions/setup-node@v4
uses: actions/setup-node@v4.1.0
with:
node-version: 20

Expand All @@ -50,10 +63,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v4.2.2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1.202.0
with:
ruby-version: .ruby-version
bundler-cache: true
Expand All @@ -64,27 +77,21 @@ jobs:
test:
runs-on: ubuntu-latest

# services:
# redis:
# image: redis
# ports:
# - 6379:6379
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libvips sqlite3

- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v4.2.2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1.202.0
with:
ruby-version: .ruby-version
bundler-cache: true

- name: Setup node
uses: actions/setup-node@v4
uses: actions/setup-node@v4.1.0
with:
node-version: 20

Expand All @@ -96,22 +103,19 @@ jobs:

- name: Prepare db
env:
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
RAILS_ENV: test
# REDIS_URL: redis://localhost:6379/0
run: bin/rails db:test:prepare

- name: Run tests
env:
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
# RAILS_ENV: test
# REDIS_URL: redis://localhost:6379/0
run: bundle exec rspec

- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v4.4.3
if: failure()
with:
name: screenshots
path: ${{ github.workspace }}/tmp/screenshots
if-no-files-found: ignore

2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/[email protected]

- name: Set up Ruby
uses: ruby/setup-ruby@v1.201.0
uses: ruby/setup-ruby@v1.202.0
with:
ruby-version: .ruby-version
bundler-cache: true
Expand Down
2 changes: 2 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins:
- standard-rails
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem "puma", ">= 5.0"
gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ windows jruby ]
gem "tzinfo-data", platforms: %i[windows jruby]

# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
gem "solid_cache"
Expand All @@ -32,15 +32,17 @@ gem "thruster", require: false

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
gem "debug", platforms: %i[mri windows], require: "debug/prelude"

# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
gem "brakeman", require: false

# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false
gem "rspec-rails"
gem "factory_bot_rails"

gem "standard"
gem "standard-rails"
end

group :development do
Expand Down
31 changes: 20 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ GEM
thor (~> 1.3)
zeitwerk (>= 2.6.18, < 3.0)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
logger (1.6.1)
loofah (2.23.1)
crass (~> 1.0.2)
Expand Down Expand Up @@ -299,22 +300,14 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
parser (>= 3.3.1.0)
rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.23.0)
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.27.0)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails-omakase (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
ruby-lsp (0.21.3)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
Expand Down Expand Up @@ -366,6 +359,21 @@ GEM
net-sftp (>= 2.1.2)
net-ssh (>= 2.8.0)
ostruct
standard (1.42.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.68.0)
standard-custom (~> 1.0.0)
standard-performance (~> 1.5)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.5.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.22.0)
standard-rails (1.2.0)
lint_roller (~> 1.0)
rubocop-rails (~> 2.26.0)
stringio (3.1.2)
thor (1.3.2)
thruster (0.1.9)
Expand Down Expand Up @@ -435,7 +443,6 @@ DEPENDENCIES
rails
rotp (~> 6.3)
rspec-rails
rubocop-rails-omakase
ruby-lsp
ruby-lsp-rails
ruby-lsp-rspec
Expand All @@ -444,6 +451,8 @@ DEPENDENCIES
solid_cache
solid_queue
sqlite3 (>= 2.1)
standard
standard-rails
thruster
tzinfo-data
vite_rails (~> 3.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def set_current_request_details
end

def authenticate
if session_record = Session.find_by_id(cookies.signed[:session_token])
if (session_record = Session.find_by_id(cookies.signed[:session_token]))
Current.session = session_record
end
end
Expand Down
27 changes: 18 additions & 9 deletions app/controllers/connections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@ class ConnectionsController < ApplicationController
skip_before_action :require_authentication
before_action :only_for_guests

rate_limit to: 10,
within: 1.minute,
only: :create,
by: -> { params[:email] },
with: -> { redirect_to new_connection_path, error: "Le maximum de tentatives a été atteint." }
rate_limit to: 1, within: 1.minute, only: :resend_otp
rate_limit to: 5,
within: 1.minute,
only: :create,
by: -> { params[:email] },
with: -> {
redirect_to new_connection_path,
error: "Le maximum de connexions a été atteint. Veuillez patienter."
}
rate_limit to: 1,
within: 1.minute,
only: :resend_otp,
with: -> {
redirect_to new_connection_path,
error: "Veuillez patienter."
}

def new
render inertia: "Auth/Connection"
end

def create
email = params[:email]
if user = User.find_by(email:)
if (user = User.find_by(email:))
user.send_otp_email
redirect_to new_session_path
else
user = User.create(email:) # will always fail because missing mandatory fields
if user.errors[:email].any?
redirect_to new_connection_path, inertia: { errors: user.errors }
redirect_to new_connection_path, inertia: {errors: user.errors}
else
redirect_to new_registration_path
end
end
end

def resend_otp
if user = User.find_by(email: params[:email])
if (user = User.find_by(email: params[:email]))
user.send_otp_email(expiration_check: false)
redirect_to new_session_path
else
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/identity/email_verifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ def create
end

private
def set_user
@user = User.find_by_token_for!(:email_verification, params[:sid])
rescue StandardError
redirect_to edit_identity_email_path, error: "That email verification link is invalid"
end

def send_email_verification
UserMailer.with(user: Current.user).email_verification.deliver_later
end
def set_user
@user = User.find_by_token_for!(:email_verification, params[:sid])
rescue
redirect_to edit_identity_email_path, error: "That email verification link is invalid"
end

def send_email_verification
UserMailer.with(user: Current.user).email_verification.deliver_later
end
end
33 changes: 17 additions & 16 deletions app/controllers/identity/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ def update
end

private
def set_user
@user = Current.user
end

def user_params
params.permit(:email, :password_challenge).with_defaults(password_challenge: "")
end
def set_user
@user = Current.user
end

def redirect_to_root
if @user.email_previously_changed?
resend_email_verification
redirect_to root_path, success: "Your email has been changed"
else
redirect_to root_path
end
end
def user_params
params.permit(:email, :password_challenge).with_defaults(password_challenge: "")
end

def resend_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
def redirect_to_root
if @user.email_previously_changed?
resend_email_verification
redirect_to root_path, success: "Your email has been changed"
else
redirect_to root_path
end
end

def resend_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
end
end
Loading

0 comments on commit 4adf075

Please sign in to comment.