]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/davical.rb
Way too many changes to mention. The 'rm' mode works now.
[mailshears.git] / lib / rm / plugins / davical.rb
1 require 'pg'
2
3 require 'common/davical_plugin'
4 require 'rm/rm_plugin'
5
6 class DavicalRm
7 #
8 # DAViCal only supports Postgres, so even if we ever are
9 # database-agnostic, this plugin can't be.
10 #
11 include DavicalPlugin
12 include RmPlugin
13
14
15 def delete_domain(domain)
16 # DAViCal doesn't have a concept of domains.
17 end
18
19
20 def delete_account(account)
21 # Delete the given username. DAViCal uses foreign keys properly
22 # and only supports postgres, so we let the ON DELETE CASCADE
23 # trigger handle most of the work.
24 sql_queries = ['DELETE FROM usr WHERE username = $1']
25
26 begin
27 connection = PGconn.connect(@db_host,
28 @db_port,
29 @db_opts,
30 @db_tty,
31 @db_name,
32 @db_user,
33 @db_pass)
34
35 sql_queries.each do |sql_query|
36 connection.query(sql_query, [account])
37 end
38
39 connection.close()
40
41 rescue PGError => e
42 # Pretend like we're database-agnostic in case we ever are.
43 raise DatabaseError.new(e)
44 end
45
46 end
47
48
49
50 def get_domain_usernames(domain)
51 usernames = get_davical_usernames();
52 matches = usernames.select do |username|
53 username =~ /@#{domain}$/
54 end
55
56 return matches
57 end
58
59 end