# Bug OP-18352 - User not fully deleted if that user created a recurring meeting

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-18352

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module | Administration / User administration, Frontend components and Primer design system |
| Target versions | 16.6.3 |
| Observed in versions | 16.6.0 |
| Sprint | 16.6.3 |
| Backlog bucket |  |
| Bug found in version (deprecated) | 16.6.x |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers | Christophe Bliard |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Steps to reproduce

1.  Create a user and log in with this user

2.  Create a work package

3.  Create a recurring meeting

4.  Now log out and log in as an admin

5.  Delete the user in the administration
    
    1.  do not forget to go to administration \> Users \> Settings and check "User accounts deletable by admins" to have the "Delete" button available.

6.  Go to the work package this user created

### What is the buggy behavior?

  - Error 500 when the activity tab is loaded

  - This prevents using the app correctly as it will show a 500 error for *any* work package the deleted user has commented / created.

### What is the expected behavior?

1.  User should be fully deleted

2.  All created objects should be reassigned to "Deleted user"

### 

### **Logs**

The activities tab rendering fails with this error:

``` text
ActionController::UrlGenerationError (No route matches {action: "show", controller: "users", id: nil, work_package_id: "43"}, possible unmatched constraints: [:id]):
lib/open_project/object_linking.rb:133:in 'OpenProject::ObjectLinking#primer_link_to_user'
app/components/work_packages/activities_tab/shared_helpers.rb:41:in 'WorkPackages::ActivitiesTab::SharedHelpers#truncated_user_name'
app/components/work_packages/activities_tab/journals/item_component/details.rb:113:in 'block in WorkPackages::ActivitiesTab::Journals::ItemComponent::Details#render_user_nam
[...]
```

`primer_link_to_user` does not deal well with `user` being `nil`.

This happened in production for a customer. That's how we discovered the issue.

Here is the appsignal link to the rendering problem:  <https://appsignal.com/openproject-gmbh/sites/674718f1d2a5e4a7cb8b2298/exceptions/incidents/1317>.

### Analysis

The user deletion was incomplete: the references to `RecurringMeeting.author_id` was *not* replaced with the `DeletedUser` instance.

The `Principals::DeleteJob` fails with the following error:

`PG::ForeignKeyViolation: ERROR:  update or delete on table "users" violates foreign key constraint "fk_rails_718ca7b915" on table "recurring_meetings"`

Here is the appsignal link to that problem: <https://appsignal.com/openproject-gmbh/sites/674718f1d2a5e4a7cb8b2298/exceptions/incidents/1002>.

The user can still be found in the system by doing `User.unscoped.deleted`.

To fix the issue:

``` ruby
Principals::ReplaceReferencesService.add_replacements("RecurringMeeting" => :author_id)
while user_to_delete = User.unscoped.deleted.first
  Principals::DeleteJob.perform_now(user_to_delete)
end
```

### Environment information

**OpenProject installation type**

  - Hosted cloud edition

**OpenProject version**

16.6.1, but the issue exists on older versions too.

**Browser**

- [ ] Chrome
- [x] Firefox
- [ ] Safari
- [ ] Mobile Safari
- [ ] Other (please specify)

**Operating System**

- [ ] Windows
- [x] Mac OS X
- [ ] Mobile iOS
- [ ] Mobile Android
- [ ] Linux (please specify distro)
- [ ] Chrome OS
- [ ] Other (please specify)

**Language**

*Please specify the browser language and the language of the OpenProject user for which the bug occurred.*
