]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mailshears/plugins/davical.rb
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 principal_id
= self.get_principal_id(account
)
32 return 'User not found'
34 return "Principal ID: #{principal_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.principal_id "
101 sql_query +
= "FROM (principal INNER JOIN usr "
102 sql_query +
= " ON principal.user_no = usr.user_no) "
103 sql_query +
= "WHERE usr.username = $1;"
105 connection
.query(sql_query
, [account
]) do |result
|
106 if result
.num_tuples
> 0
107 principal_id
= result
[0]['principal_id']
114 # Pretend like we're database-agnostic in case we ever are.
115 raise DatabaseError
.new(e
)
122 def get_davical_usernames()
126 connection
= PGconn
.connect(@db_host,
134 # User #1 is the super-user, and not tied to an email address.
135 sql_query
= 'SELECT username FROM usr WHERE user_no > 1;'
137 connection
.query(sql_query
) do |result
|
138 usernames
= result
.field_values('username')
143 # Pretend like we're database-agnostic in case we ever are.
144 raise DatabaseError
.new(e
)