diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 619d0e5db..d38f60283 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -27,6 +27,43 @@ class ApplicationController < ActionController::Base
helper_method :current_person
+ # Overrides built in `url_for` to better support branded domains
+ # @see http://api.rubyonrails.org/classes/ActionController/Metal.html#method-i-url_for
+ helper_method def url_for(options)
+ space = if options[0].try(:branded_domain).present?
+ options.delete_at(0)
+ elsif [:edit, :new].include?(options[0]) && options[1].try(:branded_domain).present?
+ options.delete_at(1)
+ elsif options.try(:branded_domain).present?
+ options
+ end
+
+ return super unless space
+
+ # Appends the domain to the options passed to `url_for`
+ if options.respond_to?(:last) && options.last.is_a?(Hash)
+ options.last[:domain] = space.branded_domain
+ elsif options.respond_to?(:<<) && options.length > 0
+ options << {domain: space.branded_domain}
+ else
+ options = [:root, {domain: space.branded_domain}]
+ end
+
+ super
+ end
+
+ # Removes the root branded domain from the path builder
+ # @see http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html#method-i-polymorphic_path
+ helper_method def polymorphic_path(options, **attributes)
+ if options[0].try(:branded_domain).present? && options.length > 1
+ options.delete_at(0)
+ elsif [:edit, :new].include?(options[0]) && options.try(:branded_domain).present?
+ options.delete_at(1)
+ end
+
+ super
+ end
+
private
OPERATOR_TOKEN = ENV["OPERATOR_API_KEY"]
diff --git a/app/controllers/authenticated_sessions_controller.rb b/app/controllers/authenticated_sessions_controller.rb
index a68a0046f..5583554fb 100644
--- a/app/controllers/authenticated_sessions_controller.rb
+++ b/app/controllers/authenticated_sessions_controller.rb
@@ -17,6 +17,8 @@ def create
end
end
+ alias_method :update, :create
+
def destroy
authenticated_session.destroy
redirect_to current_space
diff --git a/app/controllers/furniture_placements_controller.rb b/app/controllers/furniture_placements_controller.rb
index 18b61f9bf..25d36df27 100644
--- a/app/controllers/furniture_placements_controller.rb
+++ b/app/controllers/furniture_placements_controller.rb
@@ -4,7 +4,7 @@ def create
if furniture_placement.save!
format.html do
redirect_to(
- space_room_path(furniture_placement.room.space, furniture_placement.room),
+ [furniture_placement.room.space, furniture_placement.room],
notice: t(".success", name: furniture_placement.furniture.model_name.human)
)
end
@@ -25,7 +25,7 @@ def update
if furniture_placement.update!(furniture_placement_params)
format.html do
redirect_to(
- edit_space_room_path(furniture_placement.room.space, furniture_placement.room),
+ [:edit, furniture_placement.room.space, furniture_placement.room],
notice: t(".success", name: furniture_placement.furniture.model_name.human)
)
end
@@ -38,7 +38,7 @@ def destroy
respond_to do |format|
format.html do
redirect_to(
- space_room_path(furniture_placement.room.space, furniture_placement.room),
+ [furniture_placement.room.space, furniture_placement.room],
notice: t(".success", name: furniture_placement.furniture.model_name.human.titleize)
)
end
diff --git a/app/controllers/memberships_controller.rb b/app/controllers/memberships_controller.rb
index b75c32db7..19f3d31de 100644
--- a/app/controllers/memberships_controller.rb
+++ b/app/controllers/memberships_controller.rb
@@ -25,7 +25,7 @@ def destroy
respond_to do |format|
format.html do
- redirect_to(space_memberships_path(membership.space))
+ redirect_to([membership.space, :memberships])
end
format.turbo_stream do
diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb
index 665a2af9b..18ba15552 100644
--- a/app/controllers/rooms_controller.rb
+++ b/app/controllers/rooms_controller.rb
@@ -19,7 +19,7 @@ def edit
def create
if room.save
flash[:notice] = t(".success", room_name: room.name)
- redirect_to edit_space_room_path(room.space, room)
+ redirect_to [:edit, room.space, room]
else
render :new, status: :unprocessable_entity
end
@@ -29,7 +29,7 @@ def update
respond_to do |format|
if room.update(room_params)
format.html do
- redirect_to edit_space_path(room.space), notice: t(".success", room_name: room.name)
+ redirect_to [:edit, room.space], notice: t(".success", room_name: room.name)
end
else
format.html { render :edit, status: :unprocessable_entity }
@@ -41,7 +41,7 @@ def update
def destroy
if room.destroy
- redirect_to edit_space_path(room.space), notice: t(".success", room_name: room.name)
+ redirect_to [:edit, room.space], notice: t(".success", room_name: room.name)
else
flash.now[:alert] = t(".failure", room_name: room.name)
render :edit
@@ -69,16 +69,16 @@ def room_params
return unless room.persisted?
unless room.enterable?(current_access_code(room))
- redirect_to space_room_waiting_room_path(current_space, current_room, redirect_url: after_authorization_redirect_url)
+ redirect_to [current_space, current_room, :waiting_room, redirect_url: after_authorization_redirect_url]
end
end
# TODO: Unit test authorize and redirect url
private def after_authorization_redirect_url
if %i[edit update].include?(action_name.to_sym)
- return edit_space_room_path(room.space, room)
+ return url_for([:edit, room.space, room])
end
- space_room_path(room.space, room)
+ url_for([room.space, room])
end
end
diff --git a/app/controllers/spaces_controller.rb b/app/controllers/spaces_controller.rb
index 10357662e..e147c70ef 100644
--- a/app/controllers/spaces_controller.rb
+++ b/app/controllers/spaces_controller.rb
@@ -25,7 +25,7 @@ def create
def update
if space.update(space_params)
flash[:notice] = t(".success")
- redirect_to space_path(space)
+ redirect_to space
else
flash.now[:alert] = t(".error")
render :edit
diff --git a/app/controllers/utility_hookups_controller.rb b/app/controllers/utility_hookups_controller.rb
index a281e7135..aa9e9e367 100644
--- a/app/controllers/utility_hookups_controller.rb
+++ b/app/controllers/utility_hookups_controller.rb
@@ -11,7 +11,7 @@ def edit
def create
if utility_hookup.save
- redirect_to edit_space_path(space)
+ redirect_to [:edit, space]
else
render :new
end
@@ -19,7 +19,7 @@ def create
def update
if utility_hookup.update(utility_hookup_params)
- redirect_to edit_space_path(space)
+ redirect_to [:edit, space]
else
render :edit
end
diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb
index 082b1ea00..3ce8b6714 100644
--- a/app/helpers/rooms_helper.rb
+++ b/app/helpers/rooms_helper.rb
@@ -1,9 +1,5 @@
module RoomsHelper
def end_call_path(space)
- if space.branded_domain.present?
- "https://#{space.branded_domain}/"
- else
- space_path(space)
- end
+ [space]
end
end
diff --git a/app/models/authenticated_session.rb b/app/models/authenticated_session.rb
index bfd4f3cdf..e5b4b59d3 100644
--- a/app/models/authenticated_session.rb
+++ b/app/models/authenticated_session.rb
@@ -25,7 +25,7 @@ def authentication_method_id=(authentication_method_id)
end
def persisted?
- false
+ true
end
def destroy
diff --git a/app/views/authenticated_sessions/_form.html.erb b/app/views/authenticated_sessions/_form.html.erb
index 2421f8d61..2517af8ce 100644
--- a/app/views/authenticated_sessions/_form.html.erb
+++ b/app/views/authenticated_sessions/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_with model: authenticated_session, url: space_authenticated_session_path(current_space), local: true do |form| %>
+<%= form_with model: [current_space, authenticated_session] do |form| %>