]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mailshears/plugins/agendav.rb
8 cfg
= Configuration
.new()
9 @db_host = cfg
.agendav_dbhost
10 @db_port = cfg
.agendav_dbport
11 @db_opts = cfg
.agendav_dbopts
12 @db_tty = cfg
.agendav_dbtty
13 @db_name = cfg
.agendav_dbname
14 @db_user = cfg
.agendav_dbuser
15 @db_pass = cfg
.agendav_dbpass
19 def describe_domain(domain
)
20 # AgenDAV doesn't have a concept of domains.
24 def describe_account(account
)
25 if self.user_exists(account
)
26 return "Username: #{account}"
28 return 'User not found'
32 def delete_domain(domain
)
33 # AgenDAV doesn't have a concept of domains.
36 def delete_account(account
)
37 # Delete the given username and any records in other tables
40 sql_queries
= ['DELETE FROM prefs WHERE username = $1;']
41 sql_queries
<< 'DELETE FROM shared WHERE user_from = $1;'
44 connection
= PGconn
.connect(@db_host,
52 sql_queries
.each
do |sql_query
|
53 connection
.query(sql_query
, [account
])
59 # Pretend like we're database-agnostic in case we ever are.
60 raise DatabaseError
.new(e
)
66 def get_leftover_domains(db_domains
)
67 # AgenDAV doesn't have a concept of domains.
72 def get_leftover_accounts(db_accounts
)
73 # Get a list of all users who have logged in to AgenDAV.
74 ad_accounts
= self.get_agendav_usernames()
75 return ad_accounts
- db_accounts
81 def user_exists(account
)
82 ad_users
= get_agendav_usernames()
83 return ad_users
.include?(account
)
86 def get_agendav_usernames()
89 # Just assume PostgreSQL for now.
91 connection
= PGconn
.connect(@db_host,
99 sql_query
= '(SELECT username FROM prefs)'
101 sql_query +
= '(SELECT user_from FROM shared);'
103 connection
.query(sql_query
) do |result
|
104 usernames
= result
.field_values('username')
109 # Pretend like we're database-agnostic in case we ever are.
110 raise DatabaseError
.new(e
)