Class: FatFreeCRM::Cloudfuji::EventObservers::UserObserver

Inherits:
Cloudfuji::EventObserver
  • Object
show all
Includes:
Base
Defined in:
lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb

Instance Method Summary collapse

Methods included from Base

#find_lead_by_data, #find_or_create_activity_subject!

Instance Method Details

#user_addedObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb', line 7

def user_added
  data = params['data']
  ido_id = data['ido_id'].to_s

  puts "Adding a new user with incoming data #{params.inspect}"
  puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="
  puts "Setting username to: #{ido_id}"

  user = User.unscoped.find_or_create_by_ido_id(ido_id)

  user.email      = data['email']
  user.first_name = user.email.split('@').first
  user.last_name  = user.email.split('@').last
  user.username   = data['email']
  user.deleted_at = nil
  user.send("#{::Authlogic::Cas.cas_username_column}=".to_sym, ido_id)

  puts user.inspect

  user.save!
end

#user_removedObject



29
30
31
32
33
34
35
36
37
# File 'lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb', line 29

def user_removed
  puts "Removing user based on incoming data #{params.inspect}"
  puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="

  user = User.unscoped.find_by_ido_id(params['data']['ido_id'])

  # TODO: Disable the user instead of destroying them (to prevent data loss)
  user.try(:destroy)
end

#user_updatedObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb', line 39

def user_updated
  puts "Updating user based on incoming data #{params.inspect}"
  puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="

  data = params['data']
  user = User.unscoped.find_by_ido_id(data['ido_id'])

  if user
    # Re-use the CAS login method to set all the extra attributes we
    # care about (first_name, last_name, email, local, timezone,
    # etc.)
    user.cloudfuji_extra_attributes(data)
    user.save
  end
end