Class: AccountUser

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveUUID::UUID
Defined in:
app/models/account_user.rb

Instance Method Summary collapse

Methods included from ActiveUUID::UUID

#fix_uuid_strings, included

Instance Method Details

#_destroyObject



15
# File 'app/models/account_user.rb', line 15

alias :_destroy :destroy

#add_default_rolesObject

Write tests for this



33
34
35
36
# File 'app/models/account_user.rb', line 33

def add_default_roles
  roles.create( { :name => APP_ROLES[ "owner_role" ] } )
  roles.create( { :name => APP_ROLES[ "admin_role" ] } ) if APP_ROLES[ "owner_role" ] != APP_ROLES[ "admin_role" ]
end

#cancel_destructionObject



28
29
30
# File 'app/models/account_user.rb', line 28

def cancel_destruction
  destruction_job.try(:destroy) unless destruction_job.try(:locked_at)
end

#destroyObject



16
17
18
# File 'app/models/account_user.rb', line 16

def destroy
  Delayed::Job.enqueue DestroyAccountUserJob.new(id.to_s), :queue => "account_user_#{id}_destroy", :run_at => DateTime.now + IuguSDK::
end

#destroying?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/account_user.rb', line 24

def destroying?
  !!destruction_job
end

#destruction_jobObject



20
21
22
# File 'app/models/account_user.rb', line 20

def destruction_job
  Delayed::Job.find_by_queue("account_user_#{id}_destroy")
end

#is?(role) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'app/models/account_user.rb', line 60

def is?(role)
  role = APP_ROLES[ "owner_role" ] if role.to_s == "owner"
  role = APP_ROLES[ "admin_role" ] if role.to_s == "admin"
  roles.exists?(:name => role)
end

#set_ownerObject



55
56
57
58
# File 'app/models/account_user.rb', line 55

def set_owner
  roles.create name: "owner"
  reload
end

#set_roles(new_roles) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/account_user.rb', line 38

def set_roles(new_roles)
  if new_roles.nil?
    roles.destroy_all
  else
    valid = true
    new_roles.each do |new_role|
      valid = false unless APP_ROLES['roles'].include? new_role
    end
    return false unless valid 
    roles.destroy_all
    new_roles.each do |new_role|
      roles.create( :name => new_role )
    end
  end
  true
end