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| %>
<%- if form.object.contact_location.blank? %> <%= form.hidden_field :contact_method, value: :email %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ec2bc615e..82e834d9d 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -5,11 +5,11 @@ diff --git a/app/views/spaces/_room_card.html.erb b/app/views/spaces/_room_card.html.erb index 0eb1b3701..e09fc6ae4 100644 --- a/app/views/spaces/_room_card.html.erb +++ b/app/views/spaces/_room_card.html.erb @@ -10,7 +10,7 @@ -<%- end %> \ No newline at end of file +<%- end %> diff --git a/app/views/waiting_rooms/show.html.erb b/app/views/waiting_rooms/show.html.erb index 397d8a244..27ea62b19 100644 --- a/app/views/waiting_rooms/show.html.erb +++ b/app/views/waiting_rooms/show.html.erb @@ -2,11 +2,11 @@
- <%= current_room.name %> + <%= waiting_room.room.name %>
- <%= form_with model: waiting_room, url: space_room_waiting_room_path(waiting_room.space, waiting_room.room), class: "access-code-form", local: true do |form| %> + <%= form_with model: [waiting_room.room.space, waiting_room.room, waiting_room], class: "access-code-form", local: true do |form| %> <%= render "password_field", form: form, attribute: :access_code%> <%= form.hidden_field :redirect_url %> diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb index 64d230981..1bc8757f9 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -3,20 +3,20 @@ # @see https://github.com/kzkn/gretel crumb :root do if current_space.present? - link current_space.name, space_path(current_space) + link current_space.name, current_space else link t("home.title"), root_path end end crumb :edit_space do |space| - link "Configure Space", edit_space_path(space) + link "Configure Space", [:edit, space] end crumb :memberships do |space| link "Members", [space, :memberships] if policy(space).edit? - parent :edit_space, Space + parent :edit_space, space else parent :root end @@ -33,7 +33,7 @@ end crumb :utility_hookups do |space| - link "Utility Hookups", space_utility_hookups_path(space) + link "Utility Hookups", [space, :utility_hookups] parent :edit_space, space end @@ -51,12 +51,12 @@ end crumb :new_room do |room| - link t("helpers.submit.room.create"), new_space_room_path(room.space) + link t("helpers.submit.room.create"), [:new, room.space, :room] parent :edit_space, room.space end crumb :edit_room do |room| - link t("helpers.submit.room.edit", {room_name: room.name}), edit_space_room_path(room.space, room) + link t("helpers.submit.room.edit", {room_name: room.name}), [:edit, room.space, room] parent :room, room end @@ -74,4 +74,3 @@ link "Configure #{furniture_placement.title}" parent :edit_room, furniture_placement.room end - diff --git a/config/routes.rb b/config/routes.rb index 1a23bd555..718ac361a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ # post "/auth/:provider/callback", "sessions#create" # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html resources :spaces, only: %I[show edit update create destroy] do - resource :authenticated_session, only: %i[new create destroy show] + resource :authenticated_session, only: %i[new create update destroy show] resources :invitations, only: %i[create destroy index] do resource :rsvp, only: %i[show update] @@ -41,8 +41,22 @@ end constraints BrandedDomainConstraint.new(Space) do - resources :authenticated_sessions, only: %i[new create delete show] + get :edit, to: "spaces#edit" + get "/" => "spaces#show" + put "/" => "spaces#update" - get "/:id", to: "rooms#show" + resources :invitations, only: %i[create destroy index] do + resource :rsvp, only: %i[show update] + end + + resources :memberships, only: %i[index show destroy] + + resources :utility_hookups, only: %I[create edit update destroy index] + + resource :authenticated_session, only: %i[new create update destroy show] + + resources :rooms, only: %i[show edit update new create destroy] do + Furniture.append_routes(self) + end end end diff --git a/features/harness/RoomEditPage.js b/features/harness/RoomEditPage.js index 90299cc79..48acb6ce6 100644 --- a/features/harness/RoomEditPage.js +++ b/features/harness/RoomEditPage.js @@ -20,12 +20,12 @@ class RoomEditPage extends Page { * @param {AccessCode} accessCode * @returns {Promise} */ - async unlock(accessCode) { + unlock(accessCode) { const waitingRoom = new WaitingRoomPage(this.driver); - await waitingRoom.submitAccessCode(accessCode); - await this.accessLevel().select("unlocked"); - await this.submitButton().click(); - return this; + return waitingRoom.submitAccessCode(accessCode) + .then(() => this.accessLevel().select('unlocked')) + .then(() => this.submitButton().click()) + .finally(() => this) } /** * @param {string} accessLevel diff --git a/spec/requests/spaces/rooms_request_spec.rb b/spec/requests/spaces/rooms_request_spec.rb index 80aaf8faa..6443db600 100644 --- a/spec/requests/spaces/rooms_request_spec.rb +++ b/spec/requests/spaces/rooms_request_spec.rb @@ -123,7 +123,7 @@ it "removes the room" do delete path expect { room.reload }.to raise_error(ActiveRecord::RecordNotFound) - expect(response).to redirect_to(edit_space_path(room.space)) + expect(response).to redirect_to([:edit, room.space]) expect(flash[:notice]).to eql(I18n.t("rooms.destroy.success", room_name: room.name)) end end diff --git a/spec/requests/spaces/utility_hookups_spec.rb b/spec/requests/spaces/utility_hookups_spec.rb index 458974ed4..cc59dda20 100644 --- a/spec/requests/spaces/utility_hookups_spec.rb +++ b/spec/requests/spaces/utility_hookups_spec.rb @@ -70,7 +70,7 @@ it "Updates the Utility Hookup" do expect { perform_request }.to(change { utility_hookup.reload.attributes }) - expect(response).to redirect_to edit_space_path(space) + expect(response).to redirect_to [:edit, space] expect(utility_hookup.utility_slug).to eq(utility_hookup_attributes[:utility_slug]) expect(utility_hookup.utility.configuration).to eq(utility_hookup_attributes[:utility_attributes]) end @@ -109,7 +109,7 @@ expect { perform_request } .to(change { space.utility_hookups.count }.by(1)) - expect(response).to redirect_to edit_space_path(space) + expect(response).to redirect_to [:edit, space] expect(space.utility_hookups.last.utility_slug).to eql("jitsi") expect(space.utility_hookups.last.utility.configuration).to eq(utility_hookup_attributes[:utility_attributes]) end diff --git a/spec/requests/spaces_request_spec.rb b/spec/requests/spaces_request_spec.rb index 31a11c33a..abcca1ea9 100644 --- a/spec/requests/spaces_request_spec.rb +++ b/spec/requests/spaces_request_spec.rb @@ -62,7 +62,7 @@ SystemTestSpace.prepare space = Space.find_by(slug: "system-test") - delete space_path(space), + delete polymorphic_path(space), headers: authorization_headers, as: :json @@ -86,14 +86,14 @@ end it "updates the theme" do - put space_path(space), params: {space: {theme: "desert_dunes"}} + put polymorphic_path(space), params: {space: {theme: "desert_dunes"}} expect(space.reload.theme).to eq("desert_dunes") expect(flash[:notice]).to include("successfully updated") end it "shows an error message with an invalid theme" do - put space_path(space), params: {space: {theme: "bogus_theme"}} + put polymorphic_path(space), params: {space: {theme: "bogus_theme"}} expect(space.reload.theme).to eq("purple_mountains") expect(flash[:alert]).to include("went wrong")