Fixed flag deletion when user is deleted.

This patch contains:
- Fixed ID call.
- Added tests for flag deletion when user is deleted.