Class: InvitationRepl

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
src/ruby/invitation-repl.rb

Class Method Summary collapse

Class Method Details

.perform_update(which) ⇒ Object



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'src/ruby/invitation-repl.rb', line 18

def self.perform_update(which)
    # send event invites
    rows = @@neo4j.neo4j_query(<<~END_OF_QUERY).map { |x| {:eid => x['eid'], :email => x['email'], :name => x['name'], :org_email => x['org_email'] } }
        MATCH (u)-[rt:IS_PARTICIPANT]->(e:Event)-[:ORGANIZED_BY]->(ou:User)
        WHERE (u:ExternalUser OR u:PredefinedExternalUser) AND rt.invitation_requested = true AND COALESCE(rt.deleted, false) = false AND COALESCE(e.deleted, false) = false
        RETURN e.id AS eid, u.email AS email, u.name AS name, ou.email AS org_email
    END_OF_QUERY

    if rows.size > 0
        STDERR.puts ">>> Sending #{rows.size} event invites!"
        STDERR.puts '-' * 59
        rows.each.with_index do |row, i|
            # send invitation mail
            STDERR.puts ">>> Sending invite #{i + 1} of #{rows.size}..."
            STDERR.puts '-' * 59
            Main.invite_external_user_for_event(row[:eid], row[:email], row[:org_email])
            sleep 10.0
            # wait for 10 seconds
        end
    end
    
    # send poll run invites
    rows = @@neo4j.neo4j_query(<<~END_OF_QUERY).map { |x| {:prid => x['prid'], :email => x['email'], :name => x['name'], :org_email => x['org_email'] } }
        MATCH (u)-[rt:IS_PARTICIPANT]->(pr:PollRun)-[:RUNS]->(p:Poll)-[:ORGANIZED_BY]->(ou:User)
        WHERE (u:ExternalUser OR u:PredefinedExternalUser) AND rt.invitation_requested = true AND COALESCE(rt.deleted, false) = false AND COALESCE(pr.deleted, false) = false AND COALESCE(p.deleted, false) = false
        RETURN pr.id AS prid, u.email AS email, u.name AS name, ou.email AS org_email
    END_OF_QUERY

    if rows.size > 0
        STDERR.puts ">>> Sending #{rows.size} poll run invites!"
        STDERR.puts '-' * 59
        rows.each.with_index do |row, i|
            # send invitation mail
            STDERR.puts ">>> Sending invite #{i + 1} of #{rows.size}..."
            STDERR.puts '-' * 59
            Main.invite_external_user_for_poll_run(row[:prid], row[:email], row[:org_email])
            unless DEVELOPMENT
                sleep 1.0
            end
            # wait for 10 seconds
        end
    end
end