Drop User.system and replace with Account#system_user

This commit is contained in:
Mike Dalessio
2025-11-24 13:10:39 -05:00
parent a9da44b575
commit e0aa1d257e
11 changed files with 33 additions and 23 deletions
+4
View File
@@ -31,4 +31,8 @@ class Account < ApplicationRecord
def account
self
end
def system_user
users.where(role: :system).first!
end
end
+1 -1
View File
@@ -49,7 +49,7 @@ module Board::Accessible
end
def watchers
users.without(User.system).where(accesses: { involvement: :watching })
users.active.where(accesses: { involvement: :watching })
end
private
+1 -1
View File
@@ -26,7 +26,7 @@ module Card::Entropic
class_methods do
def auto_postpone_all_due
due_to_be_postponed.find_each do |card|
card.auto_postpone(user: User.system)
card.auto_postpone(user: card.account.system_user)
end
end
end
@@ -8,7 +8,7 @@ class Card::Eventable::SystemCommenter
def comment
return unless comment_body.present?
card.comments.create! creator: User.system, body: comment_body, created_at: event.created_at
card.comments.create! creator: card.account.system_user, body: comment_body, created_at: event.created_at
end
private
-6
View File
@@ -8,12 +8,6 @@ module User::Role
scope :active, -> { where(active: true, role: %i[ admin member ]) }
end
class_methods do
def system
find_or_create_by!(account: Current.account, role: :system) { it.name = "System" }
end
end
def can_change?(other)
admin? || other == self
end
+2 -2
View File
@@ -2,11 +2,11 @@
<strong class="txt-uppercase">Subscribers</strong>
<p class="margin-none-block-start margin-block-end-half">
<%= pluralize(card.watchers.without(User.system).count, "person") %> will be notified when someone comments on this.
<%= pluralize(card.watchers.active.count, "person") %> will be notified when someone comments on this.
</p>
<div class="flex align-center flex-wrap gap-half max-width txt-normal">
<% card.watchers.without(User.system).alphabetically.each do |watcher| %>
<% card.watchers.active.alphabetically.each do |watcher| %>
<%= avatar_tag watcher %>
<% end %>
</div>
+6
View File
@@ -31,3 +31,9 @@ mike:
role: admin
identity: mike
account: initech_uuid
system_initech:
id: <%= ActiveRecord::FixtureSet.identify("system_initech", :uuid) %>
name: System
role: system
account: initech_uuid
+16
View File
@@ -41,6 +41,22 @@ class AccountTest < ActiveSupport::TestCase
assert_equal "David", admin.name
assert_equal "david@37signals.com", admin.identity.email_address
assert_equal "admin", admin.role
assert_predicate account.system_user, :present?
end
end
test "#system_user returns the system user of the account" do
system_user = User.find_by!(account: accounts("37s"), role: :system)
assert_equal system_user, accounts("37s").system_user
end
test "#system_user raises if there is no system user" do
account = Account.create!(name: "No System User Account")
assert_raises ActiveRecord::RecordNotFound do
account.system_user
end
end
end
+1 -1
View File
@@ -43,7 +43,7 @@ class Card::EntropicTest < ActiveSupport::TestCase
end
assert cards(:logo).reload.postponed?
assert_equal User.system, cards(:logo).postponed_by
assert_equal accounts("37s").system_user, cards(:logo).postponed_by
assert_not cards(:shipping).reload.postponed?
end
+1 -1
View File
@@ -7,7 +7,7 @@ class Notifier::EventNotifierTest < ActiveSupport::TestCase
test "generate does not create notifications if the event was system-generated" do
cards(:logo).drafted!
events(:logo_published).update!(creator: User.system)
events(:logo_published).update!(creator: accounts("37s").system_user)
assert_no_difference -> { Notification.count } do
Notifier.for(events(:logo_published)).notify
-10
View File
@@ -35,14 +35,4 @@ class UserTest < ActiveSupport::TestCase
assert_equal "DHH", User.new(name: "David Heinemeier Hansson").initials
assert_equal "ÉLH", User.new(name: "Éva-Louise Hernández").initials
end
test "system user" do
system_user = User.system
assert system_user.system?
assert_equal "System", system_user.name
assert_equal "S", system_user.initials
assert_not_includes User.active, system_user
end
end