]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/agendav_plugin.rb
fc19d3d60fd45fccfec195ca745de1c0d7b5b3b5
[mailshears.git] / lib / common / agendav_plugin.rb
1 require 'common/plugin'
2 require 'common/user'
3
4 module AgendavPlugin
5 # Code that all Agendav plugins (Prune, Rm, Mv...) will
6 # share. That is, we implement the Plugin interface.
7 include Plugin
8
9
10 def initialize(cfg)
11 @db_host = cfg.agendav_dbhost
12 @db_port = cfg.agendav_dbport
13 @db_opts = cfg.agendav_dbopts
14 @db_tty = cfg.agendav_dbtty
15 @db_name = cfg.agendav_dbname
16 @db_user = cfg.agendav_dbuser
17 @db_pass = cfg.agendav_dbpass
18 end
19
20
21 def describe_domain(domain)
22 return domain.to_s()
23 end
24
25 def describe_user(user)
26 return user.to_s()
27 end
28
29
30 def list_users()
31 #
32 # Produce a list of AgenDAV users. This is public because it's
33 # useful in testing.
34 #
35 users = []
36
37 # Just assume PostgreSQL for now.
38 begin
39 connection = PGconn.connect(@db_host,
40 @db_port,
41 @db_opts,
42 @db_tty,
43 @db_name,
44 @db_user,
45 @db_pass)
46
47 sql_query = '(SELECT username FROM prefs)'
48 sql_query += 'UNION'
49 sql_query += '(SELECT user_from FROM shared);'
50
51 connection.query(sql_query) do |result|
52 users = result.field_values('username')
53 end
54
55 connection.close()
56 rescue PGError => e
57 # Pretend like we're database-agnostic in case we ever are.
58 raise DatabaseError.new(e)
59 end
60
61 return users.map{ |u| User.new(u) }
62 end
63
64 end