From 8527b20075be430af588c6839aa857c92f2ac1ec Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 12:39:43 +0100 Subject: [PATCH 1/6] Remove wedding date attribute --- app/models/wedding.rb | 2 -- db/migrate/20241207112305_remove_wedding_date.rb | 5 +++++ db/schema.rb | 5 +---- spec/requests/users/registrations_spec.rb | 7 ------- 4 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20241207112305_remove_wedding_date.rb diff --git a/app/models/wedding.rb b/app/models/wedding.rb index cee2fb7..125c58e 100644 --- a/app/models/wedding.rb +++ b/app/models/wedding.rb @@ -5,7 +5,6 @@ # 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 @@ -17,6 +16,5 @@ 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 diff --git a/db/migrate/20241207112305_remove_wedding_date.rb b/db/migrate/20241207112305_remove_wedding_date.rb new file mode 100644 index 0000000..2176f55 --- /dev/null +++ b/db/migrate/20241207112305_remove_wedding_date.rb @@ -0,0 +1,5 @@ +class RemoveWeddingDate < ActiveRecord::Migration[8.0] + def change + remove_column :weddings, :date, :date, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 7ff33f3..f1c5b20 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# Copyright (C) 2024 Manuel Bustillo - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,7 +10,7 @@ # # 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_12_07_112305) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -222,7 +220,6 @@ ActiveRecord::Schema[8.0].define(version: 2024_11_30_185731) do 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 diff --git a/spec/requests/users/registrations_spec.rb b/spec/requests/users/registrations_spec.rb index f29b387..2cbaeea 100644 --- a/spec/requests/users/registrations_spec.rb +++ b/spec/requests/users/registrations_spec.rb @@ -24,13 +24,6 @@ RSpec.describe 'users/registrations', type: :request do password_confirmation: SwaggerResponseHelper::PASSWORD } }, - wedding: { - type: :object, - required: %i[date], - properties: { - date: { type: :string, format: :date}, - } - }, **Swagger::Schema::CAPTCHA } } From 022b58bb3867a68784e9f32d26898b1a780962be Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 12:43:08 +0100 Subject: [PATCH 2/6] Fix issues with tenant during registration --- app/controllers/captcha_controller.rb | 2 +- app/controllers/users/registrations_controller.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/captcha_controller.rb b/app/controllers/captcha_controller.rb index 428328d..351b324 100644 --- a/app/controllers/captcha_controller.rb +++ b/app/controllers/captcha_controller.rb @@ -2,7 +2,7 @@ class CaptchaController < ApplicationController skip_before_action :authenticate_user! - + skip_before_action :set_tenant def create id = LibreCaptcha.new.get_id render json: { diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 4894d4b..0aae89d 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -7,7 +7,7 @@ class Users::RegistrationsController < Devise::RegistrationsController before_action :validate_captcha!, only: :create def create - wedding = Wedding.create(wedding_params) + wedding = Wedding.create(slug: params[:slug]) unless wedding.persisted? render json: { errors: wedding.errors.full_messages }, status: :unprocessable_entity return @@ -22,7 +22,7 @@ class Users::RegistrationsController < Devise::RegistrationsController private - def wedding_params - { slug: params[:slug], **params.expect(wedding: :date) } + def set_tenant + set_current_tenant(nil) end end \ No newline at end of file From a3f14f4fec8bfb2ee4174ae8073b11cf07086c09 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 19:07:06 +0100 Subject: [PATCH 3/6] Include slug in root_url --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 1357d9c..bd26594 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,8 @@ Rails.application.routes.draw do get :summary, on: :collection end resources :tables_arrangements, only: %i[index show] + + root to: redirect("/%{slug}") end resources :captcha, only: :create do @@ -31,6 +33,4 @@ Rails.application.routes.draw do mount Rswag::Api::Engine => '/api-docs' get 'up' => 'rails/health#show', as: :rails_health_check - - root to: redirect('/dashboard') end From 9b612ce01d4728e71e03618216cc1a36fbf071a4 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 18:09:21 +0000 Subject: [PATCH 4/6] Add copyright notice --- db/migrate/20241207112305_remove_wedding_date.rb | 2 ++ db/schema.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/db/migrate/20241207112305_remove_wedding_date.rb b/db/migrate/20241207112305_remove_wedding_date.rb index 2176f55..c810ee4 100644 --- a/db/migrate/20241207112305_remove_wedding_date.rb +++ b/db/migrate/20241207112305_remove_wedding_date.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + class RemoveWeddingDate < ActiveRecord::Migration[8.0] def change remove_column :weddings, :date, :date, null: false diff --git a/db/schema.rb b/db/schema.rb index f1c5b20..29940a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Manuel Bustillo + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. From fdef94be9acb80fcb4fbf35ef218307efbebebb6 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 23:18:23 +0100 Subject: [PATCH 5/6] Revert "Fix tenant-related error retrieving captcha" This reverts commit 3996ffc85c1fe3a912db14cbb317158fe9bcd8e2. --- app/controllers/captcha_controller.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/captcha_controller.rb b/app/controllers/captcha_controller.rb index 0ac3548..351b324 100644 --- a/app/controllers/captcha_controller.rb +++ b/app/controllers/captcha_controller.rb @@ -10,10 +10,4 @@ class CaptchaController < ApplicationController media_url: media_captcha_index_url(id:) }, status: :created end - - private - - def set_tenant - ActsAsTenant.current_tenant = nil - end end From 93d907cdc82b063967b319d30a8ab0045b168767 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 7 Dec 2024 23:43:21 +0100 Subject: [PATCH 6/6] Remove leftovers of the date attribute --- db/seeds.rb | 2 +- spec/factories/weddings.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 9d93073..eb45757 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -11,7 +11,7 @@ ActsAsTenant.without_tenant do Wedding.delete_all end -wedding = Wedding.create!(slug: :default, date: 1.year.from_now) +wedding = Wedding.create!(slug: :default) ActsAsTenant.with_tenant(wedding) do Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed') diff --git a/spec/factories/weddings.rb b/spec/factories/weddings.rb index 3680045..5a765a1 100644 --- a/spec/factories/weddings.rb +++ b/spec/factories/weddings.rb @@ -3,6 +3,5 @@ FactoryBot.define do factory :wedding do sequence(:slug) { |i| "wedding-#{i}" } - date { 1.year.from_now } end end