diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb
index f1e997503..a01c27bc2 100644
--- a/app/channels/application_cable/connection.rb
+++ b/app/channels/application_cable/connection.rb
@@ -10,8 +10,9 @@ module ApplicationCable
private
def set_current_user
if session = find_session_by_cookie
- membership = session.identity.memberships.find_by!(tenant: current_tenant)
- self.current_user = membership.user if membership.user.active?
+ # # TODO:PLANB: not sure how to fix this
+ # membership = session.identity.memberships.find_by!(tenant: current_tenant)
+ # self.current_user = membership.user if membership.user.active?
end
end
diff --git a/app/controllers/account/entropies_controller.rb b/app/controllers/account/entropies_controller.rb
index 00d195584..9876e99d8 100644
--- a/app/controllers/account/entropies_controller.rb
+++ b/app/controllers/account/entropies_controller.rb
@@ -2,7 +2,7 @@ class Account::EntropiesController < ApplicationController
before_action :ensure_admin
def update
- Account.sole.entropy.update!(entropy_params)
+ Current.account.entropy.update!(entropy_params)
redirect_to account_settings_path, notice: "Account updated"
end
diff --git a/app/controllers/account/settings_controller.rb b/app/controllers/account/settings_controller.rb
index 42a6a60f7..bbfec0fe1 100644
--- a/app/controllers/account/settings_controller.rb
+++ b/app/controllers/account/settings_controller.rb
@@ -13,7 +13,7 @@ class Account::SettingsController < ApplicationController
private
def set_account
- @account = Account.sole
+ @account = Current.account
end
def account_params
diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb
index 5afbcccf8..9577ccb1d 100644
--- a/app/controllers/concerns/authentication.rb
+++ b/app/controllers/concerns/authentication.rb
@@ -2,8 +2,6 @@ module Authentication
extend ActiveSupport::Concern
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
before_action :require_authentication
@@ -25,11 +23,6 @@ module Authentication
before_action :resume_session, **options
allow_unauthorized_access **options
end
-
- def require_untenanted_access(**options)
- skip_before_action :require_tenant, **options
- before_action :redirect_tenanted_request, **options
- end
end
private
@@ -37,12 +30,6 @@ module Authentication
Current.session.present?
end
- def require_tenant
- if ApplicationRecord.current_tenant.blank?
- redirect_to session_menu_url(script_name: nil)
- end
- end
-
def require_authentication
resume_session || request_authentication
end
@@ -65,9 +52,7 @@ module Authentication
end
def request_authentication
- if ApplicationRecord.current_tenant.present?
- session[:return_to_after_authenticating] = request.url
- end
+ session[:return_to_after_authenticating] = request.url
redirect_to_login_url
end
@@ -80,10 +65,6 @@ module Authentication
redirect_to root_url if authenticated?
end
- def redirect_tenanted_request
- redirect_to root_url if ApplicationRecord.current_tenant
- end
-
def start_new_session_for(identity)
identity.sessions.create!(user_agent: request.user_agent, ip_address: request.remote_ip).tap do |session|
set_current_session session
diff --git a/app/controllers/concerns/authorization.rb b/app/controllers/concerns/authorization.rb
index 6d31f844e..dfd0e946d 100644
--- a/app/controllers/concerns/authorization.rb
+++ b/app/controllers/concerns/authorization.rb
@@ -2,7 +2,7 @@ module Authorization
extend ActiveSupport::Concern
included do
- before_action :ensure_can_access_account, if: -> { ApplicationRecord.current_tenant && authenticated? }
+ before_action :ensure_can_access_account, if: -> { authenticated? }
end
class_methods do
diff --git a/app/controllers/join_codes_controller.rb b/app/controllers/join_codes_controller.rb
index a4b6768b9..dcceb9f60 100644
--- a/app/controllers/join_codes_controller.rb
+++ b/app/controllers/join_codes_controller.rb
@@ -1,5 +1,4 @@
class JoinCodesController < ApplicationController
- require_untenanted_access
allow_unauthenticated_access
before_action :set_join_code
before_action :ensure_join_code_is_valid
@@ -7,7 +6,7 @@ class JoinCodesController < ApplicationController
layout "public"
def new
- @account_name = ApplicationRecord.with_tenant(tenant) { Account.sole.name }
+ @account_name = Current.account.name
end
def create
@@ -30,7 +29,8 @@ class JoinCodesController < ApplicationController
end
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
def tenant
diff --git a/app/controllers/memberships/email_addresses/confirmations_controller.rb b/app/controllers/memberships/email_addresses/confirmations_controller.rb
index b53fdc135..42d9fb096 100644
--- a/app/controllers/memberships/email_addresses/confirmations_controller.rb
+++ b/app/controllers/memberships/email_addresses/confirmations_controller.rb
@@ -1,5 +1,4 @@
class Memberships::EmailAddresses::ConfirmationsController < ApplicationController
- require_untenanted_access
allow_unauthenticated_access
before_action :set_membership
diff --git a/app/controllers/memberships/email_addresses_controller.rb b/app/controllers/memberships/email_addresses_controller.rb
index 0870410a9..f72389e64 100644
--- a/app/controllers/memberships/email_addresses_controller.rb
+++ b/app/controllers/memberships/email_addresses_controller.rb
@@ -1,6 +1,4 @@
class Memberships::EmailAddressesController < ApplicationController
- require_untenanted_access
-
layout "public"
before_action :set_membership
diff --git a/app/controllers/memberships/unlink_controller.rb b/app/controllers/memberships/unlink_controller.rb
index 63664aca8..ab29d5be9 100644
--- a/app/controllers/memberships/unlink_controller.rb
+++ b/app/controllers/memberships/unlink_controller.rb
@@ -1,5 +1,4 @@
class Memberships::UnlinkController < ApplicationController
- require_untenanted_access
before_action :set_membership
def show
diff --git a/app/controllers/pwa_controller.rb b/app/controllers/pwa_controller.rb
index bd6127182..53f299311 100644
--- a/app/controllers/pwa_controller.rb
+++ b/app/controllers/pwa_controller.rb
@@ -1,5 +1,4 @@
class PwaController < ApplicationController
- require_untenanted_access
skip_forgery_protection
# We need a stable URL at the root, so we can't use the regular asset path here.
diff --git a/app/controllers/sessions/magic_links_controller.rb b/app/controllers/sessions/magic_links_controller.rb
index 3b836e445..43021befc 100644
--- a/app/controllers/sessions/magic_links_controller.rb
+++ b/app/controllers/sessions/magic_links_controller.rb
@@ -1,5 +1,4 @@
class Sessions::MagicLinksController < ApplicationController
- require_untenanted_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." }
diff --git a/app/controllers/sessions/menus_controller.rb b/app/controllers/sessions/menus_controller.rb
index 7ad3b6a09..c6f884856 100644
--- a/app/controllers/sessions/menus_controller.rb
+++ b/app/controllers/sessions/menus_controller.rb
@@ -1,6 +1,4 @@
class Sessions::MenusController < ApplicationController
- require_untenanted_access
-
before_action(if: :render_as_menu_section?) { request.variant = :menu_section }
layout "public"
diff --git a/app/controllers/sessions/transfers_controller.rb b/app/controllers/sessions/transfers_controller.rb
index b3b7ae773..97a48daa4 100644
--- a/app/controllers/sessions/transfers_controller.rb
+++ b/app/controllers/sessions/transfers_controller.rb
@@ -1,5 +1,4 @@
class Sessions::TransfersController < ApplicationController
- require_untenanted_access
require_unauthenticated_access
def show
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 8f8222ed9..e6f4ab665 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -4,7 +4,6 @@ class SessionsController < ApplicationController
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) }
- require_untenanted_access
require_unauthenticated_access except: :destroy
rate_limit to: 10, within: 3.minutes, only: :create, with: -> { redirect_to new_session_path, alert: "Try again later." }
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e4f5b4945..0839f1ae3 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,7 +1,7 @@
module ApplicationHelper
def page_title_tag
- account_name = if ApplicationRecord.current_tenant && Current.session&.identity&.memberships&.many?
- Account.sole&.name
+ account_name = if Current.account && Current.session&.identity&.memberships&.many?
+ Current.account&.name
end
tag.title [ @page_title, account_name, "Fizzy" ].compact.join(" | ")
end
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index abeb3ae09..7fd915dba 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -7,8 +7,8 @@ class ApplicationMailer < ActionMailer::Base
private
def default_url_options
- if ApplicationRecord.current_tenant
- super.merge(script_name: Account.sole.slug)
+ if Current.account
+ super.merge(script_name: Current.account.slug)
else
super
end
diff --git a/app/models/board/entropic.rb b/app/models/board/entropic.rb
index b29d5ea42..d49e0007a 100644
--- a/app/models/board/entropic.rb
+++ b/app/models/board/entropic.rb
@@ -7,7 +7,7 @@ module Board::Entropic
end
def entropy
- super || Account.sole.entropy
+ super || Current.account.entropy
end
def auto_postpone_period=(new_value)
diff --git a/app/models/card/entropic.rb b/app/models/card/entropic.rb
index 478d4bc52..c666fa0e8 100644
--- a/app/models/card/entropic.rb
+++ b/app/models/card/entropic.rb
@@ -6,14 +6,14 @@ module Card::Entropic
active
.left_outer_joins(board: :entropy)
.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
scope :postponing_soon, -> do
active
.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', '-' || CAST(COALESCE(entropies.auto_postpone_period, ?) * 0.75 AS INTEGER) || ' 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')", Current.account.entropy.auto_postpone_period)
end
delegate :auto_postpone_period, to: :board
diff --git a/app/models/card/promptable.rb b/app/models/card/promptable.rb
index e30816023..ef2799b8f 100644
--- a/app/models/card/promptable.rb
+++ b/app/models/card/promptable.rb
@@ -24,7 +24,7 @@ module Card::Promptable
* Board id: #{board_id}
* Board name: #{board.name}
* 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}
PROMPT
diff --git a/app/models/comment/promptable.rb b/app/models/comment/promptable.rb
index 93c931432..bc20ebfa3 100644
--- a/app/models/comment/promptable.rb
+++ b/app/models/comment/promptable.rb
@@ -20,7 +20,7 @@ module Comment::Promptable
* Card title: #{card.title}
* Created by: #{creator.name}}
* 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}
PROMPT
end
diff --git a/app/models/current.rb b/app/models/current.rb
index a3ba812a6..ad5131128 100644
--- a/app/models/current.rb
+++ b/app/models/current.rb
@@ -1,5 +1,5 @@
class Current < ActiveSupport::CurrentAttributes
- attribute :session, :membership
+ attribute :session, :membership, :account
attribute :http_method, :request_id, :user_agent, :ip_address, :referrer
delegate :identity, to: :session, allow_nil: true
@@ -8,8 +8,9 @@ class Current < ActiveSupport::CurrentAttributes
def session=(value)
super(value)
- unless value.nil?
- self.membership = identity.memberships.find_by(tenant: ApplicationRecord.current_tenant)
- end
+ # # TODO:PLANB: not sure how to patch this up right now
+ # unless value.nil?
+ # self.membership = identity.memberships.find_by(tenant: ApplicationRecord.current_tenant)
+ # end
end
end
diff --git a/app/models/membership.rb b/app/models/membership.rb
index 30cd658c2..03fba7d63 100644
--- a/app/models/membership.rb
+++ b/app/models/membership.rb
@@ -16,14 +16,11 @@ class Membership < ApplicationRecord
end
def account_name
- ApplicationRecord.with_tenant(tenant) { Account.sole.name }
- rescue ActiveRecord::Tenanted::TenantDoesNotExistError, ActiveRecord::RecordNotFound
- nil
+ Current.account.name
end
def user
- ApplicationRecord.with_tenant(tenant) { User.find_by(membership_id: id) }
- rescue ActiveRecord::Tenanted::TenantDoesNotExistError
- nil
+ # TODO:PLANB: should this find should be scoped by account?
+ User.find_by(membership_id: id)
end
end
diff --git a/app/models/notification_pusher.rb b/app/models/notification_pusher.rb
index 0938954b0..debfc225b 100644
--- a/app/models/notification_pusher.rb
+++ b/app/models/notification_pusher.rb
@@ -88,7 +88,7 @@ class NotificationPusher
{
title: "New notification",
body: "You have a new notification",
- path: "#{Account.sole.slug}#{notifications_path}"
+ path: "#{Current.account.slug}#{notifications_path}"
}
end
@@ -110,10 +110,10 @@ class NotificationPusher
end
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
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
diff --git a/app/views/layouts/shared/_head.html.erb b/app/views/layouts/shared/_head.html.erb
index fd4b7cab7..4569cd9fd 100644
--- a/app/views/layouts/shared/_head.html.erb
+++ b/app/views/layouts/shared/_head.html.erb
@@ -23,7 +23,7 @@
<%= yield :head %>
- <% if ApplicationRecord.current_tenant %>
+ <% if Current.account %>
<% end %>
diff --git a/app/views/my/menus/show.html.erb b/app/views/my/menus/show.html.erb
index 94e14a642..50b7089e4 100644
--- a/app/views/my/menus/show.html.erb
+++ b/app/views/my/menus/show.html.erb
@@ -61,7 +61,7 @@
<% 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 %>