]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/agendav.rb
3 require 'common/agendav_plugin'
7 # Handle the removal of Agendav users from its database. Agendav has
8 # no concept of domains.
16 # Remove *user* from the Agendav database. This should remove him
17 # from _every_ table in which he is referenced.
19 # @param user [User] the user to remove.
22 raise NonexistentUserError
.new(user
.to_s()) if not user_exists(user
)
24 sql_queries
= ['DELETE FROM prefs WHERE username = $1;']
26 # The "shares" table contains principal URLs, and the "@" symbol
27 # is usually encoded to "%40". These queries do a regex match on
28 # the username after replacing the "%40" with a "@".
30 # As a precaution, I haven chosen not to delete based on the
31 # "calendar" field here. Nobody should have a calendar named
32 # "user%40example.com", but it's not impossible -- and we don't
33 # want to delete that calendar when the not-necessarily-related
34 # "user@example.com" account is removed. And the usual appearance
35 # of the user's email address in the "calendar" field happens when
36 # he is also the owner, so the calendar does get deleted in the
38 sql_queries
<< "DELETE FROM shares WHERE REPLACE(owner, '%40', '@') ~ $1;"
39 sql_queries
<< "DELETE FROM shares WHERE REPLACE(with, '%40', '@') ~ $1;"
41 connection
= PG
::Connection.new(@db_hash)
43 sql_queries
.each
do |sql_query
|
44 connection
.query(sql_query
, [user
.to_s()])
47 # Make sure the connection gets closed even if a query explodes.