Sha256: fa372d23c518566a9a0dd1f50bd6174837ee289cac6105277fc3494b05c398df

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

class CamaleonCms::UserDecorator < CamaleonCms::ApplicationDecorator
  include CamaleonCms::CustomFieldsConcern
  delegate_all

  # return the identifier
  def the_username
    object.username
  end

  # return the fullname
  def the_name
    object.fullname
  end

  # return the role title of this user for current site
  def the_role
    object.get_role(h.current_site).name.titleize
  end

  # return the avatar for this user, default: assets/admin/img/no_image.jpg
  def the_avatar(default_avatar = nil)
    avatar_exists? ? object.get_meta("avatar") : (default_avatar || h.asset_url("camaleon_cms/admin/img/no_image.jpg"))
  end

  # return the slogan for this user, default: Hello World
  def the_slogan
    object.get_meta("slogan", "Hello World")
  end

  # return front url for this user
  def the_url(*args)
    args = args.extract_options!
    args[:user_id] = the_id
    args[:user_name] = the_name.parameterize
    args[:user_name] = the_username unless args[:user_name].present?
    args[:locale] = get_locale unless args.include?(:locale)
    args[:format] = "html"
    as_path = args.delete(:as_path)
    h.cama_url_to_fixed("cama_profile_#{as_path.present? ? "path" : "url"}", args)
  end

  # return the url for the profile in the admin module
  def the_admin_profile_url
    h.cama_admin_profile_url(object.id)
  end

  # return all contents created by this user in current site
  def the_contents
    h.current_site.posts.where(user_id: object.id)
  end

  private

  def avatar_exists?
    # TODO change verification
    # if object.get_meta('avatar').present?
    #   File.exist?(h.cama_url_to_file_path(object.get_meta('avatar'))) || Faraday.head(object.get_meta('avatar')).status == 200
    # else
    #   false
    # end
    object.get_meta('avatar').present?
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
camaleon_cms-2.3.3 app/decorators/camaleon_cms/user_decorator.rb
camaleon_cms-2.3.2 app/decorators/camaleon_cms/user_decorator.rb
camaleon_cms-2.3.1 app/decorators/camaleon_cms/user_decorator.rb
camaleon_cms-2.3.0 app/decorators/camaleon_cms/user_decorator.rb