Removal of users

From Davical
Revision as of 19:26, 21 August 2009 by Cs (talk) (Deleting Users with SQL)
Jump to navigationJump to search

At present there is no functionality in the administrative interface to delete users or calendars.

The recommended approach is to mark users as inactive, rather than delete them.

Deleting Calendars with a DAV Client

It is possible to use a DAV client like cadaver to delete a calendar. I don't know of any CalDAV client which implements deletion of remote calendars (delete usually only removes the connection information), but the functionality is implemented in DAViCal.

Deleting Users with SQL

While there is no functionality to delete a user or a calendar through the admin user interface in DAViCal, the tasks can be done through SQL.

BEGIN;
DELETE FROM relationship WHERE to_user = (SELECT user_no FROM usr WHERE username='someuser');
DELETE FROM relationship WHERE from_user = (SELECT user_no FROM usr WHERE username='someuser');
DELETE FROM collection WHERE user_no = (SELECT user_no FROM usr WHERE username='someuser');
DELETE FROM property WHERE dav_name LIKE '/someuser/%';
DELETE FROM usr WHERE username = 'someuser';
COMMIT;

In some circumstances this won't work completely, because the user will have modified appointments in other calendars. A decision will need to be made to modify or delete those appointments in order to pass the relational integrity check.

To list the entries changed by a particular user, something like the following:

SELECT * FROM caldav_data WHERE logged_user = (SELECT user_no FROM usr WHERE username='someuser');

If you want to delete a single user, the SQL commands above will do it. Since I was in need of a more efficient way, I wrote a little script (davical_deluser) to help me with that. Read the head of the script for instructions.

Emptying a Calendar with SQL

To delete just the events in a particular calendar:

DELETE FROM caldav_data WHERE dav_name = '/username/calendar/';

A database trigger will remove the related entries from the calendar_item table.

Deleting a Calendar with SQL

To delete a calendar:

DELETE FROM collection WHERE dav_name = '/username/calendar/';