Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
j_platform / app / models / concerns / j_platform / user_concern.rb
Size: Mime:
module JPlatform
  module UserConcern
    extend ActiveSupport::Concern
    include PlatformConcern

    included do
      schema do
        string :first_name, :last_name, :email, :status, :role, :preferred_timezone, :current_password, :password
        integer :organization_id
      end
      attr_accessor :current_password

      validates :first_name, :last_name, format: { with: /\A^[^0-9`!@#\$%\^&*+_={}\[\];:<>~?\/|]+$\z/, message: :letters_only }
      validates :first_name, :last_name, presence: true
      validates :first_name, :last_name, length: { maximum: 128 }
      validates :email, presence: true
      validates :email, format: { with: /\A(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})\z/i, message: I18n.t('messages.error.email') }

      belongs_to :organization, class_name: "#{@module_name}::Organization"
      has_many :clients, class_name: "#{@module_name}::Client"
      has_many :client_memberships, class_name: "#{@module_name}::ClientMembership"
      has_many :projects, class_name: "#{@module_name}::Project"
    end

    module ClassMethods
      def me
        find('me')
      end
    end

    def is_any_client_admin
      self.clients.map(&:admin_ids).flatten.include?(self.id)
    end

    def full_name
      [self.first_name, self.last_name].join(' ')
    end
    alias_method :to_s, :full_name

    %w{member org_admin super_admin}.each do |role_type|
      define_method("#{role_type}?") do
        self.role == role_type
      end
    end

    def active?
      self.status == "active"
    end
    alias_method :is_active_status, :active?

  end
end