Class: Decidim::UserBaseEntity
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::UserBaseEntity
- Includes:
- Followable, HasUploadValidations, Loggable, Nicknamizable, Resourceable
- Defined in:
- 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(?!.*[<>?%&\^*#@()\[\]=+:;"{}\\|])/
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
Instance Method Details
#followings_blocked? ⇒ Boolean
64 65 66 |
# File '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 '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 '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 'app/models/decidim/user_base_entity.rb', line 60 def users_followings @users_followings ||= Decidim::UserBaseEntity.joins(:follows).where(decidim_follows: { user: self }) end |