Compare commits

..

No commits in common. "5f66373d505da9057fba2c649ec631bf64f0be29" and "e6cf0da8148b1d7b4f3f75e02c59ae9afb7fc09d" have entirely different histories.

13 changed files with 5 additions and 94 deletions

View File

@ -30,10 +30,6 @@ class ApplicationController < ActionController::Base
private private
def default_url_options(options = {})
options.merge(path_params: { slug: ActsAsTenant.current_tenant&.slug })
end
def set_tenant def set_tenant
ActsAsTenant.current_tenant = Wedding.find_by(slug: params[:slug]) ActsAsTenant.current_tenant = Wedding.find_by(slug: params[:slug])
end end

View File

@ -3,24 +3,4 @@
class Users::RegistrationsController < Devise::RegistrationsController class Users::RegistrationsController < Devise::RegistrationsController
clear_respond_to clear_respond_to
respond_to :json respond_to :json
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 end

View File

@ -15,8 +15,6 @@
# index_weddings_on_slug (slug) UNIQUE # index_weddings_on_slug (slug) UNIQUE
# #
class Wedding < ApplicationRecord class Wedding < ApplicationRecord
SLUG_REGEX = /[a-z\d-]+/
validates :date, presence: true validates :date, presence: true
validates :slug, presence: true, uniqueness: true, format: { with: /\A#{SLUG_REGEX}\z/ } validates :slug, presence: true, uniqueness: true
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

@ -246,7 +246,7 @@ Devise.setup do |config|
# Turn scoped views on. Before rendering "sessions/new", it will first check for # 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 # "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views. # are using only default views.
config.scoped_views = true # config.scoped_views = false
# Configure the default scope given to Warden. By default it's the first # Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user). # devise role declared in your routes (usually :user).

View File

@ -2,7 +2,7 @@
Rails.application.routes.draw do Rails.application.routes.draw do
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
scope ":slug", constraints: { slug: Wedding::SLUG_REGEX } do scope ":slug", constraints: {slug: /[a-z]+/} do
devise_for :users, skip: [:registration, :session, :confirmation] devise_for :users, skip: [:registration, :session, :confirmation]
devise_scope :user do devise_scope :user do
post 'users', to: 'users/registrations#create' post 'users', to: 'users/registrations#create'

View File

@ -3,20 +3,5 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Wedding, type: :model do RSpec.describe Wedding, type: :model do
describe 'validations' do pending "add some examples to (or delete) #{__FILE__}"
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 end

View File

@ -14,7 +14,6 @@ module Swagger
name: 'slug', name: 'slug',
in: :path, in: :path,
type: :string, type: :string,
pattern: Wedding::SLUG_REGEX,
example: :default, example: :default,
description: 'Wedding slug' description: 'Wedding slug'
} }

View File

@ -13,7 +13,7 @@ RSpec.describe 'users/registrations', type: :request do
parameter Swagger::Schema::SLUG parameter Swagger::Schema::SLUG
parameter name: :body, in: :body, schema: { parameter name: :body, in: :body, schema: {
type: :object, type: :object,
required: [:user, :wedding], required: [:user],
properties: { properties: {
user: { user: {
type: :object, type: :object,
@ -23,13 +23,6 @@ RSpec.describe 'users/registrations', type: :request do
password: SwaggerResponseHelper::PASSWORD, password: SwaggerResponseHelper::PASSWORD,
password_confirmation: SwaggerResponseHelper::PASSWORD password_confirmation: SwaggerResponseHelper::PASSWORD
} }
},
wedding: {
type: :object,
required: %i[date],
properties: {
date: { type: :string, format: :date},
}
} }
} }
} }