From 15eeba82f56f80f8ee2d08e014612062bb6a68bf Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Fri, 14 Nov 2025 13:07:30 +0100 Subject: [PATCH] Scope model methods by account --- app/models/account.rb | 4 ++-- app/models/ai.rb | 5 ----- app/models/card.rb | 2 +- app/models/push/subscription.rb | 8 +++++++- app/models/user/filtering.rb | 11 ++++++++--- app/models/webhook.rb | 2 +- 6 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 app/models/ai.rb diff --git a/app/models/account.rb b/app/models/account.rb index 5916bc690..0e7708847 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -18,8 +18,8 @@ class Account < ApplicationRecord class << self def create_with_admin_user(account:, owner:) create!(**account).tap do |account| - User.create!(account: account, role: :system, name: "System") - User.create!(**owner.reverse_merge(role: "admin", account: account)) + account.users.create!(role: :system, name: "System") + account.users.create!(**owner.reverse_merge(role: "admin")) end end end diff --git a/app/models/ai.rb b/app/models/ai.rb deleted file mode 100644 index 4b4c17743..000000000 --- a/app/models/ai.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Ai - def self.table_name_prefix - "ai_" - end -end diff --git a/app/models/card.rb b/app/models/card.rb index a509b4ff2..37832092e 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -64,7 +64,7 @@ class Card < ApplicationRecord end def handle_board_change - old_board = Board.find_by(id: board_id_before_last_save) + old_board = account.boards.find_by(id: board_id_before_last_save) transaction do update! column: nil diff --git a/app/models/push/subscription.rb b/app/models/push/subscription.rb index 604d356c4..0b273b563 100644 --- a/app/models/push/subscription.rb +++ b/app/models/push/subscription.rb @@ -3,6 +3,12 @@ class Push::Subscription < ApplicationRecord belongs_to :user def notification(**params) - WebPush::Notification.new(**params, badge: user.notifications.unread.count, endpoint: endpoint, p256dh_key: p256dh_key, auth_key: auth_key) + WebPush::Notification.new( + **params, + badge: user.notifications.unread.count, + endpoint: endpoint, + p256dh_key: p256dh_key, + auth_key: auth_key + ) end end diff --git a/app/models/user/filtering.rb b/app/models/user/filtering.rb index 5cd9516c0..1b4f3070e 100644 --- a/app/models/user/filtering.rb +++ b/app/models/user/filtering.rb @@ -21,15 +21,15 @@ class User::Filtering end def tags - @tags ||= Tag.all.alphabetically + @tags ||= account.tags.all.alphabetically end def users - @users ||= Current.account.users.active.alphabetically + @users ||= account.users.active.alphabetically end def filters - @filters ||= Current.user.filters.all + @filters ||= user.filters.all end def expanded? @@ -77,4 +77,9 @@ class User::Filtering def cache_key ActiveSupport::Cache.expand_cache_key([ user, filter, expanded?, boards, tags, users, filters ], "user-filtering") end + + private + def account + user.account + end end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 92e7547ac..3b34af041 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -49,7 +49,7 @@ class Webhook < ApplicationRecord end def renderer - @renderer ||= ApplicationController.renderer.new(script_name: "/#{account.external_account_id}", https: !Rails.env.local?) + @renderer ||= ApplicationController.renderer.new(script_name: account.slug, https: !Rails.env.local?) end def for_basecamp?