]>
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 @db_host = cfg
.davical_dbhost
10 @db_port = cfg
.davical_dbport
11 @db_opts = cfg
.davical_dbopts
12 @db_tty = cfg
.davical_dbtty
13 @db_name = cfg
.davical_dbname
14 @db_user = cfg
.davical_dbuser
15 @db_pass = cfg
.davical_dbpass
19 def describe_domain(domain
)
20 # DAViCal doesn't have a concept of domains.
25 def describe_user(user
)
26 principal_id
= self.get_principal_id(user
)
29 return 'User not found'
31 return "Principal ID: #{principal_id}"
38 # Produce a list of DAViCal users. This is public because it's
44 connection
= PGconn
.connect(@db_host,
52 # User #1 is the super-user, and not tied to an email address.
53 sql_query
= "SELECT username FROM usr WHERE user_no > 1"
55 connection
.query(sql_query
) do |result
|
56 usernames
= result
.field_values('username')
61 # Pretend like we're database-agnostic in case we ever are.
62 raise DatabaseError
.new(e
)
71 def get_principal_id(user
)
75 connection
= PGconn
.connect(@db_host,
83 sql_query
= "SELECT principal.principal_id "
84 sql_query +
= "FROM (principal INNER JOIN usr "
85 sql_query +
= " ON principal.user_no = usr.user_no) "
86 sql_query +
= "WHERE usr.username = $1;"
88 connection
.query(sql_query
, [user
]) do |result
|
89 if result
.num_tuples
> 0
90 principal_id
= result
[0]['principal_id']
97 # Pretend like we're database-agnostic in case we ever are.
98 raise DatabaseError
.new(e
)