Module: Account::UsersHelper

Defined in:
app/helpers/account/users_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_membershipObject



102
103
104
# File 'app/helpers/account/users_helper.rb', line 102

def current_membership
  current_user.memberships.where(team: current_team).first
end

#get_photo_url_from(resource) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/account/users_helper.rb', line 76

def get_photo_url_from(resource)
  photo_method = if resource.is_a?(User)
    :profile_photo
  elsif resource.is_a?(Membership)
    :user_profile_photo
  end

  if cloudinary_enabled?
    resource.send(:"#{photo_method}_id")
  elsif resource.send(photo_method).attached?
    url_for(resource.send(photo_method))
  end
end

#membership_profile_header_photo_url(membership) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/account/users_helper.rb', line 63

def membership_profile_header_photo_url(membership)
  if membership.user
    (membership.user)
  else
    profile_header_photo_for(
      url: get_photo_url_from(membership),
      email: membership.invitation&.email || membership.user_email,
      first_name: membership.user_first_name,
      last_name: membership.user&.last_name || membership.user_last_name
    )
  end
end

#membership_profile_photo_url(membership) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/account/users_helper.rb', line 29

def membership_profile_photo_url(membership)
  if membership.user
    (membership.user)
  else
    profile_photo_for(
      url: get_photo_url_from(membership),
      email: membership.invitation&.email || membership.user_email,
      first_name: membership.user_first_name,
      last_name: membership.user_last_name
    )
  end
end

#photo_url_for_active_storage_attachment(attachment, options) ⇒ Object



2
3
4
5
# File 'app/helpers/account/users_helper.rb', line 2

def photo_url_for_active_storage_attachment attachment, options
  size_details = {resize_to_limit: [options[:width], options[:height]]}
  attachment.representation(size_details)
end

#profile_header_photo_for(url: nil, email: nil, first_name: nil, last_name: nil) ⇒ Object

TODO: We can do away with these three ‘profile_header` methods, I’m just leaving them in case we have other developers depending on these methods.



44
45
46
47
48
49
50
51
52
# File 'app/helpers/account/users_helper.rb', line 44

def profile_header_photo_for(url: nil, email: nil, first_name: nil, last_name: nil)
  if cloudinary_enabled? && !url.blank?
    cl_image_path(url, {width: 700, height: 200, crop: :fill})
  elsif !url.blank?
    url + "?" + {size: 200}.to_param
  else
    ui_avatar_params(email, first_name, last_name)
  end
end

#profile_photo_for(url: nil, email: nil, first_name: nil, last_name: nil, profile_header: false) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/account/users_helper.rb', line 7

def profile_photo_for(url: nil, email: nil, first_name: nil, last_name: nil, profile_header: false)
  size_details = profile_header ? {width: 700, height: 200} : {width: 100, height: 100}
  size_details[:crop] = :fill

  if cloudinary_enabled? && !url.blank?
    cl_image_path(url, size_details)
  elsif !url.blank?
    url + "?" + size_details.to_param
  else
    ui_avatar_params(email, first_name, last_name)
  end
end

#ui_avatar_params(email, first_name, last_name) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/account/users_helper.rb', line 90

def ui_avatar_params(email, first_name, last_name)
  background_color = Colorizer.colorize_similarly(email.to_s, 0.5, 0.6).delete("#")
  "https://ui-avatars.com/api/?" + {
    color: "ffffff",
    background: background_color,
    bold: true,
    # email.to_s should not be necessary once we fix the edge case of cancelling an unclaimed membership
    name: "#{first_name&.first || email.to_s[0]} #{last_name&.first || email.to_s[1]}",
    size: 200,
  }.to_param
end

#user_profile_header_photo_url(user) ⇒ Object



54
55
56
57
58
59
60
61
# File 'app/helpers/account/users_helper.rb', line 54

def (user)
  profile_header_photo_for(
    url: get_photo_url_from(user),
    email: user.email,
    first_name: user.first_name,
    last_name: user.last_name
  )
end

#user_profile_photo_url(user) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/helpers/account/users_helper.rb', line 20

def (user)
  profile_photo_for(
    url: get_photo_url_from(user),
    email: user.email,
    first_name: user.first_name,
    last_name: user.last_name
  )
end