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
47 changes: 47 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require:
- rubocop-capybara
- rubocop-rails
- rubocop-rspec

AllCops:
NewCops: enable
Exclude:
- 'db/migrate/2023041*.rb'
- 'db/schema.rb'
- 'bin/bundle'

Rails:
Enabled: true

# Personal Customizations
Layout/LineLength:
Max: 150

Layout/EmptyLineAfterGuardClause:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'config/environments/*.rb'

# follow standardrb
Style/StringLiterals:
EnforcedStyle: double_quotes

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

Layout/ArgumentAlignment:
EnforcedStyle: with_fixed_indentation

Layout/ArrayAlignment:
EnforcedStyle: with_fixed_indentation

Metrics/MethodLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Rails/I18nLocaleTexts:
Enabled: false
95 changes: 39 additions & 56 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,80 +1,63 @@
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.2.1"
gem "rails", "~> 7.0.4", ">= 7.0.4.3"

gem "sprockets-rails"
gem "pg", "~> 1.1"
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"
gem "turbo-rails"
gem "stimulus-rails"
gem "tailwindcss-rails"
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
gem "bcrypt", "~> 3.1.7"

gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
# gem 'googleauth'
# gem 'image_processing', '~> 1.2' # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem 'importmap-rails', '~> 1.1'
# gem 'kredis' # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem 'omniauth-rails_csrf_protection'
# gem 'redis', '~> 4.0' # Use Redis adapter to run Action Cable in production
# gem 'sassc-rails' # Use Sass to process CSS
# gem 'attr_encrypted'
gem "activerecord-session_store"
gem "active_storage-postgresql" # https://github.com/lsylvester/active_storage-postgresql
gem "bcrypt", "~> 3.1.7" # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
gem "bootsnap", require: false

# Use Sass to process CSS
# gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

################################################################################
# forestbot
gem "google-apis-core"
gem "google-apis-docs_v1"
gem "google-apis-drive_v3"
gem "google-apis-sheets_v4"
gem "importmap-rails" # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "jbuilder"
gem "omniauth"
gem "omniauth-google-oauth2"
# gem "omniauth-rails_csrf_protection"
gem "pg", "~> 1.1"
gem "puma", "~> 5.0"
gem "rack-cors"
gem "google-apis-drive_v3"
gem "google-apis-sheets_v4"
gem "google-apis-docs_v1"
gem 'google-apis-core'
# gem "googleauth"
gem "activerecord-session_store"
gem 'redis-rails'
# gem 'attr_encrypted'
# gem "importmap-rails", "~> 1.1"

# 5.0 doesn't work with session state storage crap
gem "redis", "~> 4.8.1", "< 5"

# Store activestorage files in postgres:
# rails active_storage:install
# rails active_storage:postgresql:install
# rails db:migrate
# see config in https://github.com/lsylvester/active_storage-postgresql
gem 'active_storage-postgresql'

################################################################################
gem "rails", "~> 7.0.4", ">= 7.0.4.3"
gem "redis", "~> 4.8.1", "< 5" # 5.0 doesn't work with session state storage crap
gem "redis-rails"
gem "rspec-rails", "~> 6.0"
gem "rubocop", require: false
gem "rubocop-rails", require: false
gem "rubocop-rspec", require: false
gem "sprockets-rails"
gem "standard", "~> 1.26"
gem "stimulus-rails"
gem "tailwindcss-rails"
gem "turbo-rails"
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
gem "yard", "~> 0.9.34"

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

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
# gem 'rack-mini-profiler'

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
# gem 'spring'
end

group :test do
Expand Down
62 changes: 62 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.16.0)
Expand All @@ -98,6 +99,7 @@ GEM
irb (>= 1.5.0)
reline (>= 0.3.1)
declarative (0.0.20)
diff-lcs (1.5.0)
erubi (1.12.0)
faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1)
Expand Down Expand Up @@ -140,7 +142,9 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
jwt (2.7.0)
language_server-protocol (3.17.0.3)
loofah (2.20.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -192,6 +196,9 @@ GEM
oauth2 (>= 1.4, < 3)
omniauth (~> 2.0)
os (1.1.4)
parallel (1.22.1)
parser (3.2.2.0)
ast (~> 2.4.1)
pg (1.4.6)
public_suffix (5.0.1)
puma (5.6.5)
Expand Down Expand Up @@ -230,6 +237,7 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis (4.8.1)
redis-actionpack (5.3.0)
Expand Down Expand Up @@ -257,6 +265,48 @@ GEM
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.2.5)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.1)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.11)
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.12.0)
rubocop (1.48.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.17.1)
rubocop (~> 1.41)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.19.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.19.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
selenium-webdriver (4.8.6)
Expand All @@ -278,6 +328,10 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
standard (1.26.0)
language_server-protocol (~> 3.17.0.2)
rubocop (~> 1.48.1)
rubocop-performance (~> 1.16.0)
stimulus-rails (1.2.1)
railties (>= 6.0.0)
tailwindcss-rails (2.0.27-arm64-darwin)
Expand All @@ -294,6 +348,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unicode-display_width (2.4.2)
version_gem (1.1.2)
web-console (4.2.0)
actionview (>= 6.0.0)
Expand All @@ -311,6 +366,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.34)
zeitwerk (2.6.7)

PLATFORMS
Expand Down Expand Up @@ -338,14 +394,20 @@ DEPENDENCIES
rails (~> 7.0.4, >= 7.0.4.3)
redis (~> 4.8.1, < 5)
redis-rails
rspec-rails (~> 6.0)
rubocop
rubocop-rails
rubocop-rspec
selenium-webdriver
sprockets-rails
standard (~> 1.26)
stimulus-rails
tailwindcss-rails
turbo-rails
tzinfo-data
web-console
webdrivers
yard (~> 0.9.34)

RUBY VERSION
ruby 3.2.1p31
Expand Down
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Rakefile
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand Down
3 changes: 3 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# app/channels/application_cable/channel.rb
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
3 changes: 3 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# app/channels/application_cable/connection.rb
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# app/controllers/application_controller.rb
# frozen_string_literal: true

# ApplicationController is the base class for all controllers in this application.
# It provides methods that are available to all controllers.
# We are using it to globally require authentication for all controllers.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
helper_method :current_user, :logged_in?
before_action :authenticate_user!

skip_before_action :authenticate_user!, only: [:omniauth_callback, :index, :login]
skip_before_action :authenticate_user!, only: %i[omniauth_callback index destroy] # rubocop:disable Rails/LexicallyScopedActionFilter

private

Expand All @@ -18,14 +22,12 @@ def logged_in?
# Current oauth user
def current_user
entry_dbg
@current_user ||= User.find_by_id(session[:user_id])
@current_user ||= User.find_by(id: session[:user_id])
end

# Ensure user is logged in before allowing them to access a page
def authenticate_user!
entry_dbg
unless logged_in?
redirect_to root_path, alert: 'You need to sign in first!'
end
logged_in? ? true : redirect_to(root_path, alert: "You need to sign in first!")
end
end
Loading