]>
gitweb.michael.orlitzky.com - mailshears.git/blob - davical.rb
fae30d8f794d3667b835773157ed2b801f5855ed
5 # DAViCal only supports Postgres, so even if we ever are
6 # database-agnostic, this plugin can't be.
11 cfg
= Configuration
.new()
12 @db_host = cfg
.davical_dbhost
13 @db_port = cfg
.davical_dbport
14 @db_opts = cfg
.davical_dbopts
15 @db_tty = cfg
.davical_dbtty
16 @db_name = cfg
.davical_dbname
17 @db_user = cfg
.davical_dbuser
18 @db_pass = cfg
.davical_dbpass
22 def describe_domain(domain
)
23 # DAViCal doesn't have a concept of domains.
28 def describe_account(account
)
29 user_id
= self.get_principal_id(account
)
32 return 'User not found'
34 return "Principal ID: #{user_id}"
39 def delete_domain(domain
)
40 # DAViCal doesn't have a concept of domains.
44 def delete_account(account
)
45 # Delete the given username. DAViCal uses foreign keys properly
46 # and only supports postgres, so we let the ON DELETE CASCADE
47 # trigger handle most of the work.
48 sql_queries
= ['DELETE FROM usr WHERE username = $1']
51 connection
= PGconn
.connect(@db_host,
59 sql_queries
.each
do |sql_query
|
60 connection
.query(sql_query
, [account
])
66 # Pretend like we're database-agnostic in case we ever are.
67 raise DatabaseError
.new(e
)
73 def get_leftover_domains(db_domains
)
74 # AgenDAV doesn't have a concept of domains.
79 def get_leftover_accounts(db_accounts
)
80 # Get a list of all users who have logged in to DAViCal.
81 davical_accounts
= self.get_davical_usernames()
82 return davical_accounts
- db_accounts
88 def get_principal_id(account
)
92 connection
= PGconn
.connect(@db_host,
100 sql_query
= "SELECT principal_id FROM principal WHERE username = $1;"
102 connection
.query(sql_query
, [account
]) do |result
|
103 if result
.num_tuples
> 0
104 principal_id
= result
[0]['principal_id']
111 # Pretend like we're database-agnostic in case we ever are.
112 raise DatabaseError
.new(e
)
119 def get_davical_usernames()
123 connection
= PGconn
.connect(@db_host,
131 # User #1 is the super-user, and not tied to an email address.
132 sql_query
= 'SELECT username FROM usr WHERE user_no > 1;'
134 connection
.query(sql_query
) do |result
|
135 usernames
= result
.field_values('username')
140 # Pretend like we're database-agnostic in case we ever are.
141 raise DatabaseError
.new(e
)