Clean up user/domain describing in the plugins.
[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 # Just assume PostgreSQL for now.
29 begin
30 connection = PGconn.connect(@db_host,
31 @db_port,
32 @db_opts,
33 @db_tty,
34 @db_name,
35 @db_user,
36 @db_pass)
37
38 sql_query = '(SELECT username FROM prefs)'
39 sql_query += 'UNION'
40 sql_query += '(SELECT user_from FROM shared);'
41
42 connection.query(sql_query) do |result|
43 users = result.field_values('username')
44 end
45
46 connection.close()
47 rescue PGError => e
48 # Pretend like we're database-agnostic in case we ever are.
49 raise DatabaseError.new(e)
50 end
51
52 return users.map{ |u| User.new(u) }
53 end
54
55 end