]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/agendav.rb
7a594425816bcb894778cd42434fe7be5041db23
3 require 'common/plugin'
12 cfg
= Configuration
.new()
13 @db_host = cfg
.agendav_dbhost
14 @db_port = cfg
.agendav_dbport
15 @db_opts = cfg
.agendav_dbopts
16 @db_tty = cfg
.agendav_dbtty
17 @db_name = cfg
.agendav_dbname
18 @db_user = cfg
.agendav_dbuser
19 @db_pass = cfg
.agendav_dbpass
23 def describe_domain(domain
)
24 # AgenDAV doesn't have a concept of domains.
28 def describe_account(account
)
29 if self.user_exists(account
)
30 return "Username: #{account}"
32 return 'User not found'
36 def delete_domain(domain
)
37 # AgenDAV doesn't have a concept of domains.
40 def delete_account(account
)
41 # Delete the given username and any records in other tables
44 sql_queries
= ['DELETE FROM prefs WHERE username = $1;']
45 sql_queries
<< 'DELETE FROM shared WHERE user_from = $1;'
48 connection
= PGconn
.connect(@db_host,
56 sql_queries
.each
do |sql_query
|
57 connection
.query(sql_query
, [account
])
63 # Pretend like we're database-agnostic in case we ever are.
64 raise DatabaseError
.new(e
)
70 def get_leftover_domains(db_domains
)
71 # AgenDAV doesn't have a concept of domains.
76 def get_leftover_accounts(db_accounts
)
77 # Get a list of all users who have logged in to AgenDAV.
78 ad_accounts
= self.get_agendav_usernames()
79 return ad_accounts
- db_accounts
85 def user_exists(account
)
86 ad_users
= get_agendav_usernames()
87 return ad_users
.include?(account
)
90 def get_agendav_usernames()
93 # Just assume PostgreSQL for now.
95 connection
= PGconn
.connect(@db_host,
103 sql_query
= '(SELECT username FROM prefs)'
105 sql_query +
= '(SELECT user_from FROM shared);'
107 connection
.query(sql_query
) do |result
|
108 usernames
= result
.field_values('username')
113 # Pretend like we're database-agnostic in case we ever are.
114 raise DatabaseError
.new(e
)