Class: Decidim::UserBaseEntity
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::UserBaseEntity
- Includes:
- Followable, HasUploadValidations, Loggable, Nicknamizable, Resourceable
- Defined in:
- decidim-core/app/models/decidim/user_base_entity.rb
Overview
This class serves as a base class for ‘Decidim::User` and `Decidim::UserGroup` so that we can set some shared logic. This class is not supposed to be used directly.
Constant Summary collapse
- REGEXP_NAME =
Regex for name & nickname format validations
/\A(?!.*[<>?%&\^*#@()\[\]=+:;"{}\\|])/
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #followings_blocked? ⇒ Boolean
-
#public_followings ⇒ Object
Public: Returns a collection with all the public entities this user is following.
- #public_users_followings ⇒ Object
- #users_followings ⇒ Object
Methods included from HasUploadValidations
#attached_uploader, #maximum_avatar_size, #maximum_upload_size
Methods included from Followable
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
76 77 78 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 76 def self.ransackable_associations(_auth_object = nil) [] end |
.ransackable_attributes(auth_object = nil) ⇒ Object
68 69 70 71 72 73 74 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 68 def self.ransackable_attributes(auth_object = nil) base = %w(name email nickname last_sign_in_at) return base unless auth_object&.admin? base + %w(invitation_sent_at invitation_accepted_at officialized_at) end |
Instance Method Details
#followings_blocked? ⇒ Boolean
64 65 66 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 64 def followings_blocked? Decidim::UserBaseEntity.joins(:follows).where(decidim_follows: { user: self }).blocked.exists? end |
#public_followings ⇒ Object
Public: Returns a collection with all the public entities this user is following.
This cannot be done as with a ‘has_many :following, through: :following_follows` since it is a polymorphic relation and Rails does not know how to load it. With this implementation we only query the database once for each kind of following.
Returns an Array of Decidim::Followable
44 45 46 47 48 49 50 51 52 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 44 def public_followings @public_followings ||= following_follows.select("array_agg(decidim_followable_id)") .group(:decidim_followable_type) .pluck(:decidim_followable_type, "array_agg(decidim_followable_id)") .to_h .flat_map do |type, ids| only_public(type.constantize, ids) end end |
#public_users_followings ⇒ Object
54 55 56 57 58 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 54 def public_users_followings # To include users and groups self.class is not valid because for a user # self.class.joins(:follows)... only return users @public_users_followings ||= users_followings.not_blocked end |
#users_followings ⇒ Object
60 61 62 |
# File 'decidim-core/app/models/decidim/user_base_entity.rb', line 60 def users_followings @users_followings ||= Decidim::UserBaseEntity.joins(:follows).where(decidim_follows: { user: self }) end |