@@ -9,23 +9,21 @@
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
# created_by_id :bigint not null
|
||||
# updated_by_id :bigint not null
|
||||
# created_by_id :bigint
|
||||
# updated_by_id :bigint
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_macros_on_account_id (account_id)
|
||||
# index_macros_on_created_by_id (created_by_id)
|
||||
# index_macros_on_updated_by_id (updated_by_id)
|
||||
# index_macros_on_account_id (account_id)
|
||||
#
|
||||
class Macro < ApplicationRecord
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :created_by,
|
||||
class_name: :User
|
||||
class_name: :User, optional: true
|
||||
belongs_to :updated_by,
|
||||
class_name: :User
|
||||
class_name: :User, optional: true
|
||||
has_many_attached :files
|
||||
|
||||
enum visibility: { personal: 0, global: 1 }
|
||||
@@ -41,10 +39,9 @@ class Macro < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.with_visibility(user, params)
|
||||
records = user.administrator? ? Current.account.macros : Current.account.macros.global
|
||||
records = records.or(personal.where(created_by_id: user.id)) if user.agent?
|
||||
records.page(current_page(params))
|
||||
records
|
||||
records = Current.account.macros.global
|
||||
records = records.or(personal.where(created_by_id: user.id))
|
||||
records.order(:id).page(current_page(params))
|
||||
end
|
||||
|
||||
def self.current_page(params)
|
||||
|
||||
@@ -92,17 +92,13 @@ class User < ApplicationRecord
|
||||
has_many :team_members, dependent: :destroy_async
|
||||
has_many :teams, through: :team_members
|
||||
has_many :articles, foreign_key: 'author_id', dependent: :nullify
|
||||
has_many :portal_members,
|
||||
class_name: :PortalMember,
|
||||
dependent: :destroy_async
|
||||
has_many :portals,
|
||||
through: :portal_members,
|
||||
class_name: :Portal,
|
||||
dependent: :nullify,
|
||||
source: :portal
|
||||
has_many :macros, foreign_key: 'created_by_id', dependent: :destroy_async
|
||||
|
||||
has_many :portal_members, class_name: :PortalMember, dependent: :destroy_async
|
||||
has_many :portals, through: :portal_members, source: :portal,
|
||||
class_name: :Portal,
|
||||
dependent: :nullify
|
||||
has_many :macros, foreign_key: 'created_by_id'
|
||||
before_validation :set_password_and_uid, on: :create
|
||||
after_destroy :remove_macros
|
||||
|
||||
scope :order_by_full_name, -> { order('lower(name) ASC') }
|
||||
|
||||
@@ -205,4 +201,10 @@ class User < ApplicationRecord
|
||||
count: notifications.where(account_id: account_id).count
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_macros
|
||||
macros.personal.destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user