Skip to content

Commit

Permalink
Memberships: Invitations work on BYO Domains (#1082)
Browse files Browse the repository at this point in the history
* BYO Domains: Enforce Custom Domains when Set

#74
#1078

This doesn't compeltely fix #1078, but it should help with making sure
the branded domains take precedence (which is part of the problem)

* Invitations: Use `location` to identify where to send people

Like all Resources in Convene, Invitations to a Convene Space can be on
a BYO Domain *or* a path under the Neighborhoods primary domain, they
want to use the `location` method for determining where they live within
the object graph.

* BYO Domains: Test that they redirect appropriately
  • Loading branch information
zspencer authored Jan 31, 2023
1 parent 24bfef9 commit 618aaa6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 5 deletions.
15 changes: 15 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Default controller for new resources; ensures requests fulfill authentication
# and authorization requirements, as well as exposes common helper methods.
class ApplicationController < ActionController::Base
before_action :ensure_on_byo_domain


include Pundit::Authorization
after_action :verify_authorized
after_action :verify_policy_scoped
Expand Down Expand Up @@ -64,6 +67,18 @@ class ApplicationController < ActionController::Base
super
end


# @todo this should be tested 🙃 halp me
def ensure_on_byo_domain
if request.get? && current_space.branded_domain.present? && request.domain != current_space.branded_domain

redirect_url = URI(request.url)
redirect_url.host = current_space.branded_domain
redirect_url.path = redirect_url.path.gsub("/spaces/#{current_space.slug}","")
redirect_to redirect_url.to_s, allow_other_host: true
end
end

private

OPERATOR_TOKEN = ENV["OPERATOR_API_KEY"]
Expand Down
3 changes: 3 additions & 0 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# frozen_string_literal: true

class Invitation < ApplicationRecord
self.location_parent = :space

belongs_to :space, inverse_of: :invitations


belongs_to :invitor, class_name: :Person, inverse_of: :invitations

has_one :membership
Expand Down
2 changes: 2 additions & 0 deletions app/models/rsvp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class Rsvp
include ActiveModel::Model
include WithinLocation
self.location_parent = :invitation

attr_accessor :invitation

Expand Down
2 changes: 1 addition & 1 deletion app/views/invitations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


<div>
<%= form_with(model: [space, invitation], local: true) do |invitation_form| %>
<%= form_with(model: invitation.location, local: true) do |invitation_form| %>
<div>
<%= invitation_form.label :name %>
<%= invitation_form.text_field :name %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/rsvps/_pending.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2><%= t('.header', space_name: rsvp.invitation.space.name)%></h2>
<p><%= t('.summary', space_name: rsvp.invitation.space.name, invitor_name: rsvp.invitation.invitor_display_name, invitation_date: rsvp.invitation.created_at) %></p>

<%= form_with model: [rsvp.space, rsvp.invitation, rsvp], local: true do |rsvp_form|%>
<%= form_with model: rsvp.location do |rsvp_form|%>
<%= rsvp_form.hidden_field :status, value: 'accepted' %>
<%= rsvp_form.submit t('.accept', space_name: rsvp.space.name) %>
<%- end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/rsvps/update.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h2><%= t('.header', email: rsvp.invitation.email)%></h2>
<p><%= t('.summary', invitor_name: rsvp.invitation.invitor_display_name) %></p>

<%= form_with model: [rsvp.space, rsvp.invitation, rsvp], local: true do |rsvp_form|%>
<%= form_with model: rsvp.location do |rsvp_form|%>
<%= rsvp_form.hidden_field :status, value: "accepted" %>
<%= render "text_field", form: rsvp_form, attribute: :one_time_password %>
<%= rsvp_form.submit t('.accept', space_name: rsvp.space.name) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Hi <%= @invitation.name %>,

You've been invited to <%= @invitation.space.name %> by <%= @invitation.invitor_display_name %>.

You may view, accept or ignore this invitation at <%= space_invitation_rsvp_url(@invitation.space, @invitation) %>.
You may view, accept or ignore this invitation at <%= polymorphic_url(@invitation.location(child: :rsvp)) %>.

We hope to see you there! 🥳🎈🎉

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/spaces_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it "links to the domain" do
get polymorphic_path(space)

expect(response.body).to include "//beta.example.com/"
expect(response).to redirect_to "http://beta.example.com"
end
end
end
Expand Down

0 comments on commit 618aaa6

Please sign in to comment.