Sha256: 7a69fd146a5cdabaae8cc84416f8b4198c37d59cb287b4455938661655a09fe5

Contents?: true

Size: 677 Bytes

Versions: 3

Compression:

Stored size: 677 Bytes

Contents

module Panda
  module CMS
    class User < ApplicationRecord
      validates :firstname, presence: true
      validates :lastname, presence: true
      validates :email, presence: true, uniqueness: true

      before_save :downcase_email

      scope :admin, -> { where(admin: true) }

      def is_admin?
        admin
      end

      def name
        "#{firstname} #{lastname}"
      end

      def self.for_select_list(scope = :all, order = {firstname: :asc, lastname: :asc})
        Panda::CMS::User.send(scope).order(order).map { |u| [u.name, u.id] }
      end

      private

      def downcase_email
        self.email = email.to_s.downcase
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
panda-cms-0.7.3 app/models/panda/cms/user.rb
panda-cms-0.7.2 app/models/panda/cms/user.rb
panda-cms-0.7.0 app/models/panda/cms/user.rb