]>
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 # We do not raise an error if the user doesn't exist. This is due to
20 # an unfortunate problem with the "user exists" check in AgenDAV.
21 # The AgenDAV "shares" table is not tied directly to a username, so
22 # we are forced to use a regexp match to decide what rows to delete
23 # from that table. We do so regardless of whether or not the username
24 # exists in the "prefs" table, because that table stores only non-
25 # default preferences -- not all users' preferences.
27 # @param user [User] the user to remove.
30 sql_queries
= ['DELETE FROM prefs WHERE username = $1;']
32 # The "shares" table contains principal URLs, and the "@" symbol
33 # is usually encoded to "%40". These queries do a regex match on
34 # the username after replacing the "%40" with a "@".
36 # As a precaution, I haven chosen not to delete based on the
37 # "calendar" field here. Nobody should have a calendar named
38 # "user%40example.com", but it's not impossible -- and we don't
39 # want to delete that calendar when the not-necessarily-related
40 # "user@example.com" account is removed. And the usual appearance
41 # of the user's email address in the "calendar" field happens when
42 # he is also the owner, so the calendar does get deleted in the
44 sql_queries
<< "DELETE FROM shares WHERE REPLACE(owner,'%40','@') ~ $1;"
45 sql_queries
<< "DELETE FROM shares WHERE REPLACE(\"with\",'%40','@') ~ $1;"
47 connection
= PG
::Connection.new(@db_hash)
49 sql_queries
.each
do |sql_query
|
50 connection
.query(sql_query
, [user
.to_s()])
53 # Make sure the connection gets closed even if a query explodes.