Class: Decidim::UserBaseEntity

Inherits:
ApplicationRecord show all
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.

Direct Known Subclasses

User, UserGroup

Constant Summary collapse

REGEXP_NAME =

Regex for name & nickname format validations

/\A(?!.*[<>?%&\^*#@()\[\]=+:;"{}\\|])/.freeze

Instance Method Summary collapse

Methods included from HasUploadValidations

#attached_uploader, #maximum_avatar_size, #maximum_upload_size

Methods included from Followable

#followers

Instance Method Details

#public_followingsObject

Public: Returns a collection with all the public entities this user is following.

This can’t be done as with a ‘has_many :following, through: :following_follows` since it’s a polymorphic relation and Rails doesn’t 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



35
36
37
38
39
40
41
42
43
# File 'app/models/decidim/user_base_entity.rb', line 35

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