]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/davical.rb
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 delete_domain(domain
)
44 # DAViCal doesn't have a concept of domains.
48 def delete_account(account
)
49 # Delete the given username. DAViCal uses foreign keys properly
50 # and only supports postgres, so we let the ON DELETE CASCADE
51 # trigger handle most of the work.
52 sql_queries
= ['DELETE FROM usr WHERE username = $1']
55 connection
= PGconn
.connect(@db_host,
63 sql_queries
.each
do |sql_query
|
64 connection
.query(sql_query
, [account
])
70 # Pretend like we're database-agnostic in case we ever are.
71 raise DatabaseError
.new(e
)
77 def get_leftover_domains(db_domains
)
78 # AgenDAV doesn't have a concept of domains.
83 def get_leftover_accounts(db_accounts
)
84 # Get a list of all users who have logged in to DAViCal.
85 davical_accounts
= self.get_davical_usernames()
86 return davical_accounts
- db_accounts
92 def get_principal_id(account
)
96 connection
= PGconn
.connect(@db_host,
104 sql_query
= "SELECT principal.principal_id "
105 sql_query +
= "FROM (principal INNER JOIN usr "
106 sql_query +
= " ON principal.user_no = usr.user_no) "
107 sql_query +
= "WHERE usr.username = $1;"
109 connection
.query(sql_query
, [account
]) do |result
|
110 if result
.num_tuples
> 0
111 principal_id
= result
[0]['principal_id']
118 # Pretend like we're database-agnostic in case we ever are.
119 raise DatabaseError
.new(e
)
126 def get_davical_usernames()
130 connection
= PGconn
.connect(@db_host,
138 # User #1 is the super-user, and not tied to an email address.
139 sql_query
= 'SELECT username FROM usr WHERE user_no > 1;'
141 connection
.query(sql_query
) do |result
|
142 usernames
= result
.field_values('username')
147 # Pretend like we're database-agnostic in case we ever are.
148 raise DatabaseError
.new(e
)