Sha256: 40e32d3c16656c60c3119a3b92718b0e8894da981ad96ed7d9cc32f83d37c31f

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

require "digest/md5"
require "cgi"
require "gds-sso/user"
require "workflow_actor"
require "safe_html"

class User
  include Mongoid::Document
  include Mongoid::Timestamps
  include GDS::SSO::User
  include WorkflowActor

  # Let an app configure the collection name to use, e.g. set a constant in an
  # initializer
  def self.collection_name
    defined?(USER_COLLECTION_NAME) ? USER_COLLECTION_NAME : "users"
  end

  field "name",                type: String
  field "uid",                 type: String
  field "version",             type: Integer
  field "email",               type: String
  field "permissions",         type: Array
  field "remotely_signed_out", type: Boolean, default: false
  
  GOVSPEAK_FIELDS = []

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :name, :uid
  attr_accessible :email, :name, :uid, :permissions, as: :oauth

  scope :alphabetized, order_by(name: :asc)

  validates_with SafeHtml

  # GDS::SSO specifically looks for find_by_uid within warden
  # when loading authentication user from session
  def self.find_by_uid(uid)
    where(uid: uid).first
  end

  def to_s
    name || email || ""
  end

  def gravatar_url(opts = {})
    opts.symbolize_keys!
    "%s.gravatar.com/avatar/%s%s" % [
      opts[:ssl] ? "https://secure" : "http://www",
      Digest::MD5.hexdigest(email.downcase),
      opts[:s] ? "?s=#{CGI.escape(opts[:s])}" : ""
    ]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
govuk_content_models-6.0.6 app/models/user.rb
govuk_content_models-6.0.5 app/models/user.rb
govuk_content_models-6.0.4 app/models/user.rb
govuk_content_models-6.0.3 app/models/user.rb
govuk_content_models-6.0.2 app/models/user.rb