Scope model methods by account

This commit is contained in:
Stanko K.R.
2025-11-14 13:07:30 +01:00
committed by Mike Dalessio
parent a0251255a7
commit 15eeba82f5
6 changed files with 19 additions and 13 deletions
+2 -2
View File
@@ -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
-5
View File
@@ -1,5 +0,0 @@
module Ai
def self.table_name_prefix
"ai_"
end
end
+1 -1
View File
@@ -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
+7 -1
View File
@@ -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
+8 -3
View File
@@ -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
+1 -1
View File
@@ -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?