9af7b01519b40aca2870176948ed4f0ac6f950cb
[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 list_users()
22 #
23 # Produce a list of AgenDAV users. This is public because it's
24 # useful in testing.
25 #
26 users = []
27
28 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
29 @db_name, @db_user, @db_pass)
30
31 sql_query = '(SELECT username FROM prefs)'
32 sql_query += 'UNION'
33 sql_query += '(SELECT user_from FROM shared);'
34
35 connection.query(sql_query) do |result|
36 users = result.field_values('username')
37 end
38
39 connection.close()
40
41 return users.map{ |u| User.new(u) }
42 end
43
44 end