Compare commits

..

No commits in common. "6aba5e234f44691966c95b02b6369606ac4a06b0" and "d8ee5972aad14dbc6128b497640d3da2eaee4668" have entirely different histories.

54 changed files with 112 additions and 1228 deletions

View File

@ -20,8 +20,6 @@ gem 'jsonapi-rails'
gem 'rack-cors' gem 'rack-cors'
gem 'react-rails' gem 'react-rails'
gem 'rubytree' gem 'rubytree'
gem 'acts_as_tenant'
gem 'httparty'
group :development, :test do group :development, :test do
gem 'annotaterb' gem 'annotaterb'
@ -37,10 +35,7 @@ end
group :development do group :development do
gem 'rubocop' gem 'rubocop'
gem 'web-console' gem 'web-console'
gem 'letter_opener_web'
end end
gem 'chroma' gem 'chroma'
gem 'solid_queue', '~> 1.0' gem 'solid_queue', '~> 1.0'
gem "devise", "~> 4.9"

View File

@ -72,8 +72,6 @@ GEM
securerandom (>= 0.3) securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5) tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1) uri (>= 0.13.1)
acts_as_tenant (1.0.1)
rails (>= 6.0)
addressable (2.8.7) addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0) public_suffix (>= 2.0.2, < 7.0)
annotaterb (4.13.0) annotaterb (4.13.0)
@ -83,15 +81,12 @@ GEM
babel-source (>= 4.0, < 6) babel-source (>= 4.0, < 6)
execjs (~> 2.0) execjs (~> 2.0)
base64 (0.2.0) base64 (0.2.0)
bcrypt (3.1.20)
benchmark (0.4.0) benchmark (0.4.0)
bigdecimal (3.1.8) bigdecimal (3.1.8)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.18.4) bootsnap (1.18.4)
msgpack (~> 1.2) msgpack (~> 1.2)
builder (3.3.0) builder (3.3.0)
childprocess (5.1.0)
logger (~> 1.5)
chroma (0.2.0) chroma (0.2.0)
coderay (1.1.3) coderay (1.1.3)
concurrent-ruby (1.3.4) concurrent-ruby (1.3.4)
@ -102,12 +97,6 @@ GEM
debug (1.9.2) debug (1.9.2)
irb (~> 1.10) irb (~> 1.10)
reline (>= 0.3.8) reline (>= 0.3.8)
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.5.1) diff-lcs (1.5.1)
drb (2.2.1) drb (2.2.1)
erubi (1.13.0) erubi (1.13.0)
@ -126,10 +115,6 @@ GEM
raabro (~> 1.4) raabro (~> 1.4)
globalid (1.2.1) globalid (1.2.1)
activesupport (>= 6.1) activesupport (>= 6.1)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.6) i18n (1.14.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
importmap-rails (2.0.3) importmap-rails (2.0.3)
@ -143,7 +128,7 @@ GEM
jbuilder (2.13.0) jbuilder (2.13.0)
actionview (>= 5.0.0) actionview (>= 5.0.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
json (2.8.2) json (2.7.5)
json-schema (5.0.1) json-schema (5.0.1)
addressable (~> 2.8) addressable (~> 2.8)
jsonapi-deserializable (0.2.0) jsonapi-deserializable (0.2.0)
@ -158,16 +143,6 @@ GEM
jsonapi-serializable (0.3.1) jsonapi-serializable (0.3.1)
jsonapi-renderer (~> 0.2.0) jsonapi-renderer (~> 0.2.0)
language_server-protocol (3.17.0.3) language_server-protocol (3.17.0.3)
launchy (3.0.1)
addressable (~> 2.8)
childprocess (~> 5.0)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
letter_opener_web (3.0.0)
actionmailer (>= 6.1)
letter_opener (~> 1.9)
railties (>= 6.1)
rexml
license_finder (7.2.1) license_finder (7.2.1)
bundler bundler
csv (~> 3.2) csv (~> 3.2)
@ -176,7 +151,7 @@ GEM
tomlrb (>= 1.3, < 2.1) tomlrb (>= 1.3, < 2.1)
with_env (= 1.1.0) with_env (= 1.1.0)
xml-simple (~> 1.1.9) xml-simple (~> 1.1.9)
logger (1.6.2) logger (1.6.1)
loofah (2.23.1) loofah (2.23.1)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.12.0) nokogiri (>= 1.12.0)
@ -192,8 +167,6 @@ GEM
money (6.19.0) money (6.19.0)
i18n (>= 0.6.4, <= 2) i18n (>= 0.6.4, <= 2)
msgpack (1.7.2) msgpack (1.7.2)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
net-imap (0.5.1) net-imap (0.5.1)
date date
net-protocol net-protocol
@ -204,29 +177,27 @@ GEM
net-smtp (0.5.0) net-smtp (0.5.0)
net-protocol net-protocol
nio4r (2.7.4) nio4r (2.7.4)
nokogiri (1.16.8-aarch64-linux) nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.8-arm-linux) nokogiri (1.16.7-arm-linux)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.8-arm64-darwin) nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.8-x86-linux) nokogiri (1.16.7-x86-linux)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.8-x86_64-darwin) nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.8-x86_64-linux) nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.26.3) parallel (1.26.3)
parser (3.3.6.0) parser (3.3.5.1)
ast (~> 2.4.1) ast (~> 2.4.1)
racc racc
pg (1.5.9) pg (1.5.9)
pry (0.15.0) pry (0.15.0)
coderay (~> 1.1) coderay (~> 1.1)
method_source (~> 1.0) method_source (~> 1.0)
psych (5.2.1) psych (5.2.0)
date
stringio stringio
public_suffix (6.0.1) public_suffix (6.0.1)
puma (6.5.0) puma (6.5.0)
@ -260,9 +231,9 @@ GEM
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
minitest minitest
nokogiri (>= 1.6) nokogiri (>= 1.6)
rails-html-sanitizer (1.6.1) rails-html-sanitizer (1.6.0)
loofah (~> 2.21) loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) nokogiri (~> 1.14)
railties (8.0.0) railties (8.0.0)
actionpack (= 8.0.0) actionpack (= 8.0.0)
activesupport (= 8.0.0) activesupport (= 8.0.0)
@ -285,12 +256,9 @@ GEM
redis-client (>= 0.22.0) redis-client (>= 0.22.0)
redis-client (0.22.2) redis-client (0.22.2)
connection_pool connection_pool
regexp_parser (2.9.3) regexp_parser (2.9.2)
reline (0.5.12) reline (0.5.12)
io-console (~> 0.5) io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.9) rexml (3.3.9)
rspec-core (3.13.2) rspec-core (3.13.2)
rspec-support (~> 3.13.0) rspec-support (~> 3.13.0)
@ -324,17 +292,17 @@ GEM
rswag-ui (2.16.0) rswag-ui (2.16.0)
actionpack (>= 5.2, < 8.1) actionpack (>= 5.2, < 8.1)
railties (>= 5.2, < 8.1) railties (>= 5.2, < 8.1)
rubocop (1.69.0) rubocop (1.68.0)
json (~> 2.3) json (~> 2.3)
language_server-protocol (>= 3.17.0) language_server-protocol (>= 3.17.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.3.0.2) parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0) regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.36.1, < 2.0) rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0) unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.2) rubocop-ast (1.33.0)
parser (>= 3.3.1.0) parser (>= 3.3.1.0)
ruby-progressbar (1.13.0) ruby-progressbar (1.13.0)
rubytree (2.1.0) rubytree (2.1.0)
@ -372,8 +340,6 @@ GEM
unicode-display_width (2.6.0) unicode-display_width (2.6.0)
uri (1.0.2) uri (1.0.2)
useragent (0.16.10) useragent (0.16.10)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1) web-console (4.2.1)
actionview (>= 6.0.0) actionview (>= 6.0.0)
activemodel (>= 6.0.0) activemodel (>= 6.0.0)
@ -396,20 +362,16 @@ PLATFORMS
x86_64-linux x86_64-linux
DEPENDENCIES DEPENDENCIES
acts_as_tenant
annotaterb annotaterb
bootsnap bootsnap
chroma chroma
csv csv
debug debug
devise (~> 4.9)
factory_bot_rails factory_bot_rails
faker faker
httparty
importmap-rails importmap-rails
jbuilder jbuilder
jsonapi-rails jsonapi-rails
letter_opener_web
license_finder license_finder
money money
pg (~> 1.1) pg (~> 1.1)

View File

@ -57,16 +57,7 @@ The backend service will seed the database with fake data. It's worth noting tha
The backend, frontend and workers have hot-reloading enabled, so changes made to the codebase should be reflected in the application on the next request. The backend, frontend and workers have hot-reloading enabled, so changes made to the codebase should be reflected in the application on the next request.
Once all containers have started, visit http://libre-wedding-planner.app.localhost/default/dashboard to load the application. Once all containers have started, visit http://libre-wedding-planner.app.localhost/dashboard to load the application.
## Multitenancy
LibreWeddingPlanner is designed to manage multiple weddings in a single host. All URLs (in the API and the frontend) are scoped under a slug that is unique per wedding. The slug is made of lowercase letters, numbers, and dashes (-).
The development environment is seeded with a wedding whose slug is `default`.
## Email delivery
In the development environment, real emails will not be sent. You can visit http://libre-wedding-planner.app.localhost/letter_opener/ to get a list of emails generated by the application.
## Testing ## Testing

View File

@ -1,9 +1,6 @@
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
set_current_tenant_through_filter
before_action :set_tenant
before_action :authenticate_user!
after_action :set_csrf_cookie after_action :set_csrf_cookie
skip_before_action :verify_authenticity_token, if: :development_swagger? skip_before_action :verify_authenticity_token, if: :development_swagger?
@ -31,29 +28,9 @@ class ApplicationController < ActionController::Base
private private
def validate_captcha!
Rails.logger.info("Captcha params: #{captcha_params}")
return if LibreCaptcha.new.valid?(id: captcha_params[:id], answer: captcha_params[:answer])
render json: { error: 'Incorrect CAPTCHA solution' }, status: :unprocessable_entity
end
def captcha_params
params.expect(captcha: [:id, :answer])
end
def default_url_options(options = {})
options.merge(path_params: { slug: ActsAsTenant.current_tenant&.slug })
end
def set_tenant
set_current_tenant(Wedding.find_by!(slug: params[:slug]))
end
def development_swagger? def development_swagger?
Rails.env.test? || Rails.env.test? ||
Rails.env.development? && request.headers['referer']&.include?('/api-docs/index.html') Rails.env.development? && request.headers['referer'].include?('/api-docs/index.html')
end end
def set_csrf_cookie def set_csrf_cookie

View File

@ -1,13 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class CaptchaController < ApplicationController
skip_before_action :authenticate_user!
def create
id = LibreCaptcha.new.get_id
render json: {
id:,
media_url: media_captcha_index_url(id:)
}, status: :created
end
end

View File

@ -1,23 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class Users::ConfirmationsController < Devise::ConfirmationsController
clear_respond_to
respond_to :json
def show
super do |resource|
if resource.errors.empty?
respond_to do |format|
format.json { render json: resource, status: :ok }
format.any { redirect_to root_path }
end
else
render json: {
message: 'Record invalid',
errors: resource.errors.full_messages
}, status: :unprocessable_entity
end
return
end
end
end

View File

@ -1,28 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class Users::RegistrationsController < Devise::RegistrationsController
clear_respond_to
respond_to :json
before_action :validate_captcha!, only: :create
def create
wedding = Wedding.create(wedding_params)
unless wedding.persisted?
render json: { errors: wedding.errors.full_messages }, status: :unprocessable_entity
return
end
ActsAsTenant.with_tenant(wedding) do
super do |user|
wedding.destroy unless user.persisted?
end
end
end
private
def wedding_params
{ slug: params[:slug], **params.expect(wedding: :date) }
end
end

View File

@ -1,6 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class Users::SessionsController < Devise::SessionsController
clear_respond_to
respond_to :json
end

View File

@ -3,23 +3,21 @@
class TableSimulatorJob < ApplicationJob class TableSimulatorJob < ApplicationJob
queue_as :default queue_as :default
def perform(wedding_id) def perform(*_args)
ActsAsTenant.with_tenant(Wedding.find(wedding_id)) do engine = VNS::Engine.new
engine = VNS::Engine.new
engine.add_perturbation(Tables::Swap) engine.add_perturbation(Tables::Swap)
engine.add_perturbation(Tables::Shift) engine.add_perturbation(Tables::Shift)
initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10) initial_solution = Tables::Distribution.new(min_per_table: 8, max_per_table: 10)
initial_solution.random_distribution(Guest.potential.shuffle) initial_solution.random_distribution(Guest.potential.shuffle)
engine.initial_solution = initial_solution engine.initial_solution = initial_solution
engine.target_function(&:discomfort) engine.target_function(&:discomfort)
best_solution = engine.run best_solution = engine.run
best_solution.save! best_solution.save!
end
end end
end end

View File

@ -10,18 +10,8 @@
# pricing_type :enum default("fixed"), not null # pricing_type :enum default("fixed"), not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# wedding_id :uuid not null
#
# Indexes
#
# index_expenses_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (wedding_id => weddings.id)
# #
class Expense < ApplicationRecord class Expense < ApplicationRecord
acts_as_tenant :wedding
enum :pricing_type, enum :pricing_type,
fixed: 'fixed', fixed: 'fixed',
per_person: 'per_person' per_person: 'per_person'

View File

@ -12,22 +12,17 @@
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# parent_id :uuid # parent_id :uuid
# wedding_id :uuid not null
# #
# Indexes # Indexes
# #
# index_groups_on_name (name) UNIQUE # index_groups_on_name (name) UNIQUE
# index_groups_on_parent_id (parent_id) # index_groups_on_parent_id (parent_id)
# index_groups_on_wedding_id (wedding_id)
# #
# Foreign Keys # Foreign Keys
# #
# fk_rails_... (parent_id => groups.id) # fk_rails_... (parent_id => groups.id)
# fk_rails_... (wedding_id => weddings.id)
# #
class Group < ApplicationRecord class Group < ApplicationRecord
acts_as_tenant :wedding
validates :name, uniqueness: true validates :name, uniqueness: true
validates :name, :order, presence: true validates :name, :order, presence: true

View File

@ -11,20 +11,16 @@
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# group_id :uuid not null # group_id :uuid not null
# wedding_id :uuid not null
# #
# Indexes # Indexes
# #
# index_guests_on_group_id (group_id) # index_guests_on_group_id (group_id)
# index_guests_on_wedding_id (wedding_id)
# #
# Foreign Keys # Foreign Keys
# #
# fk_rails_... (group_id => groups.id) # fk_rails_... (group_id => groups.id)
# fk_rails_... (wedding_id => weddings.id)
# #
class Guest < ApplicationRecord class Guest < ApplicationRecord
acts_as_tenant :wedding
belongs_to :group belongs_to :group
enum :status, { enum :status, {
@ -49,6 +45,6 @@ class Guest < ApplicationRecord
def recalculate_simulations def recalculate_simulations
TablesArrangement.delete_all TablesArrangement.delete_all
ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new(wedding_id) }) ActiveJob.perform_all_later(50.times.map { TableSimulatorJob.new })
end end
end end

View File

@ -10,22 +10,18 @@
# updated_at :datetime not null # updated_at :datetime not null
# guest_id :uuid not null # guest_id :uuid not null
# tables_arrangement_id :uuid not null # tables_arrangement_id :uuid not null
# wedding_id :uuid not null
# #
# Indexes # Indexes
# #
# index_seats_on_guest_id (guest_id) # index_seats_on_guest_id (guest_id)
# index_seats_on_tables_arrangement_id (tables_arrangement_id) # index_seats_on_tables_arrangement_id (tables_arrangement_id)
# index_seats_on_wedding_id (wedding_id)
# #
# Foreign Keys # Foreign Keys
# #
# fk_rails_... (guest_id => guests.id) # fk_rails_... (guest_id => guests.id)
# fk_rails_... (tables_arrangement_id => tables_arrangements.id) ON DELETE => cascade # fk_rails_... (tables_arrangement_id => tables_arrangements.id) ON DELETE => cascade
# fk_rails_... (wedding_id => weddings.id)
# #
class Seat < ApplicationRecord class Seat < ApplicationRecord
acts_as_tenant :wedding
belongs_to :guest belongs_to :guest
belongs_to :table_arrangement belongs_to :table_arrangement
end end

View File

@ -9,18 +9,8 @@
# name :string not null # name :string not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# wedding_id :uuid not null
#
# Indexes
#
# index_tables_arrangements_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (wedding_id => weddings.id)
# #
class TablesArrangement < ApplicationRecord class TablesArrangement < ApplicationRecord
acts_as_tenant :wedding
has_many :seats has_many :seats
has_many :guests, through: :seats has_many :guests, through: :seats

View File

@ -1,40 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
# == Schema Information
#
# Table name: users
#
# id :uuid not null, primary key
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# email :string default(""), not null
# encrypted_password :string default(""), not null
# failed_attempts :integer default(0), not null
# locked_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# unconfirmed_email :string
# unlock_token :string
# created_at :datetime not null
# updated_at :datetime not null
# wedding_id :uuid not null
#
# Indexes
#
# index_users_on_confirmation_token (confirmation_token) UNIQUE
# index_users_on_email (email) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (wedding_id => weddings.id)
#
class User < ApplicationRecord
acts_as_tenant :wedding
devise :database_authenticatable, :registerable,
:recoverable, :validatable, :confirmable, :lockable
end

View File

@ -1,22 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
# == Schema Information
#
# Table name: weddings
#
# id :uuid not null, primary key
# date :date not null
# slug :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_weddings_on_slug (slug) UNIQUE
#
class Wedding < ApplicationRecord
SLUG_REGEX = /[a-z\d-]+/
validates :date, presence: true
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ }
end

View File

@ -1,20 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class LibreCaptcha
def get_id
HTTParty.post("http://libre-captcha:8888/v2/captcha",
body: {
input_type: "text",
level: :hard,
media: 'image/png',
size: '350x100'
}.to_json
).then { |raw| JSON.parse(raw)['id'] }
end
def valid?(id:, answer:)
HTTParty.post("http://libre-captcha:8888/v2/answer",
body: { id:, answer: }.to_json
).then { |raw| JSON.parse(raw)['result'] == 'True' }
end
end

View File

@ -28,7 +28,10 @@ module VNS
@best_solution = @initial_solution @best_solution = @initial_solution
@best_score = @target_function.call(@best_solution) @best_score = @target_function.call(@best_solution)
puts "Initial score: #{@best_score.to_f}"
self.class.sequence(@perturbations).each do |perturbation| self.class.sequence(@perturbations).each do |perturbation|
puts "Running perturbation: #{perturbation.name}"
optimize(perturbation.new(@best_solution)) optimize(perturbation.new(@best_solution))
end end
@ -45,6 +48,8 @@ module VNS
@best_solution = alternative_solution.deep_dup @best_solution = alternative_solution.deep_dup
@best_score = score @best_score = score
puts "New lowest score: #{@best_score.to_f}"
return optimize(perturbation.class.new(@best_solution)) return optimize(perturbation.class.new(@best_solution))
end end
end end

View File

@ -1,7 +0,0 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(slug: ActsAsTenant.current_tenant&.slug, confirmation_token: @token) %></p>

View File

@ -1,9 +0,0 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p>Hello <%= @email %>!</p>
<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>

View File

@ -1,5 +0,0 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>

View File

@ -1,10 +0,0 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(slug: ActsAsTenant.current_tenant&.slug, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

View File

@ -1,9 +0,0 @@
<%# Copyright (C) 2024 Manuel Bustillo %>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(slug: ActsAsTenant.current_tenant&.slug, unlock_token: @token) %></p>

View File

@ -40,10 +40,8 @@ Rails.application.configure do
# Don't care if the mailer can't send. # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'libre-wedding-planner.app.localhost/api' }
config.action_mailer.delivery_method = :letter_opener_web
config.action_mailer.perform_deliveries = true
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log config.active_support.deprecation = :log

View File

@ -1,5 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
ActsAsTenant.configure do |config|
config.require_tenant = !Rails.env.test?
end

View File

@ -1,315 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
# frozen_string_literal: true
# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
# breaking changes in upgrades (i.e., in the event that future versions of
# Devise change the default values for those options).
#
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = '11353ae8c2bf66dd638d9edff9ec82856aecf74bba6c598273559a8750c902d3439da1b301e40c47578577a971f1058dbf37211c107fba5107c29baa654e9888'
# ==> Controller configuration
# Configure the parent class to the devise controllers.
# config.parent_controller = 'DeviseController'
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'noreply@libreweddingplanner.org'
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
# Configure the parent class responsible to send e-mails.
# config.parent_mailer = 'ActionMailer::Base'
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# just :email. You can configure it to use [:username, :subdomain], so for
# authenticating a user, both parameters are required. Remember that those
# parameters are used only when authenticating and not when retrieving from
# session. If you need permissions, you should implement that in a before filter.
# You can also supply a hash where the value is a boolean determining whether
# or not authentication should be aborted when the value is not present.
# config.authentication_keys = [:email]
# Configure parameters from the request object used for authentication. Each entry
# given should be a request method and it will automatically be passed to the
# find_for_authentication method and considered in your model lookup. For instance,
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
# The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = []
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [:email]
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:email]
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# given strategies, for example, `config.params_authenticatable = [:database]` will
# enable it only for database (email + password) authentication.
# config.params_authenticatable = true
# Tell if authentication through HTTP Auth is enabled. False by default.
# It can be set to an array that will enable http authentication only for the
# given strategies, for example, `config.http_authenticatable = [:database]` will
# enable it only for database authentication.
# For API-only applications to support authentication "out-of-the-box", you will likely want to
# enable this with :database unless you are using a custom strategy.
# The supported strategies are:
# :database = Support basic authentication with authentication key + password
# config.http_authenticatable = false
# If 401 status code should be returned for AJAX requests. True by default.
# config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. 'Application' by default.
# config.http_authentication_realm = 'Application'
# It will change confirmation, password recovery and other workflows
# to behave the same regardless if the e-mail provided was right or wrong.
# Does not affect registerable.
config.paranoid = true
# By default Devise will store the user in session. You can skip storage for
# particular strategies by setting this option.
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing skip: :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]
# By default, Devise cleans up the CSRF token on authentication to
# avoid CSRF token fixation attacks. This means that, when using AJAX
# requests for sign in and sign up, you need to get a new CSRF token
# from the server. You can disable this option at your own risk.
# config.clean_up_csrf_token_on_authentication = true
# When false, Devise will not attempt to reload routes on eager load.
# This can reduce the time taken to boot the app but if your application
# requires the Devise mappings to be loaded during boot time the application
# won't boot properly.
# config.reload_routes = true
# ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 12. If
# using other algorithms, it sets how many times you want the password to be hashed.
# The number of stretches used for generating the hashed password are stored
# with the hashed password. This allows you to change the stretches without
# invalidating existing passwords.
#
# Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments. Note that, for bcrypt (the default
# algorithm), the cost increases exponentially with the number of stretches (e.g.
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
config.stretches = Rails.env.test? ? 1 : 12
# Set up a pepper to generate the hashed password.
# config.pepper = '6f86425fd587f80f4a338a785a6abbbccf8de7322f70fcccf356118d982942c9421819445f9d236a296fa3c431ef5e509be20e6db03f90ec2b42aa78f3a7e526'
# Send a notification to the original email when the user's email is changed.
config.send_email_changed_notification = false
# Send a notification email when the user's password is changed.
config.send_password_change_notification = false
# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming their account. For instance, if set to 2.days, the user will be
# able to access the website for two days without confirming their account,
# access will be blocked just in the third day.
# You can also set it to nil, which will allow the user to access the website
# without confirming their account.
# Default is 0.days, meaning the user cannot access the website without
# confirming their account.
# config.allow_unconfirmed_access_for = 2.days
# A period that the user is allowed to confirm their account before their
# token becomes invalid. For example, if set to 3.days, the user can confirm
# their account within 3 days after the mail was sent, but on the fourth day
# their account can't be confirmed with the token any more.
# Default is nil, meaning there is no restriction on how long a user can take
# before confirming their account.
config.confirm_within = 3.days
# If true, requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed, new email is stored in
# unconfirmed_email column, and copied to email column on successful confirmation.
config.reconfirmable = true
# Defines which key will be used when confirming an account
# config.confirmation_keys = [:email]
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
# Invalidates all the remember me tokens when the user signs out.
config.expire_all_remember_me_on_sign_out = true
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false
# Options to be passed to the created cookie. For instance, you can set
# secure: true in order to force SSL only cookies.
# config.rememberable_options = {}
# ==> Configuration for :validatable
# Range for password length.
config.password_length = 15..128
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity.
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
# ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
# :none = No lock strategy. You should handle locking by yourself.
config.lock_strategy = :failed_attempts
# Defines which key will be used when locking and unlocking an account
# config.unlock_keys = [:email]
# Defines which strategy will be used to unlock an account.
# :email = Sends an unlock link to the user email
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
# :both = Enables both strategies
# :none = No unlock strategy. You should handle unlocking by yourself.
config.unlock_strategy = :both
# Number of authentication tries before locking an account if lock_strategy
# is failed attempts.
config.maximum_attempts = 10
# Time interval to unlock the account if :time is enabled as unlock_strategy.
config.unlock_in = 1.hour
# Warn on the last attempt before the account is locked.
# config.last_attempt_warning = true
# ==> Configuration for :recoverable
#
# Defines which key will be used when recovering the password for an account
# config.reset_password_keys = [:email]
# Time interval you can reset your password with a reset password key.
# Don't put a too small interval or your users won't have the time to
# change their passwords.
config.reset_password_within = 6.hours
# When set to false, does not sign a user in automatically after their password is
# reset. Defaults to true, so a user is signed in automatically after a reset.
config.sign_in_after_reset_password = true
# ==> Configuration for :encryptable
# Allow you to use another hashing or encryption algorithm besides bcrypt (default).
# You can use :sha1, :sha512 or algorithms from others authentication tools as
# :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
# for default behavior) and :restful_authentication_sha1 (then you should set
# stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
#
# Require the `devise-encryptable` gem when using anything other than bcrypt
# config.encryptor = :sha512
# ==> Scopes configuration
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
config.scoped_views = true
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
# config.default_scope = :user
# Set this configuration to false if you want /users/sign_out to sign out
# only the current scope. By default, Devise signs out all scopes.
# config.sign_out_all_scopes = true
# ==> Navigation configuration
# Lists the formats that should be treated as navigational. Formats like
# :html should redirect to the sign in page when the user does not have
# access, but formats like :xml or :json, should return 401.
#
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists.
#
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ['*/*', :html, :turbo_stream]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
# ==> Warden configuration
# If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block.
#
# config.warden do |manager|
# manager.intercept_401 = false
# manager.default_strategies(scope: :user).unshift :some_external_strategy
# end
# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
# is mountable, there are some extra configurations to be taken into account.
# The following options are available, assuming the engine is mounted as:
#
# mount MyEngine, at: '/my_engine'
#
# The router that invoked `devise_for`, in the example above, would be:
# config.router_name = :my_engine
#
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = '/my_engine/users/auth'
# ==> Hotwire/Turbo configuration
# When using Devise with Hotwire/Turbo, the http status for error responses
# and some redirects must match the following. The default in Devise for existing
# apps is `200 OK` and `302 Found` respectively, but new apps are generated with
# these new defaults that match Hotwire/Turbo behavior.
# Note: These might become the new default in future versions of Devise.
config.responder.error_status = :unprocessable_entity
config.responder.redirect_status = :see_other
# ==> Configuration for :registerable
# When set to false, does not sign a user in automatically after their password is
# changed. Defaults to true, so a user is signed in automatically after changing a password.
# config.sign_in_after_change_password = true
end

View File

@ -1,65 +0,0 @@
# Additional translations at https://github.com/heartcombo/devise/wiki/I18n
en:
devise:
confirmations:
confirmed: "Your email address has been successfully confirmed."
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account is not activated yet."
invalid: "Invalid %{authentication_keys} or password."
locked: "Your account is locked."
last_attempt: "You have one more attempt before your account is locked."
not_found_in_database: "Invalid %{authentication_keys} or password."
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your email address before continuing."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock instructions"
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
passwords:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password has been changed successfully. You are now signed in."
updated_not_active: "Your password has been changed successfully."
registrations:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have signed up successfully."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
updated: "Your account has been updated successfully."
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again."
sessions:
signed_in: "Signed in successfully."
signed_out: "Signed out successfully."
already_signed_out: "Signed out successfully."
unlocks:
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
errors:
messages:
already_confirmed: "was already confirmed, please try signing in"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
expired: "has expired, please request a new one"
not_found: "not found"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"

View File

@ -1,36 +1,16 @@
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
Rails.application.routes.draw do Rails.application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
scope ":slug", constraints: { slug: Wedding::SLUG_REGEX } do
devise_for :users, skip: [:registration, :session, :confirmation]
devise_scope :user do
post 'users', to: 'users/registrations#create'
post '/users/sign_in', to: 'users/sessions#create'
delete '/users/sign_out', to: 'users/sessions#destroy'
get '/users/confirmation', to: 'users/confirmations#show', as: :confirmation
end
resources :groups, only: :index
resources :guests, only: %i[index create update destroy] do
post :bulk_update, on: :collection
end
resources :expenses, only: %i[index update] do
get :summary, on: :collection
end
resources :tables_arrangements, only: %i[index show]
end
resources :captcha, only: :create do
get 'v2/media', to: 'captcha#media', on: :collection, as: :media
end
mount Rswag::Ui::Engine => '/api-docs' mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs' mount Rswag::Api::Engine => '/api-docs'
resources :groups, only: :index
resources :guests, only: %i[index create update destroy] do
post :bulk_update, on: :collection
end
resources :expenses, only: %i[index update] do
get :summary, on: :collection
end
resources :tables_arrangements, only: %i[index show]
get 'up' => 'rails/health#show', as: :rails_health_check get 'up' => 'rails/health#show', as: :rails_health_check
root to: redirect('/dashboard')
end end

View File

@ -1,46 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
# frozen_string_literal: true
class DeviseCreateUsers < ActiveRecord::Migration[8.0]
def change
create_table :users, id: :uuid do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
# t.datetime :remember_created_at
## Trackable
# t.integer :sign_in_count, default: 0, null: false
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.string :current_sign_in_ip
# t.string :last_sign_in_ip
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
add_index :users, :confirmation_token, unique: true
add_index :users, :unlock_token, unique: true
end
end

View File

@ -1,12 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class CreateWeddings < ActiveRecord::Migration[8.0]
def change
create_table :weddings, id: :uuid do |t|
t.string :slug, null: false, index: { unique: true }
t.date :date, null: false
t.timestamps
end
end
end

View File

@ -1,9 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
class AddWeddingIdToModels < ActiveRecord::Migration[8.0]
def change
[:expenses, :guests, :seats, :tables_arrangements, :groups, :users].each do |table|
add_reference table, :wedding, type: :uuid, null: false, foreign_key: true
end
end
end

48
db/schema.rb generated
View File

@ -12,7 +12,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do ActiveRecord::Schema[8.0].define(version: 2024_11_11_063741) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"
@ -26,8 +26,6 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do
t.enum "pricing_type", default: "fixed", null: false, enum_type: "pricing_types" t.enum "pricing_type", default: "fixed", null: false, enum_type: "pricing_types"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.uuid "wedding_id", null: false
t.index ["wedding_id"], name: "index_expenses_on_wedding_id"
end end
create_table "groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -38,10 +36,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.uuid "parent_id" t.uuid "parent_id"
t.string "color" t.string "color"
t.uuid "wedding_id", null: false
t.index ["name"], name: "index_groups_on_name", unique: true t.index ["name"], name: "index_groups_on_name", unique: true
t.index ["parent_id"], name: "index_groups_on_parent_id" t.index ["parent_id"], name: "index_groups_on_parent_id"
t.index ["wedding_id"], name: "index_groups_on_wedding_id"
end end
create_table "guests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "guests", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -51,9 +47,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do
t.uuid "group_id", null: false t.uuid "group_id", null: false
t.integer "status", default: 0 t.integer "status", default: 0
t.string "name" t.string "name"
t.uuid "wedding_id", null: false
t.index ["group_id"], name: "index_guests_on_group_id" t.index ["group_id"], name: "index_guests_on_group_id"
t.index ["wedding_id"], name: "index_guests_on_wedding_id"
end end
create_table "seats", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "seats", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -62,10 +56,8 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do
t.integer "table_number" t.integer "table_number"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.uuid "wedding_id", null: false
t.index ["guest_id"], name: "index_seats_on_guest_id" t.index ["guest_id"], name: "index_seats_on_guest_id"
t.index ["tables_arrangement_id"], name: "index_seats_on_tables_arrangement_id" t.index ["tables_arrangement_id"], name: "index_seats_on_tables_arrangement_id"
t.index ["wedding_id"], name: "index_seats_on_wedding_id"
end end
create_table "solid_queue_blocked_executions", force: :cascade do |t| create_table "solid_queue_blocked_executions", force: :cascade do |t|
@ -194,54 +186,16 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "name", null: false t.string "name", null: false
t.uuid "wedding_id", null: false
t.index ["wedding_id"], name: "index_tables_arrangements_on_wedding_id"
end end
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.integer "failed_attempts", default: 0, null: false
t.string "unlock_token"
t.datetime "locked_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.uuid "wedding_id", null: false
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
t.index ["wedding_id"], name: "index_users_on_wedding_id"
end
create_table "weddings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "slug", null: false
t.date "date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["slug"], name: "index_weddings_on_slug", unique: true
end
add_foreign_key "expenses", "weddings"
add_foreign_key "groups", "groups", column: "parent_id" add_foreign_key "groups", "groups", column: "parent_id"
add_foreign_key "groups", "weddings"
add_foreign_key "guests", "groups" add_foreign_key "guests", "groups"
add_foreign_key "guests", "weddings"
add_foreign_key "seats", "guests" add_foreign_key "seats", "guests"
add_foreign_key "seats", "tables_arrangements", on_delete: :cascade add_foreign_key "seats", "tables_arrangements", on_delete: :cascade
add_foreign_key "seats", "weddings"
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "tables_arrangements", "weddings"
add_foreign_key "users", "weddings"
end end

View File

@ -2,84 +2,69 @@
NUMBER_OF_GUESTS = 50 NUMBER_OF_GUESTS = 50
ActsAsTenant.without_tenant do TablesArrangement.delete_all
TablesArrangement.delete_all Expense.delete_all
Expense.delete_all Guest.delete_all
Guest.delete_all Group.delete_all
Group.delete_all
Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed')
Wedding.delete_all Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed')
Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person')
Expense.create!(name: 'Flowers', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Band', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Wedding planner', amount: 2000, pricing_type: 'fixed')
Expense.create!(name: 'Dress', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Suit', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Rings', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Makeup', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Hair', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
Group.create!(name: "Jim's guests", icon: 'pi pi-heart').tap do |parent|
parent.children.create!(name: "Jim's family", icon: 'pi pi-users').tap do |family|
family.children.create!(name: "Jim's close family", icon: 'pi pi-home')
family.children.create!(name: "Jim's cousins", icon: 'pi pi-home')
family.children.create!(name: "Jim's relatives", icon: 'pi pi-home')
end
parent.children.create!(name: "Jim's friends", icon: 'pi pi-bullseye')
parent.children.create!(name: "Jim's work", icon: 'pi pi-desktop').tap do |work|
work.children.create!(name: "Jim's besties at work", icon: 'pi pi-briefcase')
end
end end
wedding = Wedding.create!(slug: :default, date: 1.year.from_now) Group.create!(name: "Pam's guests", icon: 'pi pi-heart-fill').tap do |parent|
parent.children.create!(name: "Pam's family", icon: 'pi pi-users').tap do |family|
ActsAsTenant.with_tenant(wedding) do family.children.create!(name: "Pam's close family", icon: 'pi pi-home')
Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed') family.children.create!(name: "Pam's cousins", icon: 'pi pi-home')
Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed') family.children.create!(name: "Pam's relatives", icon: 'pi pi-home')
Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person')
Expense.create!(name: 'Flowers', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Band', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Wedding planner', amount: 2000, pricing_type: 'fixed')
Expense.create!(name: 'Dress', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Suit', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Rings', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Makeup', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Hair', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
Group.create!(name: "Jim's guests", icon: 'pi pi-heart').tap do |parent|
parent.children.create!(name: "Jim's family", icon: 'pi pi-users').tap do |family|
family.children.create!(name: "Jim's close family", icon: 'pi pi-home')
family.children.create!(name: "Jim's cousins", icon: 'pi pi-home')
family.children.create!(name: "Jim's relatives", icon: 'pi pi-home')
end
parent.children.create!(name: "Jim's friends", icon: 'pi pi-bullseye')
parent.children.create!(name: "Jim's work", icon: 'pi pi-desktop').tap do |work|
work.children.create!(name: "Jim's besties at work", icon: 'pi pi-briefcase')
end
end end
parent.children.create!(name: "Pam's friends", icon: 'pi pi-bullseye')
Group.create!(name: "Pam's guests", icon: 'pi pi-heart-fill').tap do |parent| parent.children.create!(name: "Pam's work", icon: 'pi pi-desktop').tap do |work|
parent.children.create!(name: "Pam's family", icon: 'pi pi-users').tap do |family| work.children.create!(name: "Pam's besties at work", icon: 'pi pi-briefcase')
family.children.create!(name: "Pam's close family", icon: 'pi pi-home')
family.children.create!(name: "Pam's cousins", icon: 'pi pi-home')
family.children.create!(name: "Pam's relatives", icon: 'pi pi-home')
end
parent.children.create!(name: "Pam's friends", icon: 'pi pi-bullseye')
parent.children.create!(name: "Pam's work", icon: 'pi pi-desktop').tap do |work|
work.children.create!(name: "Pam's besties at work", icon: 'pi pi-briefcase')
end
end end
end
Group.create!(name: 'Common guests', icon: 'pi pi-users').tap do |parent| Group.create!(name: 'Common guests', icon: 'pi pi-users').tap do |parent|
parent.children.create!(name: 'College friends', icon: 'pi pi-calculator') parent.children.create!(name: 'College friends', icon: 'pi pi-calculator')
parent.children.create!(name: 'High school friends', icon: 'pi pi-crown') parent.children.create!(name: 'High school friends', icon: 'pi pi-crown')
parent.children.create!(name: 'Childhood friends', icon: 'pi pi-envelope') parent.children.create!(name: 'Childhood friends', icon: 'pi pi-envelope')
end end
groups = Group.all groups = Group.all
NUMBER_OF_GUESTS.times do NUMBER_OF_GUESTS.times do
Guest.create!( Guest.create!(
name: Faker::Name.name, name: Faker::Name.name,
phone: Faker::PhoneNumber.cell_phone, phone: Faker::PhoneNumber.cell_phone,
group: groups.sample, group: groups.sample,
status: Guest.statuses.keys.sample status: Guest.statuses.keys.sample
)
end
ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new(wedding.id) })
'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
Group.roots.each(&:colorize_children)
User.create!(
email: 'development@example.com',
confirmed_at: Time.zone.now,
password: 'supersecretpassword',
password_confirmation: 'supersecretpassword',
) )
end end
ActiveJob.perform_all_later(3.times.map { TableSimulatorJob.new })
'red'.paint.palette.triad(as: :hex).zip(Group.roots).each { |(color, group)| group.update!(color: color.paint.desaturate(40)) }
Group.roots.each(&:colorize_children)

View File

@ -36,12 +36,6 @@ services:
- backend - backend
volumes: volumes:
- ../wedding-planner-frontend/:/app - ../wedding-planner-frontend/:/app
libre-captcha:
image: librecaptcha/lc-core:latest
volumes:
- "./tmp/libre-captcha-data:/lc-core/data"
ports:
- 8888
nginx: nginx:
image: nginx:latest image: nginx:latest
ports: ports:

View File

@ -7,16 +7,6 @@ server {
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
} }
location /letter_opener/ {
proxy_pass http://backend:3000/letter_opener/;
proxy_set_header Host $http_host;
}
location /captcha/v2/media/ {
proxy_pass http://libre-captcha:8888/v2/media/;
proxy_set_header Host $http_host;
}
location / { location / {
proxy_pass http://frontend:3000; proxy_pass http://frontend:3000;
proxy_set_header Host $http_host; proxy_set_header Host $http_host;

View File

@ -2,7 +2,6 @@
FactoryBot.define do FactoryBot.define do
factory :expense do factory :expense do
wedding
sequence(:name) { |i| "Expense #{i}" } sequence(:name) { |i| "Expense #{i}" }
pricing_type { "fixed" } pricing_type { "fixed" }
amount { 100 } amount { 100 }

View File

@ -2,7 +2,6 @@
FactoryBot.define do FactoryBot.define do
factory :group do factory :group do
wedding
sequence(:name) { |i| "Group #{i}" } sequence(:name) { |i| "Group #{i}" }
order { 1 } order { 1 }
end end

View File

@ -2,8 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :guest do factory :guest do
group association :group
wedding
name { Faker::Name.name } name { Faker::Name.name }
phone { Faker::PhoneNumber.cell_phone } phone { Faker::PhoneNumber.cell_phone }

View File

@ -1,8 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
FactoryBot.define do
factory :tables_arrangement do
wedding
end
end

View File

@ -1,7 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
FactoryBot.define do
factory :user do
wedding
end
end

View File

@ -1,8 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
FactoryBot.define do
factory :wedding do
sequence(:slug) { |i| "wedding-#{i}" }
date { 1.year.from_now }
end
end

View File

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe TablesArrangement, type: :model do RSpec.describe TablesArrangement, type: :model do
describe 'callbacks' do describe 'callbacks' do
it 'assigns a name before creation' do it 'assigns a name before creation' do
expect(create(:tables_arrangement).name).to be_present expect(described_class.create!.name).to be_present
end end
end end
end end

View File

@ -1,7 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'rails_helper'
RSpec.describe User, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,22 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'rails_helper'
RSpec.describe Wedding, type: :model do
describe 'validations' do
subject { build(:wedding) }
describe 'slug' do
it { should allow_value('foo').for(:slug) }
it { should allow_value('foo-bar').for(:slug) }
it { should allow_value('foo-123').for(:slug) }
it { should allow_value('foo-123-').for(:slug) }
it { should allow_value('foo--123').for(:slug) }
it { should_not allow_value('Foo').for(:slug) }
it { should_not allow_value('/foo').for(:slug) }
it { should_not allow_value('foo/123').for(:slug) }
it { should_not allow_value('foo_123').for(:slug) }
it { should_not allow_value('foo/').for(:slug) }
end
end
end

View File

@ -1,24 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper'
RSpec.describe 'captcha', type: :request do
path '/captcha' do
post('create a CAPTCHA challenge') do
tags 'CAPTCHA'
consumes 'application/json'
produces 'application/json'
response(201, 'created') do
schema type: :object,
required: %i[id],
properties: {
id: { type: :string, format: :uuid },
media_url: { type: :string, format: :uri },
}
xit
end
end
end
end

View File

@ -3,12 +3,10 @@
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'expenses', type: :request do RSpec.describe 'expenses', type: :request do
path '/{slug}/expenses' do path '/expenses' do
get('list expenses') do get('list expenses') do
tags 'Expenses' tags 'Expenses'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
response(200, 'successful') do response(200, 'successful') do
schema type: :array, schema type: :array,
items: { items: {
@ -24,17 +22,15 @@ RSpec.describe 'expenses', type: :request do
xit xit
end end
regular_api_responses
end end
end end
path '/{slug}/expenses/{id}' do path '/expenses/{id}' do
patch('update expense') do patch('update expense') do
tags 'Expenses' tags 'Expenses'
consumes 'application/json' consumes 'application/json'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: 'id', in: :path, type: :string, format: :uuid, description: 'id' parameter name: 'id', in: :path, type: :string, format: :uuid, description: 'id'
parameter name: :body, in: :body, schema: { parameter name: :body, in: :body, schema: {
type: :object, type: :object,
@ -48,7 +44,6 @@ RSpec.describe 'expenses', type: :request do
response_empty_200 response_empty_200
response_422 response_422
response_404 response_404
regular_api_responses
end end
end end
end end

View File

@ -3,11 +3,10 @@
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'groups', type: :request do RSpec.describe 'groups', type: :request do
path '/{slug}/groups' do path '/groups' do
get('list groups') do get('list groups') do
tags 'Groups' tags 'Groups'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
response(200, 'successful') do response(200, 'successful') do
schema type: :array, schema type: :array,
items: { items: {
@ -29,7 +28,6 @@ RSpec.describe 'groups', type: :request do
} }
xit xit
end end
regular_api_responses
end end
end end
end end

View File

@ -3,11 +3,10 @@
require 'swagger_helper' require 'swagger_helper'
RSpec.describe 'guests', type: :request do RSpec.describe 'guests', type: :request do
path '/{slug}/guests' do path '/guests' do
get('list guests') do get('list guests') do
tags 'Guests' tags 'Guests'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
response(200, 'successful') do response(200, 'successful') do
schema type: :array, schema type: :array,
items: { items: {
@ -27,14 +26,12 @@ RSpec.describe 'guests', type: :request do
} }
xit xit
end end
regular_api_responses
end end
post('create guest') do post('create guest') do
tags 'Guests' tags 'Guests'
consumes 'application/json' consumes 'application/json'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: :body, in: :body, schema: { parameter name: :body, in: :body, schema: {
type: :object, type: :object,
required: %i[guest], required: %i[guest],
@ -53,16 +50,14 @@ RSpec.describe 'guests', type: :request do
response_empty_201 response_empty_201
response_422 response_422
regular_api_responses
end end
end end
path '/{slug}/guests/{id}' do path '/guests/{id}' do
patch('update guest') do patch('update guest') do
tags 'Guests' tags 'Guests'
consumes 'application/json' consumes 'application/json'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: 'id', in: :path, type: :string, format: :uuid parameter name: 'id', in: :path, type: :string, format: :uuid
parameter name: :body, in: :body, schema: { parameter name: :body, in: :body, schema: {
type: :object, type: :object,
@ -82,18 +77,15 @@ RSpec.describe 'guests', type: :request do
response_empty_200 response_empty_200
response_422 response_422
response_404 response_404
regular_api_responses
end end
delete('delete guest') do delete('delete guest') do
tags 'Guests' tags 'Guests'
produces 'application/json' produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: 'id', in: :path, type: :string, format: :uuid parameter name: 'id', in: :path, type: :string, format: :uuid
response_empty_200 response_empty_200
response_404 response_404
regular_api_responses
end end
end end
end end

View File

@ -1,33 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
module Swagger
module Schema
USER = {
id: { type: :string, format: :uuid },
email: { type: :string, format: :email },
created_at: SwaggerResponseHelper::TIMESTAMP,
updated_at: SwaggerResponseHelper::TIMESTAMP
}
SLUG = {
name: 'slug',
in: :path,
type: :string,
pattern: Wedding::SLUG_REGEX,
example: :default,
description: 'Wedding slug'
}
CAPTCHA = {
captcha: {
type: :object,
required: %i[id answer],
properties: {
id: { type: :string, format: :uuid },
answer: { type: :string }
}
}
}
end
end

View File

@ -1,23 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper'
RSpec.describe 'users/confirmations', type: :request do
path '/{slug}/users/confirmation' do
get('confirm user email') do
tags 'Users'
produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: :confirmation_token, in: :query, type: :string, required: true
response(200, 'confirmed') do
schema Swagger::Schema::USER
xit
end
response_422
end
end
end

View File

@ -1,44 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper'
RSpec.describe 'users/registrations', type: :request do
path '/{slug}/users' do
post('create registration') do
tags 'Users Registrations'
consumes 'application/json'
produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: :body, in: :body, schema: {
type: :object,
required: [:user, :wedding],
properties: {
user: {
type: :object,
required: %i[email password password_confirmation],
properties: {
email: { type: :string, format: :email},
password: SwaggerResponseHelper::PASSWORD,
password_confirmation: SwaggerResponseHelper::PASSWORD
}
},
wedding: {
type: :object,
required: %i[date],
properties: {
date: { type: :string, format: :date},
}
},
**Swagger::Schema::CAPTCHA
}
}
response(201, 'created') do
schema type: :object, properties: Swagger::Schema::USER
xit
end
end
end
end

View File

@ -1,50 +0,0 @@
# Copyright (C) 2024 Manuel Bustillo
require 'swagger_helper'
RSpec.describe 'users/sessions', type: :request do
path '/{slug}/users/sign_in' do
post('create session') do
tags 'Users Sessions'
consumes 'application/json'
produces 'application/json'
parameter Swagger::Schema::SLUG
parameter name: :body, in: :body, schema: {
type: :object,
required: %i[user],
properties: {
user: {
type: :object,
required: %i[email password],
properties: {
email: { type: :string, format: :email },
password: SwaggerResponseHelper::PASSWORD
}
}
}
}
response(201, 'created') do
schema type: :object, properties: Swagger::Schema::USER
xit
end
response_401(message: 'Invalid Email or password.')
end
end
path '/{slug}/users/sign_out' do
parameter Swagger::Schema::SLUG
delete('delete session') do
tags 'Users Sessions'
consumes 'application/json'
produces 'application/json'
response(204, 'Session destroyed') do
xit
end
end
end
end

View File

@ -4,7 +4,6 @@
require 'rails_helper' require 'rails_helper'
require_relative './swagger_response_helper' require_relative './swagger_response_helper'
require_relative './requests/schemas.rb'
include SwaggerResponseHelper include SwaggerResponseHelper

View File

@ -1,17 +1,6 @@
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
module SwaggerResponseHelper module SwaggerResponseHelper
TIMESTAMP_FORMAT = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z'
TIMESTAMP_EXAMPLE = Time.zone.now.iso8601(3)
TIMESTAMP = {type: :string,pattern: TIMESTAMP_FORMAT,example: TIMESTAMP_EXAMPLE}.freeze
PASSWORD = { type: :string, minLength: User.password_length.begin, maxLength: User.password_length.end }
def regular_api_responses
response_401
end
def response_422 def response_422
response(422, 'Validation errors in input parameters') do response(422, 'Validation errors in input parameters') do
produces 'application/json' produces 'application/json'
@ -44,18 +33,6 @@ module SwaggerResponseHelper
end end
end end
def response_401(message: nil)
response(401, 'Unauthorized') do
produces 'application/json'
schema type: :object,
required: %i[error],
properties: {
error: { type: :string, example: message || 'You need to sign in or sign up before continuing.' }
}
xit
end
end
private private
def error_schema def error_schema