Class: Decidim::UserPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper, TranslatableAttributes
Defined in:
decidim-core/app/presenters/decidim/user_presenter.rb

Overview

Decorator for users

Direct Known Subclasses

UserGroupPresenter

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#avatarObject



32
33
34
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 32

def avatar
  attached_uploader(:avatar)
end

#avatar_url(variant = nil) ⇒ Object



36
37
38
39
40
41
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 36

def avatar_url(variant = nil)
  return default_avatar_url if __getobj__.blocked?
  return default_avatar_url unless avatar.attached?

  avatar.path(variant:)
end

#badgeObject



20
21
22
23
24
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 20

def badge
  return "" unless officialized?

  "verified-badge"
end

#can_be_contacted?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 63

def can_be_contacted?
  true unless blocked?
end

#can_follow?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 72

def can_follow?
  true
end

#default_avatar_urlObject



43
44
45
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 43

def default_avatar_url
  avatar.default_url
end

#direct_messages_enabled?(context) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 53

def direct_messages_enabled?(context)
  return false unless __getobj__.respond_to?(:accepts_conversation?)

  __getobj__.accepts_conversation?(context[:current_user])
end

#display_mentionObject



59
60
61
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 59

def display_mention
  link_to nickname, profile_url, data: { "external-link": false }
end

#has_tooltip?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 76

def has_tooltip?
  return if respond_to?(:deleted?) && deleted?

  true
end

#nicknameObject

nickname presented in a twitter-like style



14
15
16
17
18
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 14

def nickname
  return "" if __getobj__.blocked?

  "@#{__getobj__.nickname}"
end

#officialization_textObject



67
68
69
70
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 67

def officialization_text
  translated_attribute(officialized_as).presence ||
    I18n.t("decidim.profiles.default_officialization_text_for_users")
end

#profile_pathObject



47
48
49
50
51
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 47

def profile_path
  return "" if respond_to?(:deleted?) && deleted?

  decidim.profile_path(__getobj__.nickname)
end

#profile_urlObject



26
27
28
29
30
# File 'decidim-core/app/presenters/decidim/user_presenter.rb', line 26

def profile_url
  return "" if respond_to?(:deleted?) && deleted?

  decidim.profile_url(__getobj__.nickname)
end