Account.sole → Current.account
and some other de-tenant changes, including removing the controller tenanting concerns
This commit is contained in:
@@ -10,8 +10,9 @@ module ApplicationCable
|
|||||||
private
|
private
|
||||||
def set_current_user
|
def set_current_user
|
||||||
if session = find_session_by_cookie
|
if session = find_session_by_cookie
|
||||||
membership = session.identity.memberships.find_by!(tenant: current_tenant)
|
# # TODO:PLANB: not sure how to fix this
|
||||||
self.current_user = membership.user if membership.user.active?
|
# membership = session.identity.memberships.find_by!(tenant: current_tenant)
|
||||||
|
# self.current_user = membership.user if membership.user.active?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class Account::EntropiesController < ApplicationController
|
|||||||
before_action :ensure_admin
|
before_action :ensure_admin
|
||||||
|
|
||||||
def update
|
def update
|
||||||
Account.sole.entropy.update!(entropy_params)
|
Current.account.entropy.update!(entropy_params)
|
||||||
redirect_to account_settings_path, notice: "Account updated"
|
redirect_to account_settings_path, notice: "Account updated"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Account::SettingsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
def set_account
|
def set_account
|
||||||
@account = Account.sole
|
@account = Current.account
|
||||||
end
|
end
|
||||||
|
|
||||||
def account_params
|
def account_params
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ module Authentication
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
# Checking for tenant must happen first so we redirect before trying to access the db.
|
|
||||||
before_action :require_tenant
|
|
||||||
prepend_before_action :clear_old_scoped_session_cookies
|
prepend_before_action :clear_old_scoped_session_cookies
|
||||||
|
|
||||||
before_action :require_authentication
|
before_action :require_authentication
|
||||||
@@ -25,11 +23,6 @@ module Authentication
|
|||||||
before_action :resume_session, **options
|
before_action :resume_session, **options
|
||||||
allow_unauthorized_access **options
|
allow_unauthorized_access **options
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_untenanted_access(**options)
|
|
||||||
skip_before_action :require_tenant, **options
|
|
||||||
before_action :redirect_tenanted_request, **options
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -37,12 +30,6 @@ module Authentication
|
|||||||
Current.session.present?
|
Current.session.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_tenant
|
|
||||||
if ApplicationRecord.current_tenant.blank?
|
|
||||||
redirect_to session_menu_url(script_name: nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def require_authentication
|
def require_authentication
|
||||||
resume_session || request_authentication
|
resume_session || request_authentication
|
||||||
end
|
end
|
||||||
@@ -65,9 +52,7 @@ module Authentication
|
|||||||
end
|
end
|
||||||
|
|
||||||
def request_authentication
|
def request_authentication
|
||||||
if ApplicationRecord.current_tenant.present?
|
session[:return_to_after_authenticating] = request.url
|
||||||
session[:return_to_after_authenticating] = request.url
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect_to_login_url
|
redirect_to_login_url
|
||||||
end
|
end
|
||||||
@@ -80,10 +65,6 @@ module Authentication
|
|||||||
redirect_to root_url if authenticated?
|
redirect_to root_url if authenticated?
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_tenanted_request
|
|
||||||
redirect_to root_url if ApplicationRecord.current_tenant
|
|
||||||
end
|
|
||||||
|
|
||||||
def start_new_session_for(identity)
|
def start_new_session_for(identity)
|
||||||
identity.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |session|
|
identity.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |session|
|
||||||
set_current_session session
|
set_current_session session
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module Authorization
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_action :ensure_can_access_account, if: -> { ApplicationRecord.current_tenant && authenticated? }
|
before_action :ensure_can_access_account, if: -> { authenticated? }
|
||||||
end
|
end
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class JoinCodesController < ApplicationController
|
class JoinCodesController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
allow_unauthenticated_access
|
allow_unauthenticated_access
|
||||||
before_action :set_join_code
|
before_action :set_join_code
|
||||||
before_action :ensure_join_code_is_valid
|
before_action :ensure_join_code_is_valid
|
||||||
@@ -7,7 +6,7 @@ class JoinCodesController < ApplicationController
|
|||||||
layout "public"
|
layout "public"
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@account_name = ApplicationRecord.with_tenant(tenant) { Account.sole.name }
|
@account_name = Current.account.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -30,7 +29,8 @@ class JoinCodesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_join_code
|
def set_join_code
|
||||||
@join_code ||= ApplicationRecord.with_tenant(tenant) { Account::JoinCode.active.find_by(code: code) }
|
# TODO:PLANB: this find should be scoped by account
|
||||||
|
@join_code ||= Account::JoinCode.active.find_by(code: code)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tenant
|
def tenant
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Memberships::EmailAddresses::ConfirmationsController < ApplicationController
|
class Memberships::EmailAddresses::ConfirmationsController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
allow_unauthenticated_access
|
allow_unauthenticated_access
|
||||||
|
|
||||||
before_action :set_membership
|
before_action :set_membership
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
class Memberships::EmailAddressesController < ApplicationController
|
class Memberships::EmailAddressesController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
|
|
||||||
layout "public"
|
layout "public"
|
||||||
|
|
||||||
before_action :set_membership
|
before_action :set_membership
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Memberships::UnlinkController < ApplicationController
|
class Memberships::UnlinkController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
before_action :set_membership
|
before_action :set_membership
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class PwaController < ApplicationController
|
class PwaController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
skip_forgery_protection
|
skip_forgery_protection
|
||||||
|
|
||||||
# We need a stable URL at the root, so we can't use the regular asset path here.
|
# We need a stable URL at the root, so we can't use the regular asset path here.
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Sessions::MagicLinksController < ApplicationController
|
class Sessions::MagicLinksController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
require_unauthenticated_access
|
require_unauthenticated_access
|
||||||
rate_limit to: 10, within: 15.minutes, only: :create, with: -> { redirect_to session_magic_link_path, alert: "Try again in 15 minutes." }
|
rate_limit to: 10, within: 15.minutes, only: :create, with: -> { redirect_to session_magic_link_path, alert: "Try again in 15 minutes." }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
class Sessions::MenusController < ApplicationController
|
class Sessions::MenusController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
|
|
||||||
before_action(if: :render_as_menu_section?) { request.variant = :menu_section }
|
before_action(if: :render_as_menu_section?) { request.variant = :menu_section }
|
||||||
|
|
||||||
layout "public"
|
layout "public"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class Sessions::TransfersController < ApplicationController
|
class Sessions::TransfersController < ApplicationController
|
||||||
require_untenanted_access
|
|
||||||
require_unauthenticated_access
|
require_unauthenticated_access
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ class SessionsController < ApplicationController
|
|||||||
SIGNUP_PASSWORD = Rails.env.local? ? "testpassword" : Rails.application.credentials.account_signup_http_basic_auth.password
|
SIGNUP_PASSWORD = Rails.env.local? ? "testpassword" : Rails.application.credentials.account_signup_http_basic_auth.password
|
||||||
http_basic_authenticate_with name: SIGNUP_USERNAME, password: SIGNUP_PASSWORD, realm: "Fizzy Signup", only: :create, unless: -> { Identity.exists?(email_address: email_address) }
|
http_basic_authenticate_with name: SIGNUP_USERNAME, password: SIGNUP_PASSWORD, realm: "Fizzy Signup", only: :create, unless: -> { Identity.exists?(email_address: email_address) }
|
||||||
|
|
||||||
require_untenanted_access
|
|
||||||
require_unauthenticated_access except: :destroy
|
require_unauthenticated_access except: :destroy
|
||||||
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
|
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
def page_title_tag
|
def page_title_tag
|
||||||
account_name = if ApplicationRecord.current_tenant && Current.session&.identity&.memberships&.many?
|
account_name = if Current.account && Current.session&.identity&.memberships&.many?
|
||||||
Account.sole&.name
|
Current.account&.name
|
||||||
end
|
end
|
||||||
tag.title [ @page_title, account_name, "Fizzy" ].compact.join(" | ")
|
tag.title [ @page_title, account_name, "Fizzy" ].compact.join(" | ")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class ApplicationMailer < ActionMailer::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def default_url_options
|
def default_url_options
|
||||||
if ApplicationRecord.current_tenant
|
if Current.account
|
||||||
super.merge(script_name: Account.sole.slug)
|
super.merge(script_name: Current.account.slug)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ module Board::Entropic
|
|||||||
end
|
end
|
||||||
|
|
||||||
def entropy
|
def entropy
|
||||||
super || Account.sole.entropy
|
super || Current.account.entropy
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_postpone_period=(new_value)
|
def auto_postpone_period=(new_value)
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ module Card::Entropic
|
|||||||
active
|
active
|
||||||
.left_outer_joins(board: :entropy)
|
.left_outer_joins(board: :entropy)
|
||||||
.where("last_active_at <= DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')",
|
.where("last_active_at <= DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')",
|
||||||
Account.sole.entropy.auto_postpone_period)
|
Current.account.entropy.auto_postpone_period)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope :postponing_soon, -> do
|
scope :postponing_soon, -> do
|
||||||
active
|
active
|
||||||
.left_outer_joins(board: :entropy)
|
.left_outer_joins(board: :entropy)
|
||||||
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')", Account.sole.entropy.auto_postpone_period)
|
.where("last_active_at > DATETIME('now', '-' || COALESCE(entropies.auto_postpone_period, ?) || ' seconds')", Current.account.entropy.auto_postpone_period)
|
||||||
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropies.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' seconds')", Account.sole.entropy.auto_postpone_period)
|
.where("last_active_at <= DATETIME('now', '-' || CAST(COALESCE(entropies.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' seconds')", Current.account.entropy.auto_postpone_period)
|
||||||
end
|
end
|
||||||
|
|
||||||
delegate :auto_postpone_period, to: :board
|
delegate :auto_postpone_period, to: :board
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ module Card::Promptable
|
|||||||
* Board id: #{board_id}
|
* Board id: #{board_id}
|
||||||
* Board name: #{board.name}
|
* Board name: #{board.name}
|
||||||
* Number of comments: #{comments.count}
|
* Number of comments: #{comments.count}
|
||||||
* Path: #{card_path(self, script_name: Account.sole.slug)}
|
* Path: #{card_path(self, script_name: Current.account.slug)}
|
||||||
|
|
||||||
END OF CARD #{id}
|
END OF CARD #{id}
|
||||||
PROMPT
|
PROMPT
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Comment::Promptable
|
|||||||
* Card title: #{card.title}
|
* Card title: #{card.title}
|
||||||
* Created by: #{creator.name}}
|
* Created by: #{creator.name}}
|
||||||
* Created at: #{created_at}}
|
* Created at: #{created_at}}
|
||||||
* Path: #{card_path(card, anchor: ActionView::RecordIdentifier.dom_id(self), script_name: Account.sole.slug)}
|
* Path: #{card_path(card, anchor: ActionView::RecordIdentifier.dom_id(self), script_name: Current.account.slug)}
|
||||||
END OF COMMENT #{id}
|
END OF COMMENT #{id}
|
||||||
PROMPT
|
PROMPT
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Current < ActiveSupport::CurrentAttributes
|
class Current < ActiveSupport::CurrentAttributes
|
||||||
attribute :session, :membership
|
attribute :session, :membership, :account
|
||||||
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
|
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
|
||||||
|
|
||||||
delegate :identity, to: :session, allow_nil: true
|
delegate :identity, to: :session, allow_nil: true
|
||||||
@@ -8,8 +8,9 @@ class Current < ActiveSupport::CurrentAttributes
|
|||||||
def session=(value)
|
def session=(value)
|
||||||
super(value)
|
super(value)
|
||||||
|
|
||||||
unless value.nil?
|
# # TODO:PLANB: not sure how to patch this up right now
|
||||||
self.membership = identity.memberships.find_by(tenant: ApplicationRecord.current_tenant)
|
# unless value.nil?
|
||||||
end
|
# self.membership = identity.memberships.find_by(tenant: ApplicationRecord.current_tenant)
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,14 +16,11 @@ class Membership < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def account_name
|
def account_name
|
||||||
ApplicationRecord.with_tenant(tenant) { Account.sole.name }
|
Current.account.name
|
||||||
rescue ActiveRecord::Tenanted::TenantDoesNotExistError, ActiveRecord::RecordNotFound
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def user
|
def user
|
||||||
ApplicationRecord.with_tenant(tenant) { User.find_by(membership_id: id) }
|
# TODO:PLANB: should this find should be scoped by account?
|
||||||
rescue ActiveRecord::Tenanted::TenantDoesNotExistError
|
User.find_by(membership_id: id)
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class NotificationPusher
|
|||||||
{
|
{
|
||||||
title: "New notification",
|
title: "New notification",
|
||||||
body: "You have a new notification",
|
body: "You have a new notification",
|
||||||
path: "#{Account.sole.slug}#{notifications_path}"
|
path: "#{Current.account.slug}#{notifications_path}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -110,10 +110,10 @@ class NotificationPusher
|
|||||||
end
|
end
|
||||||
|
|
||||||
def card_path(card)
|
def card_path(card)
|
||||||
"#{Account.sole.slug}#{Rails.application.routes.url_helpers.card_path(card)}"
|
"#{Current.account.slug}#{Rails.application.routes.url_helpers.card_path(card)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def card_path_with_comment_anchor(comment)
|
def card_path_with_comment_anchor(comment)
|
||||||
"#{Account.sole.slug}#{Rails.application.routes.url_helpers.card_path(comment.card, anchor: ActionView::RecordIdentifier.dom_id(comment))}"
|
"#{Current.account.slug}#{Rails.application.routes.url_helpers.card_path(comment.card, anchor: ActionView::RecordIdentifier.dom_id(comment))}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<%= yield :head %>
|
<%= yield :head %>
|
||||||
|
|
||||||
<% if ApplicationRecord.current_tenant %>
|
<% if Current.account %>
|
||||||
<link rel="manifest" href="<%= pwa_manifest_path(format: :json) %>">
|
<link rel="manifest" href="<%= pwa_manifest_path(format: :json) %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
<link rel="icon" href="/favicon.png" type="image/png">
|
<link rel="icon" href="/favicon.png" type="image/png">
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= turbo_frame_tag Current.identity, :account_menu, src: session_menu_url(script_name: nil, menu_section: true, without: ApplicationRecord.current_tenant) %>
|
<%= turbo_frame_tag Current.identity, :account_menu, src: session_menu_url(script_name: nil, menu_section: true, without: Current.account.id) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<footer class="nav__footer">
|
<footer class="nav__footer">
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<% @page_title = @board.name %>
|
<% @page_title = @board.name %>
|
||||||
|
|
||||||
<% content_for :head do %>
|
<% content_for :head do %>
|
||||||
<%= tag.meta property: "og:title", content: "#{@board.name} | #{Account.sole.name}" %>
|
<%= tag.meta property: "og:title", content: "#{@board.name} | #{Current.account.name}" %>
|
||||||
<%= tag.meta property: "og:description", content: format_excerpt(@board&.public_description, length: 200) %>
|
<%= tag.meta property: "og:description", content: format_excerpt(@board&.public_description, length: 200) %>
|
||||||
<%= tag.meta property: "og:image", content: "#{request.base_url}/app-icon.png" %>
|
<%= tag.meta property: "og:image", content: "#{request.base_url}/app-icon.png" %>
|
||||||
<%= tag.meta property: "og:url", content: published_board_url(@board) %>
|
<%= tag.meta property: "og:url", content: published_board_url(@board) %>
|
||||||
|
|
||||||
<%= tag.meta property: "twitter:title", content: "#{@board.name} | #{Account.sole.name}" %>
|
<%= tag.meta property: "twitter:title", content: "#{@board.name} | #{Current.account.name}" %>
|
||||||
<%= tag.meta property: "twitter:description", content: format_excerpt(@board&.public_description, length: 200) %>
|
<%= tag.meta property: "twitter:description", content: format_excerpt(@board&.public_description, length: 200) %>
|
||||||
<%= tag.meta property: "twitter:image", content: "#{request.base_url}/app-icon.png" %>
|
<%= tag.meta property: "twitter:image", content: "#{request.base_url}/app-icon.png" %>
|
||||||
<%= tag.meta property: "twitter:card", content: "summary_large_image" %>
|
<%= tag.meta property: "twitter:card", content: "summary_large_image" %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": <%= [ "Fizzy", Account.sole.name, Rails.env.production? ? nil : Rails.env ].compact.join(" - ").to_json.html_safe %>,
|
"name": <%= [ "Fizzy", Current.account.name, Rails.env.production? ? nil : Rails.env ].compact.join(" - ").to_json.html_safe %>,
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/app-icon-192.png",
|
"src": "/app-icon-192.png",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<h1 class="txt-x-large font-weight-black margin-none">
|
<h1 class="txt-x-large font-weight-black margin-none">
|
||||||
<%= @page_title %>
|
<%= @page_title %>
|
||||||
</h1>
|
</h1>
|
||||||
<p class="margin-none">Just a sec while we sign you in with <%= Account.sole.name %>.</p>
|
<p class="margin-none">Just a sec while we sign you in with <%= Current.account.name %>.</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<%= form_with url: session_start_path, method: :post, data: { controller: "form auto-submit" } do |form| %>
|
<%= form_with url: session_start_path, method: :post, data: { controller: "form auto-submit" } do |form| %>
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ needs_seeding() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
has_tenant=$(bin/rails runner "pp ApplicationRecord.tenants.any? { ApplicationRecord.with_tenant(_1) { Account.sole } }" 2>/dev/null)
|
has_data=$(bin/rails runner "pp Account.all.any?" 2>/dev/null)
|
||||||
if [ "$has_tenant" = "true" ]; then
|
if [ "$has_data" = "true" ] ; then
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
+1
-2
@@ -27,9 +27,8 @@ def create_tenant(signal_account_name)
|
|||||||
membership: membership
|
membership: membership
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Current.account = account
|
||||||
end
|
end
|
||||||
|
|
||||||
ApplicationRecord.current_tenant = tenant_id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_create_user(full_name, email_address)
|
def find_or_create_user(full_name, email_address)
|
||||||
|
|||||||
+5
-4
@@ -1,11 +1,12 @@
|
|||||||
namespace :seed do
|
namespace :seed do
|
||||||
desc "Seed customer data for a specific account (e.g: rails seed:customer ARTENANT=1234)"
|
desc "Seed customer data for a specific account (e.g: rails seed:customer ARTENANT=1234)"
|
||||||
task :customer, [ :tenant_id ] => "db:tenant" do |t, args|
|
task :customer, [ :tenant_id ] => "db:tenant" do |t, args|
|
||||||
raise "Please provide a tenant ID: rails seed:customer ARTENANT=1234" unless ApplicationRecord.current_tenant
|
raise "TODO:PLANB: Need to re-implement this task for untenanted context"
|
||||||
|
# raise "Please provide a tenant ID: rails seed:customer ARTENANT=1234" unless ApplicationRecord.current_tenant
|
||||||
|
|
||||||
account = Account.sole
|
# account = Account.sole
|
||||||
Account::Seeder.new(account, User.active.first).seed!
|
# Account::Seeder.new(account, User.active.first).seed!
|
||||||
|
|
||||||
puts "✓ Seeded account #{account.name} (tenant: #{account.id})"
|
# puts "✓ Seeded account #{account.name} (tenant: #{account.id})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ Current.set(
|
|||||||
|
|
||||||
# Step 3: Get or create join code
|
# Step 3: Get or create join code
|
||||||
ApplicationRecord.with_tenant(tenant_id) do
|
ApplicationRecord.with_tenant(tenant_id) do
|
||||||
account = Account.sole
|
account = Current.account
|
||||||
join_code = account.join_code
|
join_code = account.join_code
|
||||||
|
|
||||||
puts "✓ Join code ready"
|
puts "✓ Join code ready"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ require_relative "../config/environment"
|
|||||||
tenant = ActiveRecord::FixtureSet.identify(identifier)
|
tenant = ActiveRecord::FixtureSet.identify(identifier)
|
||||||
|
|
||||||
ApplicationRecord.with_tenant(tenant) do |tenant|
|
ApplicationRecord.with_tenant(tenant) do |tenant|
|
||||||
Account.sole.destroy!
|
Current.account.destroy!
|
||||||
|
|
||||||
Account.create_with_admin_user \
|
Account.create_with_admin_user \
|
||||||
account: { name: "Company #{identifier}" },
|
account: { name: "Company #{identifier}" },
|
||||||
@@ -48,6 +48,6 @@ ApplicationRecord.with_tenant(tenant) do |tenant|
|
|||||||
board.accesses.grant_to(user)
|
board.accesses.grant_to(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
url = Rails.application.routes.url_helpers.root_url(Rails.application.config.action_controller.default_url_options.merge(script_name: Account.sole.slug))
|
url = Rails.application.routes.url_helpers.root_url(Rails.application.config.action_controller.default_url_options.merge(script_name: Current.account.slug))
|
||||||
puts "\n\nLogin to #{url} as #{user.email_address} / secret123456"
|
puts "\n\nLogin to #{url} as #{user.email_address} / secret123456"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ ApplicationRecord.with_each_tenant do |tenant|
|
|||||||
# Create a new Identity
|
# Create a new Identity
|
||||||
Identity.transaction do
|
Identity.transaction do
|
||||||
identity = Identity.create!
|
identity = Identity.create!
|
||||||
user.membership = identity.memberships.create!(user_id: user.id, user_tenant: user.tenant, email_address: user.email_address, account_name: Account.sole.name)
|
user.membership = identity.memberships.create!(user_id: user.id, user_tenant: user.tenant, email_address: user.email_address, account_name: Current.account.name)
|
||||||
puts "Created identity #{identity.id} for user #{user.id} (#{user.email_address})"
|
puts "Created identity #{identity.id} for user #{user.id} (#{user.email_address})"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# Merge this User's Membership into the existing Identity
|
# Merge this User's Membership into the existing Identity
|
||||||
identity = memberships.first.identity
|
identity = memberships.first.identity
|
||||||
user.membership = identity.memberships.create!(user_id: user.id, user_tenant: user.tenant, email_address: user.email_address, account_name: Account.sole.name)
|
user.membership = identity.memberships.create!(user_id: user.id, user_tenant: user.tenant, email_address: user.email_address, account_name: Current.account.name)
|
||||||
puts "Merged membership for user #{user.id} (#{user.email_address}) into identity #{identity.id}"
|
puts "Merged membership for user #{user.id} (#{user.email_address}) into identity #{identity.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ def fix_attachments(rich_text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
ApplicationRecord.with_each_tenant do |tenant|
|
ApplicationRecord.with_each_tenant do |tenant|
|
||||||
account_id = Account.sole.queenbee_id
|
account_id = Current.account.queenbee_id
|
||||||
|
|
||||||
unless account_id
|
unless account_id
|
||||||
puts "Skipping URL fixup for tenant: #{tenant}"
|
puts "Skipping URL fixup for tenant: #{tenant}"
|
||||||
@@ -37,7 +37,7 @@ ApplicationRecord.with_each_tenant do |tenant|
|
|||||||
domain = domains[Rails.env] || domains["production"]
|
domain = domains[Rails.env] || domains["production"]
|
||||||
regex = %r{://\w+\.#{domain}/}
|
regex = %r{://\w+\.#{domain}/}
|
||||||
|
|
||||||
pp [ Account.sole.name, account_id, domain, regex ]
|
pp [ Current.account.name, account_id, domain, regex ]
|
||||||
puts
|
puts
|
||||||
|
|
||||||
Card.find_each do |card|
|
Card.find_each do |card|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Account::SettingsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
test "update" do
|
test "update" do
|
||||||
put account_settings_path, params: { account: { name: "New Account Name" } }
|
put account_settings_path, params: { account: { name: "New Account Name" } }
|
||||||
assert_equal "New Account Name", Account.sole.name
|
assert_equal "New Account Name", Current.account.name
|
||||||
assert_redirected_to account_settings_path
|
assert_redirected_to account_settings_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
class IdentityMailerPreview < ActionMailer::Preview
|
class IdentityMailerPreview < ActionMailer::Preview
|
||||||
def email_change_confirmation
|
def email_change_confirmation
|
||||||
ApplicationRecord.current_tenant = "897362094"
|
flunk "TODO:PLANB: need to figure out how to test this without setting a tenant"
|
||||||
|
# ApplicationRecord.current_tenant = "897362094"
|
||||||
|
|
||||||
identity = Identity.find_by(email_address: "david@37signals.com")
|
# identity = Identity.find_by(email_address: "david@37signals.com")
|
||||||
membership = identity&.memberships&.find_by(tenant: ApplicationRecord.current_tenant)
|
# membership = identity&.memberships&.find_by(tenant: ApplicationRecord.current_tenant)
|
||||||
|
|
||||||
new_email_address = "david.new@example.com"
|
# new_email_address = "david.new@example.com"
|
||||||
token = membership.send(:generate_email_address_change_token, to: new_email_address)
|
# token = membership.send(:generate_email_address_change_token, to: new_email_address)
|
||||||
|
|
||||||
IdentityMailer.email_change_confirmation(
|
# IdentityMailer.email_change_confirmation(
|
||||||
email_address: new_email_address,
|
# email_address: new_email_address,
|
||||||
token: token,
|
# token: token,
|
||||||
membership: membership
|
# membership: membership
|
||||||
)
|
# )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require "test_helper"
|
|||||||
|
|
||||||
class Account::SedeableTest < ActiveSupport::TestCase
|
class Account::SedeableTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@account = Account.sole
|
@account = Current.account
|
||||||
end
|
end
|
||||||
|
|
||||||
test "setup_customer_template adds boards, cards, and comments" do
|
test "setup_customer_template adds boards, cards, and comments" do
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class AccountTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "slug" do
|
test "slug" do
|
||||||
account = Account.sole
|
account = Current.account
|
||||||
assert_equal "/#{ApplicationRecord.current_tenant}", account.slug
|
assert_equal "/#{ApplicationRecord.current_tenant}", account.slug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Entropy::Test < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "touch cards when entropy changes for account container" do
|
test "touch cards when entropy changes for account container" do
|
||||||
account = Account.sole
|
account = Current.account
|
||||||
|
|
||||||
assert_changes -> { account.cards.first.updated_at } do
|
assert_changes -> { account.cards.first.updated_at } do
|
||||||
boards(:writebook).entropy.update!(auto_postpone_period: 15.days)
|
boards(:writebook).entropy.update!(auto_postpone_period: 15.days)
|
||||||
|
|||||||
Reference in New Issue
Block a user