-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Neighborhood
: Assign an Operator
and create a Space
on first run (
#1141) * `Neighborhood` Get rid of a "Default" Space This gets rid of the idea of "Default" Space, in favor of a first-run experience where an `Operator` creates a Space * `Space`: A temporary attribute of Blueprint OK, so maybe this should be persisted? But whatever, for now it makes sure we can create a space via the API. * `Neighborhood`: Allow `Authentication` at `Neibhorhood` level Turns out, the `authenticated_session` path was implicitely a Space-only action. With `Neighborhood` becoming the Root, we no longer can expect sessions to only be at the Space level! * `Neighborhood`: Provide step-by-step setup instructions 1. `Operator`s are told to configure email if they haven't already 2. `Operator`s are told how to make themselves an operator via the Rails console 3. Only `Operator`s may create a `Space` 4. All Links to Sign in and Out at the `Neighborhood` level work
- Loading branch information
Showing
24 changed files
with
163 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,9 @@ SMTP_ENABLE_TLS=false | |
PORT=3000 | ||
# Used to build URLs in mailers | ||
APP_ROOT_URL=http://localhost:3000 | ||
EMAIL_DEFAULT_FROM='Convene Support <[email protected]>' | ||
EMAIL_DEFAULT_FROM='Neighborhood Support <[email protected]>' | ||
|
||
# Ensures the data in our database is fully encrypted | ||
LOCKBOX_MASTER_KEY=0000000000000000000000000000000000000000000000000000000000000000 | ||
|
||
|
||
DEFAULT_SPACE=system-test | ||
OPERATOR_API_KEY=a-secret-that-should-get-changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class NeighborhoodsController < ApplicationController | ||
def show | ||
end | ||
|
||
helper_method def neighborhood | ||
@neighborhood ||= authorize(Neighborhood.new) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class Neighborhood | ||
def self.config | ||
@config ||= Config.new | ||
def spaces | ||
Space.all | ||
end | ||
|
||
class Config | ||
def default_space_slug | ||
ENV.fetch("DEFAULT_SPACE", "convene") | ||
end | ||
def email_configured? | ||
if email_configuration[:address] == "localhost" | ||
email_configuration.except(:user_name, :password) | ||
else | ||
email_configuration | ||
end.values.none?(:nil?) && | ||
ENV["APP_ROOT_URL"].present? && | ||
ENV["EMAIL_DEFAULT_FROM"].present? | ||
end | ||
|
||
def operators | ||
Person.where(operator: true) | ||
end | ||
|
||
def email_configuration | ||
{ | ||
address: ENV["SMTP_ADDRESS"], | ||
domain: ENV["SMTP_DOMAIN"], | ||
port: ENV["SMTP_PORT"].to_i, | ||
user_name: ENV["SMTP_USERNAME"], | ||
password: ENV["SMTP_PASSWORD"], | ||
authentication: ENV["SMTP_AUTHENTICATION"]&.to_sym, | ||
tls: ENV.fetch("SMTP_ENABLE_TLS", true) != "false", | ||
enable_starttls_auto: ENV.fetch("SMTP_ENABLE_TLS", true) != "false" | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class NeighborhoodPolicy < ApplicationPolicy | ||
def show? | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<div> | ||
<%- if policy(current_space).edit? %> | ||
<%= link_to "", [:edit, current_space], class: "icon --configure", aria: { label: "Configure Space" }, role: "img" %> | ||
<% end %> | ||
<%= breadcrumbs container_tag: 'nav', fragment_class: 'crumb', separator: " › ", semantic: true, display_single_fragment: true %> | ||
</div> | ||
<%- if current_space.present? %> | ||
<div> | ||
<%- if policy(current_space).edit? %> | ||
<%= link_to "", [:edit, current_space], class: "icon --configure", aria: { label: "Configure Space" }, role: "img" %> | ||
<% end %> | ||
<%= breadcrumbs container_tag: 'nav', fragment_class: 'crumb', separator: " › ", semantic: true, display_single_fragment: true %> | ||
</div> | ||
<%- end %> |
2 changes: 1 addition & 1 deletion
2
app/views/authenticated_session_mailer/one_time_password_email.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Your one time password is <%= @authentication_method.one_time_password %> | ||
|
||
Or, tap here: <%= space_authenticated_session_url(@space, authenticated_session: { one_time_password: @authentication_method.one_time_password, authentication_method_id: @authentication_method.id }) %> | ||
Or, tap here: <%= polymorphic_url([@space, :authenticated_session].compact, authenticated_session: { one_time_password: @authentication_method.one_time_password, authentication_method_id: @authentication_method.id }) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<%- @pagy, @records = pagy(policy_scope(neighborhood.spaces)) %> | ||
|
||
<section class="max-w-3xl mx-auto"> | ||
<div class="mt-3 grid grid-cols-1 gap-5 sm:gap-6 sm:grid-cols-2 lg:grid-cols-4"> | ||
<%= render @records %> | ||
</div> | ||
|
||
<%== pagy_nav(@pagy, nav_extra: 'flex justify-between') %> | ||
<%- if policy(Space).new? %> | ||
<div class="text-center w-full"> | ||
<%= link_to "Add a Space",[:new, :space] %> | ||
</div> | ||
<%- end %> | ||
</section> | ||
|
||
<%- if !neighborhood.email_configured? %> | ||
<p>It looks like you haven't configured Convene to send email. Check the <code>.env.example</code> file for variables named with <code>SMTP</code> and make sure each is set with your email providers configuration.</p> | ||
|
||
<p>If you're hosting for you and your friends, you can use your current email service provider and send emails as yourself. If you want to go bigger, we recommend setting up a dedicated transactional email service, such as Mailgun.<p> | ||
|
||
<%- elsif neighborhood.operators.blank? %> | ||
<p>It looks like you don't have anyone set up as an Operator yet! To make yourself an Operator: | ||
|
||
<ol> | ||
<%- if current_person&.authenticated? %> | ||
<li>Open a <code>rails console</code> on your server's command line.</li> | ||
<li>Find yourself: <code>me = Person.joins(:authentication_methods).find_by(authentication_methods: { contact_method: :email, contact_location: "<%= current_person.authentication_methods.via_email.first.contact_location %>" })</code></li> | ||
<li>Set your operator bit to true: <code>me.update(operator: true)</code></li> | ||
<li>Reload this page!</li> | ||
<%- else %> | ||
<li><%= link_to "Sign in!", [:new, :authenticated_session]%></li> | ||
<% end%> | ||
</ol> | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= render CardComponent.new do %> | ||
<%= link_to space, class: "no-underline" do %> | ||
<h2 class="text-center p-2"><%= space.name %></h2> | ||
<%- end %> | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= form_with(model: space) do |form| %> | ||
<%= render "text_field", attribute: :name, form: form %> | ||
<%= form.fields_for(:client, space.client || space.build_client) do |client_form|%> | ||
<%= render "text_field", attribute: :name, form: client_form %> | ||
<%- end %> | ||
<%= form.submit %> | ||
<%- end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
en: | ||
activerecord: | ||
attributes: | ||
client: | ||
name: Client Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.routes.draw do | ||
root "spaces#show" | ||
mount Rswag::Ui::Engine => "/api-docs" | ||
mount Rswag::Api::Engine => "/api-docs" | ||
|
||
resources :authentication_methods, only: %i[create] | ||
resource :authenticated_session, only: %i[new create update destroy show] | ||
|
||
# get "/auth/:provider/callback", "sessions#create" | ||
# 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 | ||
resources :spaces, only: %I[new create show edit update create destroy] do | ||
SpaceRoutes.append_routes(self) | ||
end | ||
|
||
resources :memberships, only: %I[create] | ||
|
||
resource :me, only: %i[show], controller: "me" | ||
|
||
constraints DefaultSpaceConstraint.new(Space) do | ||
mount Rswag::Ui::Engine => "/api-docs" | ||
mount Rswag::Api::Engine => "/api-docs" | ||
end | ||
|
||
constraints BrandedDomainConstraint.new(Space) do | ||
get :edit, to: "spaces#edit" | ||
get "/" => "spaces#show" | ||
put "/" => "spaces#update" | ||
|
||
SpaceRoutes.append_routes(self) | ||
end | ||
|
||
root "neighborhoods#show" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.