Class: ServiceObjects::HandleChange

Inherits:
Base
  • Object
show all
Defined in:
lib/service_objects/handle_change.rb

Instance Attribute Summary

Attributes inherited from Base

#change

Instance Method Summary collapse

Methods inherited from Base

ignore?, #initialize

Constructor Details

This class inherits a constructor from ServiceObjects::Base

Instance Method Details

#callObject

TODO: handle changes to email address with appropriate renaming and aliasing TODO: limit to emails with @biola.edu domain


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/service_objects/handle_change.rb', line 5

def call
  actions = []

  begin
    unless AssignEmailAddress.ignore?(change)
      if assign_action = AssignEmailAddress.new(change).call
        Log.info "Assigning email address to person #{change.person_uuid}"
        actions << assign_action
      end
    end

    unless UpdateEmailAddress.ignore?(change)
      Log.info "Updating Google account email (#{change.university_email}) for person #{change.person_uuid}"
      actions << UpdateEmailAddress.new(change).call
    end

    unless SyncGoogleAccount.ignore?(change)
      Log.info "Syncing Google account #{change.university_email} for person #{change.person_uuid}"
      actions << SyncGoogleAccount.new(change).call
    end

    unless JoinGoogleGroup.ignore?(change)
      Log.info "Joining Google group(s) #{Whitelist.filter(change.joined_groups).to_sentence} for person #{change.person_uuid}"
      actions << JoinGoogleGroup.new(change).call
    end

    unless LeaveGoogleGroup.ignore?(change)
      Log.info "Leaving Google group(s) #{Whitelist.filter(change.left_groups).to_sentence} for person #{change.person_uuid}"
      actions << LeaveGoogleGroup.new(change).call
    end

    action = actions.first || :skip
    Log.info "No changes needed for person #{change.person_uuid}" if actions.empty?
    Workers::ChangeFinish.perform_async change.sync_log_id, action

  rescue StandardError => err
    Workers::ChangeError.perform_async change.sync_log_id, err.message
    Raven.capture_exception(err) if defined? Raven
    raise err
  end
end

#ignore?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/service_objects/handle_change.rb', line 47

def ignore?
  AssignEmailAddress.ignore?(change) && SyncGoogleAccount.ignore?(change) && UpdateEmailAddress.ignore?(change) && JoinGoogleGroup.ignore?(change) && LeaveGoogleGroup.ignore?(change)
end