]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/common/davical_plugin.rb
1 require 'common/plugin'
5 # Code that all Davical plugins (Prune, Rm, Mv...) will share. That
6 # is, we implement the Plugin interface.
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_user(user
)
21 principal_id
= self.get_principal_id(user
)
22 return "Principal ID: #{principal_id}"
28 # Produce a list of DAViCal users. This is public because it's
34 connection
= PGconn
.connect(@db_host,
42 # User #1 is the super-user, and not tied to an email address.
43 sql_query
= "SELECT username FROM usr WHERE user_no > 1"
45 connection
.query(sql_query
) do |result
|
46 usernames
= result
.field_values('username')
51 # Pretend like we're database-agnostic in case we ever are.
52 raise DatabaseError
.new(e
)
55 return usernames
.map
{ |u
| User
.new(u
) }
61 def get_principal_id(user
)
65 connection
= PGconn
.connect(@db_host,
73 sql_query
= "SELECT principal.principal_id "
74 sql_query +
= "FROM (principal INNER JOIN usr "
75 sql_query +
= " ON principal.user_no = usr.user_no) "
76 sql_query +
= "WHERE usr.username = $1;"
78 connection
.query(sql_query
, [user
.to_s()]) do |result
|
79 if result
.num_tuples
> 0
80 principal_id
= result
[0]['principal_id']
87 # Pretend like we're database-agnostic in case we ever are.
88 raise DatabaseError
.new(e
)