Sha256: 4079019bd7f1864e857a25609954be0af4fd3b484ee14136232cdda4bc81901d

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

require 'commands/init/init_model'

module Commands
  module Init

    class UserModel < InitModel
      inheritable_attributes :login, :full_name, :password, :email, :super

      @login = nil
      @full_name = nil
      @password = nil
      @email = nil
      # Set this to true if you want the user to be our 'super user'. We'll
      # generally need one of these for each init step. We will make sure a
      # protections entry for this user exists
      @super = false

      #========================================================================
      # Internal implementation - don't mess with this
      #========================================================================

      def self.abstract
        true
      end

      attr_accessor :login, :password

      def initialize
        @login = self.class.login
        @full_name = self.class.full_name
        @password = self.class.password
        @email = self.class.email
        @super = self.class.super
      end

      def email
        @email || "#{login}@example.com"
      end

      def full_name
        @full_name || login
      end

      def super?
        @super
      end

      def to_s
        "UserModel: login=#{login} email=#{email} full_name=#{full_name} password=#{password}"
      end

      def to_spec
        spec = {
            'User' => login,
            'Email' => email,
            'FullName' => full_name
        }
        spec
      end

      def execute(p4, models=nil, super_user=nil)
        p4.save_user(to_spec, '-f')

        p4.user = login
        p4.password = ''

        p4.run_password('', password) if password

        if super_user
          p4.user = super_user.login
          p4.password = super_user.password
        end
      end
    end

    class DefaultSuperUser < UserModel
      @login = 'p4super'
      @password = 'superuser1A!'
      @full_name = 'Super User'
      @super = true
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
p4util-0.1.1 ./lib/commands/init/user_model.rb
p4util-0.1.0 ./lib/commands/init/user_model.rb