Class: AgendavRm

Inherits:
Object
  • Object
show all
Includes:
AgendavPlugin, RmPlugin
Defined in:
lib/rm/plugins/agendav.rb

Overview

Handle the removal of Agendav users from its database. Agendav has no concept of domains.

Direct Known Subclasses

AgendavPrune

Instance Method Summary collapse

Methods included from RmPlugin

dummy_runner, #remove, #remove_domain, runner

Methods included from Plugin::Run

#dummy_runner, #included, #includers, #run, #runner

Methods included from AgendavPlugin

#count_shares, #initialize, #list_users

Methods included from Plugin

#describe, #describe_domain, #describe_user, #domain_exists, #list_domains, #list_domains_users, #list_users, #user_exists

Instance Method Details

#remove_user(user) ⇒ Object

Remove user from the Agendav database. This should remove him from every table in which he is referenced.

We do not raise an error if the user doesn’t exist. This is due to an unfortunate problem with the “user exists” check in AgenDAV. The AgenDAV “shares” table is not tied directly to a username, so we are forced to use a regexp match to decide what rows to delete from that table. We do so regardless of whether or not the username exists in the “prefs” table, because that table stores only non- default preferences – not all users’ preferences.

Parameters:

  • user (User)

    the user to remove.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rm/plugins/agendav.rb', line 29

def remove_user(user)
  sql_queries = ['DELETE FROM prefs WHERE username = $1;']

  # The "shares" table contains principal URLs, and the "@" symbol
  # is usually encoded to "%40". These queries do a regex match on
  # the username after replacing the "%40" with a "@".
  #
  # As a precaution, I haven chosen not to delete based on the
  # "calendar" field here. Nobody should have a calendar named
  # "user%40example.com", but it's not impossible -- and we don't
  # want to delete that calendar when the not-necessarily-related
  # "[email protected]" account is removed. And the usual appearance
  # of the user's email address in the "calendar" field happens when
  # he is also the owner, so the calendar does get deleted in the
  # normal situation.
  sql_queries << "DELETE FROM shares WHERE REPLACE(owner,'%40','@')    ~ $1;"
  sql_queries << "DELETE FROM shares WHERE REPLACE(\"with\",'%40','@') ~ $1;"

  connection = PG::Connection.new(@db_hash)
  begin
    sql_queries.each do |sql_query|
      connection.sync_exec_params(sql_query, [user.to_s()])
    end
  ensure
    # Make sure the connection gets closed even if a query explodes.
    connection.close()
  end
end