diff --git a/app/controllers/sessions/menus_controller.rb b/app/controllers/sessions/menus_controller.rb index d62cf9beb..984e83a43 100644 --- a/app/controllers/sessions/menus_controller.rb +++ b/app/controllers/sessions/menus_controller.rb @@ -1,24 +1,13 @@ class Sessions::MenusController < ApplicationController disallow_account_scope - before_action(if: :render_as_menu_section?) { request.variant = :menu_section } - layout "public" def show - @memberships = Current.identity.memberships + @accounts = Current.identity.accounts - if params[:without] - @memberships = @memberships.where.not(tenant: params[:without]) - end - - if @memberships.one? && !render_as_menu_section? - redirect_to root_url(script_name: "/#{@memberships.first.tenant}") + if @accounts.one? + redirect_to root_url(script_name: @accounts.first.slug) end end - - private - def render_as_menu_section? - params[:menu_section] - end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index deda51d5e..1c5fa524c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -20,7 +20,7 @@ class SessionsController < ApplicationController redirect_to session_magic_link_path elsif signups_allowed? Signup.new(email_address: email_address).create_identity - session[:return_to_after_authenticating] = saas.new_signup_membership_path + session[:return_to_after_authenticating] = saas.new_signup_completion_path redirect_to session_magic_link_path end end diff --git a/app/models/account/seedeable.rb b/app/models/account/seedeable.rb index cd8bea1fe..f0592020a 100644 --- a/app/models/account/seedeable.rb +++ b/app/models/account/seedeable.rb @@ -2,6 +2,6 @@ module Account::Seedeable extend ActiveSupport::Concern def setup_customer_template - Account::Seeder.new(self, users.active.first).seed + Account::Seeder.new(self, users.active.where(role: :admin).first).seed end end diff --git a/app/models/account/seeder.rb b/app/models/account/seeder.rb index 28835041c..f7f7cf60b 100644 --- a/app/models/account/seeder.rb +++ b/app/models/account/seeder.rb @@ -7,7 +7,7 @@ class Account::Seeder end def seed - Current.set session: session do + Current.set(user: creator, account: account) do populate end end @@ -20,15 +20,11 @@ class Account::Seeder end private - def session - creator.identity.sessions.last - end - def populate # --------------- # Playground Board # --------------- - playground = Board.create! name: "Playground", creator: creator, all_access: true + playground = account.boards.create! name: "Playground", creator: creator, all_access: true # Cards playground.cards.create! creator: creator, title: "Finally, watch this Fizzy orientation video", status: "published", description: <<~HTML @@ -104,8 +100,8 @@ class Account::Seeder end def delete_everything - Current.set session: session do - Board.destroy_all + Current.set(user: creator, account: account) do + account.boards.destroy_all end end end diff --git a/app/models/board.rb b/app/models/board.rb index 4b5752604..b39e47441 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -1,7 +1,7 @@ class Board < ApplicationRecord include Accessible, AutoPostponing, Broadcastable, Cards, Entropic, Filterable, Publishable, Triageable - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { creator.account } belongs_to :creator, class_name: "User", default: -> { Current.user } has_rich_text :public_description diff --git a/app/models/column.rb b/app/models/column.rb index 5b3815561..4c8358871 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -1,7 +1,7 @@ class Column < ApplicationRecord include Colored, Positioned - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { board.account } belongs_to :board, touch: true has_many :cards, dependent: :nullify diff --git a/app/models/comment.rb b/app/models/comment.rb index b5e84d692..a42b205fc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,7 +1,7 @@ class Comment < ApplicationRecord include Attachments, Eventable, Mentions, Promptable, Searchable - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { card.account } belongs_to :card, touch: true belongs_to :creator, class_name: "User", default: -> { Current.user } has_many :reactions, dependent: :delete_all diff --git a/app/models/event.rb b/app/models/event.rb index cca00d66f..c759c18ee 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,7 +1,7 @@ class Event < ApplicationRecord include Notifiable, Particulars, Promptable - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { board.account } belongs_to :board belongs_to :creator, class_name: "User" belongs_to :eventable, polymorphic: true diff --git a/app/models/filter.rb b/app/models/filter.rb index 894a7ccca..94ce8ce72 100644 --- a/app/models/filter.rb +++ b/app/models/filter.rb @@ -1,7 +1,7 @@ class Filter < ApplicationRecord include Fields, Params, Resources, Summarized - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { creator.account } belongs_to :creator, class_name: "User", default: -> { Current.user } class << self diff --git a/app/models/identity.rb b/app/models/identity.rb index e0bb7ec0f..fc1c12bcd 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -1,9 +1,12 @@ class Identity < ApplicationRecord include Joinable, Transferable - has_many :users, dependent: :nullify has_many :magic_links, dependent: :destroy has_many :sessions, dependent: :destroy + has_many :users, dependent: :nullify + has_many :accounts, through: :users + + has_one_attached :avatar before_destroy :deactivate_users diff --git a/app/models/push/subscription.rb b/app/models/push/subscription.rb index 5776ef25f..604d356c4 100644 --- a/app/models/push/subscription.rb +++ b/app/models/push/subscription.rb @@ -1,5 +1,5 @@ class Push::Subscription < ApplicationRecord - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { user.account } belongs_to :user def notification(**params) diff --git a/app/models/step.rb b/app/models/step.rb index c3cf12378..27d580de1 100644 --- a/app/models/step.rb +++ b/app/models/step.rb @@ -1,5 +1,5 @@ class Step < ApplicationRecord - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { card.account } belongs_to :card, touch: true scope :completed, -> { where(completed: true) } diff --git a/app/models/user.rb b/app/models/user.rb index 3b541f1ac..cef823a1f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ class User < ApplicationRecord has_one_attached :avatar - belongs_to :account, default: -> { Current.account } + belongs_to :account belongs_to :identity, optional: true has_many :comments, inverse_of: :creator, dependent: :destroy diff --git a/app/models/webhook.rb b/app/models/webhook.rb index c8292a1f6..92e7547ac 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -25,7 +25,7 @@ class Webhook < ApplicationRecord has_many :deliveries, dependent: :delete_all has_one :delinquency_tracker, dependent: :delete - belongs_to :account, default: -> { Current.account } + belongs_to :account, default: -> { board.account } belongs_to :board serialize :subscribed_actions, type: Array, coder: JSON diff --git a/app/views/my/menus/show.html.erb b/app/views/my/menus/show.html.erb index 50b7089e4..f4ab9fa86 100644 --- a/app/views/my/menus/show.html.erb +++ b/app/views/my/menus/show.html.erb @@ -61,7 +61,16 @@ <% end %> <% end %> - <%= turbo_frame_tag Current.identity, :account_menu, src: session_menu_url(script_name: nil, menu_section: true, without: Current.account.id) %> + <% accounts = Current.identity.accounts.where.not(id: Current.account) %> + <% if accounts.any? %> + <% cache [ Current.identity, accounts ] do %> + <%= collapsible_nav_section "Accounts" do %> + <% accounts.each do |account| %> + <%= filter_place_menu_item landing_url(script_name: account.slug), account.name, "marker", new_window: true %> + <% end %> + <% end %> + <% end %> + <% end %> <% end %>