]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/davical_plugin.rb
1 require 'common/plugin'
4 # Code that all Davical plugins (Prune, Rm, Mv...) will share. That
5 # is, we implement the Plugin interface.
9 cfg
= Configuration
.new()
10 @db_host = cfg
.davical_dbhost
11 @db_port = cfg
.davical_dbport
12 @db_opts = cfg
.davical_dbopts
13 @db_tty = cfg
.davical_dbtty
14 @db_name = cfg
.davical_dbname
15 @db_user = cfg
.davical_dbuser
16 @db_pass = cfg
.davical_dbpass
20 def describe_domain(domain
)
21 # DAViCal doesn't have a concept of domains.
26 def describe_account(account
)
27 principal_id
= self.get_principal_id(account
)
30 return 'User not found'
32 return "Principal ID: #{principal_id}"
39 def get_principal_id(account
)
43 connection
= PGconn
.connect(@db_host,
51 sql_query
= "SELECT principal.principal_id "
52 sql_query +
= "FROM (principal INNER JOIN usr "
53 sql_query +
= " ON principal.user_no = usr.user_no) "
54 sql_query +
= "WHERE usr.username = $1;"
56 connection
.query(sql_query
, [account
]) do |result
|
57 if result
.num_tuples
> 0
58 principal_id
= result
[0]['principal_id']
65 # Pretend like we're database-agnostic in case we ever are.
66 raise DatabaseError
.new(e
)
77 connection
= PGconn
.connect(@db_host,
85 # User #1 is the super-user, and not tied to an email address.
86 sql_query
= "SELECT username FROM usr WHERE user_no > 1"
88 connection
.query(sql_query
) do |result
|
89 usernames
= result
.field_values('username')
94 # Pretend like we're database-agnostic in case we ever are.
95 raise DatabaseError
.new(e
)