Extract User::Accessor concern
Our User model is getting overloaded
This commit is contained in:
+1
-10
@@ -1,15 +1,11 @@
|
||||
class User < ApplicationRecord
|
||||
include Avatar, Role, Transferable
|
||||
include Accessor, Avatar, Role, Transferable
|
||||
|
||||
belongs_to :account
|
||||
|
||||
has_many :sessions, dependent: :destroy
|
||||
has_secure_password validations: false
|
||||
|
||||
has_many :accesses, dependent: :destroy
|
||||
has_many :buckets, through: :accesses
|
||||
has_many :accessible_bubbles, through: :buckets, source: :bubbles
|
||||
|
||||
has_many :filters, foreign_key: :creator_id, inverse_of: :creator, dependent: :destroy
|
||||
|
||||
has_many :pops, dependent: :nullify
|
||||
@@ -27,8 +23,6 @@ class User < ApplicationRecord
|
||||
|
||||
normalizes :email_address, with: ->(value) { value.strip.downcase }
|
||||
|
||||
after_create_commit :grant_access_to_buckets
|
||||
|
||||
scope :alphabetically, -> { order("lower(name)") }
|
||||
scope :sorted_with_user_first, ->(user) { order(Arel.sql("users.id != ?, lower(name)", user.id)) }
|
||||
|
||||
@@ -53,7 +47,4 @@ class User < ApplicationRecord
|
||||
email_address.sub(/@/, "-deactivated-#{SecureRandom.uuid}@")
|
||||
end
|
||||
|
||||
def grant_access_to_buckets
|
||||
Access.insert_all account.buckets.all_access.pluck(:id).collect { |bucket_id| { bucket_id: bucket_id, user_id: id } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
module User::Accessor
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :accesses, dependent: :destroy
|
||||
has_many :buckets, through: :accesses
|
||||
has_many :accessible_bubbles, through: :buckets, source: :bubbles
|
||||
|
||||
after_create_commit :grant_access_to_buckets
|
||||
end
|
||||
|
||||
private
|
||||
def grant_access_to_buckets
|
||||
Access.insert_all account.buckets.all_access.pluck(:id).collect { |bucket_id| { bucket_id: bucket_id, user_id: id } }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user