]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/agendav_plugin.rb
Rename PostfixadminDb, RoundcubeDb without the Db suffix.
[mailshears.git] / lib / common / agendav_plugin.rb
1 require 'common/plugin'
2
3 module AgendavPlugin
4 # Code that all Agendav plugins (Prune, Rm, Mv...) will
5 # share. That is, we implement the Plugin interface.
6 include Plugin
7
8
9 def initialize()
10 cfg = Configuration.new()
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 # AgenDAV doesn't have a concept of domains.
23 return domain
24 end
25
26
27 def describe_account(account)
28 if self.user_exists(account)
29 return "Username: #{account}"
30 else
31 return 'User not found'
32 end
33 end
34
35
36 protected;
37
38
39 def list_users()
40 usernames = []
41
42 # Just assume PostgreSQL for now.
43 begin
44 connection = PGconn.connect(@db_host,
45 @db_port,
46 @db_opts,
47 @db_tty,
48 @db_name,
49 @db_user,
50 @db_pass)
51
52 sql_query = '(SELECT username FROM prefs)'
53 sql_query += 'UNION'
54 sql_query += '(SELECT user_from FROM shared);'
55
56 connection.query(sql_query) do |result|
57 usernames = result.field_values('username')
58 end
59
60 connection.close()
61 rescue PGError => e
62 # Pretend like we're database-agnostic in case we ever are.
63 raise DatabaseError.new(e)
64 end
65
66 return usernames
67 end
68
69 end