]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/davical.rb
860abdc3765a2e0b47dd08c244ca0a8b3fa1f38a
3 require 'common/plugin'
8 # DAViCal only supports Postgres, so even if we ever are
9 # database-agnostic, this plugin can't be.
15 cfg
= Configuration
.new()
16 @db_host = cfg
.davical_dbhost
17 @db_port = cfg
.davical_dbport
18 @db_opts = cfg
.davical_dbopts
19 @db_tty = cfg
.davical_dbtty
20 @db_name = cfg
.davical_dbname
21 @db_user = cfg
.davical_dbuser
22 @db_pass = cfg
.davical_dbpass
26 def describe_domain(domain
)
27 # DAViCal doesn't have a concept of domains.
32 def describe_account(account
)
33 principal_id
= self.get_principal_id(account
)
36 return 'User not found'
38 return "Principal ID: #{principal_id}"
43 def mv_domain(from
, to
)
44 # DAViCal doesn't have a concept of domains.
48 def mv_account(from
, to
)
49 # Delete the given username. DAViCal uses foreign keys properly
50 # and only supports postgres, so we let the ON UPDATE CASCADE
51 # trigger handle most of the work.
52 sql_queries
= ['UPDATE usr SET username = $1 WHERE username = $2']
55 connection
= PGconn
.connect(@db_host,
63 sql_queries
.each
do |sql_query
|
64 connection
.query(sql_query
, [to
, from
])
70 # Pretend like we're database-agnostic in case we ever are.
71 raise DatabaseError
.new(e
)
79 def get_principal_id(account
)
83 connection
= PGconn
.connect(@db_host,
91 sql_query
= "SELECT principal.principal_id "
92 sql_query +
= "FROM (principal INNER JOIN usr "
93 sql_query +
= " ON principal.user_no = usr.user_no) "
94 sql_query +
= "WHERE usr.username = $1;"
96 connection
.query(sql_query
, [account
]) do |result
|
97 if result
.num_tuples
> 0
98 principal_id
= result
[0]['principal_id']
105 # Pretend like we're database-agnostic in case we ever are.
106 raise DatabaseError
.new(e
)