]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mailshears/plugins/davical.rb
8 cfg
= Configuration
.new()
9 @db_host = cfg
.davical_dbhost
10 @db_port = cfg
.davical_dbport
11 @db_opts = cfg
.davical_dbopts
12 @db_tty = cfg
.davical_dbtty
13 @db_name = cfg
.davical_dbname
14 @db_user = cfg
.davical_dbuser
15 @db_pass = cfg
.davical_dbpass
19 def describe_domain(domain
)
20 # DAViCal doesn't have a concept of domains.
25 def describe_account(account
)
26 user_id
= self.get_principal_id(account
)
29 return 'User not found'
31 return "Principal ID: #{user_id}"
36 def delete_domain(domain
)
37 # DAViCal doesn't have a concept of domains.
41 def delete_account(account
)
42 # Delete the given username. DAViCal uses foreign keys properly
43 # and only supports postgres, so we let the ON DELETE CASCADE
44 # trigger handle most of the work.
45 sql_queries
= ['DELETE FROM usr WHERE username = $1']
48 connection
= PGconn
.connect(@db_host,
56 sql_queries
.each
do |sql_query
|
57 connection
.query(sql_query
, [account
])
63 # Pretend like we're database-agnostic in case we ever are.
64 raise DatabaseError
.new(e
)
70 def get_leftover_domains(db_domains
)
71 # AgenDAV doesn't have a concept of domains.
76 def get_leftover_accounts(db_accounts
)
77 # Get a list of all users who have logged in to DAViCal.
78 davical_accounts
= self.get_davical_usernames()
79 return davical_accounts
- db_accounts
85 def get_principal_id(account
)
89 connection
= PGconn
.connect(@db_host,
97 sql_query
= "SELECT principal_id FROM users WHERE username = $1;"
99 connection
.query(sql_query
, [account
]) do |result
|
100 if result
.num_tuples
> 0
101 principal_id
= result
[0]['principal_id']
108 # Pretend like we're database-agnostic in case we ever are.
109 raise DatabaseError
.new(e
)
116 def get_davical_usernames()
119 # Just assume PostgreSQL for now.
121 connection
= PGconn
.connect(@db_host,
129 sql_query
= 'SELECT username FROM usr;'
131 connection
.query(sql_query
) do |result
|
132 usernames
= result
.field_values('username')
137 # Pretend like we're database-agnostic in case we ever are.
138 raise DatabaseError
.new(e
)