From a791fe1919e0faf01dfa54158c3640bcc5166669 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Fri, 30 Jan 2026 16:25:01 +0100 Subject: [PATCH] Hide importing accounts --- app/controllers/account/imports_controller.rb | 1 + app/models/account.rb | 11 +++++++++++ app/models/account/cancellable.rb | 6 ------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/account/imports_controller.rb b/app/controllers/account/imports_controller.rb index 05d9f957c..ac93f40d1 100644 --- a/app/controllers/account/imports_controller.rb +++ b/app/controllers/account/imports_controller.rb @@ -2,6 +2,7 @@ class Account::ImportsController < ApplicationController layout "public" disallow_account_scope only: %i[ new create ] + allow_unauthorized_access only: :show before_action :set_import, only: %i[ show ] def new diff --git a/app/models/account.rb b/app/models/account.rb index 7087a5b9b..92590d9f9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -12,6 +12,9 @@ class Account < ApplicationRecord has_many :exports, class_name: "Account::Export", dependent: :destroy has_many :imports, class_name: "Account::Import", dependent: :destroy + scope :importing, -> { left_joins(:imports).where(account_imports: { status: %i[pending processing failed] }) } + scope :active, -> { where.missing(:cancellation).and(where.not(id: importing)) } + before_create :assign_external_account_id after_create :create_join_code @@ -38,6 +41,14 @@ class Account < ApplicationRecord users.find_by!(role: :system) end + def active? + !cancelled? && !importing? + end + + def importing? + imports.where(status: %i[pending processing failed]).exists? + end + private def assign_external_account_id self.external_account_id ||= ExternalIdSequence.next diff --git a/app/models/account/cancellable.rb b/app/models/account/cancellable.rb index f10624245..71e5ac733 100644 --- a/app/models/account/cancellable.rb +++ b/app/models/account/cancellable.rb @@ -4,8 +4,6 @@ module Account::Cancellable included do has_one :cancellation, dependent: :destroy - scope :active, -> { where.missing(:cancellation) } - define_callbacks :cancel define_callbacks :reactivate end @@ -32,10 +30,6 @@ module Account::Cancellable end end - def active? - !cancelled? - end - def cancelled? cancellation.present? end