How to Delete Umbraco User Permanently

Disabling vs deleting Umbraco users

As you may have already noticed, the Umbraco back-office panel does not have a built-in user removal option. When you log in and visit the Users section you will see, that you can only deactivate a user.

How To Delete Umbraco User Permanently Disabling User In Umbraco Backoffice
Disable user in Umbraco back-office panel

I must mention here, that it’s possible to easily hide these inactive users, which I will show later in this article. However, for various reasons such as GPDR, deactivating users may not be a sufficient solution and it’s necessary to remove Users’ data permanently.

How to hard delete a Umbraco user?

When soft delete is not an option, the easiest way to terminate the Umbraco user is to execute a SQL script. Below you will find a full SQL snippet allowing you to remove the Umbraco user from the database. You can use this piece of code directly in SQL Server Management Studio or your tool of choice

Tip! Before you start removing users, make sure you’ve made a backup of your database, so you could restore the changes if something goes wrong. The following script was tested on Umbraco 8.6.0 version.

Deleting Umbraco user with SQL script

Before deleting records from the [umbracoUser] table you have to deal with related data in the following tables:

  • [dbo].[umbracoContentVersion]
  • [dbo].[umbracoNode]
  • [dbo].[umbracoLog]
  • [dbo].[umbracoUser2UserGroup]
  • [dbo].[umbracoUserLogin]
  • [dbo].[umbracoUser2NodeNotify]
  • [dbo].[umbracoUserStartNode]

We have three options here:

  • deleting all related data
  • detaching related data by setting userId = null
  • assigning related elements to a system user by setting: userId = -1.

The SQL script below uses the second approach and is a good starting point:

BEGIN TRAN

DECLARE @userId INT = (
		SELECT id
		FROM [dbo].[umbracoUser]
		WHERE userLogin = 'hello@piotrbach.com'
		);

UPDATE [dbo].[umbracoContentVersion]
SET userId = NULL
WHERE userId = @userId;

UPDATE [dbo].[umbracoNode]
SET nodeUser = NULL
WHERE nodeUser = @userId;

UPDATE [dbo].[umbracoLog]
SET userId = NULL
WHERE userId = @userId;

DELETE
FROM [dbo].[umbracoUser2UserGroup]
WHERE userId = @userId;

DELETE
FROM [dbo].[umbracoUserLogin]
WHERE userId = @userId;

DELETE
FROM [dbo].[umbracoUser2NodeNotify]
WHERE userId = @userId;

DELETE
FROM [dbo].[umbracoUserStartNode]
WHERE userId = @userId;

DELETE
FROM [dbo].[umbracoUser]
WHERE id = @userId;

ROLLBACK TRAN -- COMMIT TRAN

Tip! It’s good to wrap SQL code with the transaction to avoid data integrity issues when something goes wrong.

Once the SQL code is executed, the user should no longer show up in the Users section. At this point, it’s a good idea to run some basic system tests to make sure everything works as expected.

What about user-related content?

User-related content will not display deleted author, but you should be able to restore previous versions of the content. You can see it in the screenshot below:

Umbraco Delete User Activity Log
Content user audit log

How to hide disabled users in Backoffice

As I wrote earlier, Umbraco allows you to hide inactive users in the back office by changing the settings. To enable this feature, you need to locate the umbracoSettings.config file  (~/config/umbracoSettings.config). Then, navigate to the security section and find a tag named “hideDisabledUsersInBackoffice“.

<hideDisabledUsersInBackoffice>true</hideDisabledUsersInBackoffice>

As the name suggests, once you change the value to “true”, inactive users should not be listed in the back office section. To download the source code for this post, please visit GitHub

Similar Posts