]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/agendav.rb
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 mv_domain(from
, to
)
37 # AgenDAV doesn't have a concept of domains.
40 def mv_account(from
, to
)
41 sql_queries
= ['UPDATE prefs SET username = $1 WHERE username $2;']
42 sql_queries
<< 'UPDATE shared SET user_from = $1 WHERE user_from = $2;'
43 sql_queries
<< 'UPDATE shared SET user_which = $1 WHERE user_which = $2;'
46 connection
= PGconn
.connect(@db_host,
54 sql_queries
.each
do |sql_query
|
55 connection
.query(sql_query
, [to
, from
])
61 # Pretend like we're database-agnostic in case we ever are.
62 raise DatabaseError
.new(e
)
71 def user_exists(account
)
72 ad_users
= get_agendav_usernames()
73 return ad_users
.include?(account
)
76 def get_agendav_usernames()
79 # Just assume PostgreSQL for now.
81 connection
= PGconn
.connect(@db_host,
89 sql_query
= '(SELECT username FROM prefs)'
91 sql_query +
= '(SELECT user_from FROM shared);'
93 connection
.query(sql_query
) do |result
|
94 usernames
= result
.field_values('username')
99 # Pretend like we're database-agnostic in case we ever are.
100 raise DatabaseError
.new(e
)