bulk delete for unsynced users

Lutz Faber February 6, 2019

Starting from Confluence 6.13, admins can delete users that are unsynced from Confluence. Unsynced users are users that are not synced any more when an external user directory is being synchronized. This could be because the user has been removed from the external directory or it is because the user directory filters no longer include that user etc.

While this feature is useful, the current implementation only allows the deletion of these users individually and there is no option to perform bulk delete. Having the bulk delete feature would greatly help.

Does anyone have a set of scripts, which do such a bulk removing

There exists a feature request for that feature and it requires more voting for.

Best regards,

Lutz

3 answers

8 votes
Christoffer Bromberg _K15t_ October 15, 2019

Had to deal with that just right now on our instances - after giving the list (max out the pagesize to 100) a rough scan if I am sure they should be deleted and then opened the Java Script console to run the following Javascript

AJS.$('#user-search #browse-user-table a:not(.confluence-userlink)').each(
function (ie) {var id = $(e).attr('href').split('=')[1];    
AJS.$.post('/admin/users/removeunsynceduser-confirm.action',
userKey: id'atl_token': AJS.Meta.get('atl-token') }, 
function () { console.info('Deleted ' + id) })
})

This uses the HTML DOM on the page to select the userKeys and makes AJAX posts to remove the users. Instead of having to click 900 times for 300 users and wait for 600 page loads I just refresh the page 3 times and run the script 3 times and all the users are deleted.

A word of warning though: these users never authored anything in Confluence and deleting them is very simple. That might be different for your environment.

Still you can reduce the page size to fine tune or change the script to wait for completion (then you would need to track progress) or simply add a delay.

Lutz Faber October 15, 2019

Hello Christoffer,

if i understand Your posting correct, Your script will NOT

  • permanently replace their username with a randomised alias, wherever it appears.

or what do You mean with

"these users never authored anything Confluence"

Best regards from just around the corner in Schloßstraße,

Lutz

Christoffer Bromberg _K15t_ October 15, 2019

Well, see above answer - the community software is doing strange things ...

Daniel Corrigan November 7, 2019

Thank you for your javascript. Worked perfectly. 

Sergey May 26, 2020

Hi Christoffer

I try use your script, but see error: batch.js?healthcheck-resources=true&hostenabled=true&locale=en-GB:392 POST http://ip_addr/admin/users/removeunsynceduser-confirm.action 404 (Not Found)

Why? =(

Deleted user August 19, 2020

Used successfully the javascript incantation above to clean up unsynced users after breaking application link to JIRA service desk and then removing the user directory link.

Works well, 100 users at a time.

Lotto24 AG June 10, 2021

Works like a charm! Many THX!

Dabin Daniel Sundaram June 14, 2022

Hello @Christoffer Bromberg _K15t_

The query which you have give will delete all the users from the Unsynced from directory tab? I want to delete only a list of users not all users. Is there a way to pass the list of the user and delete the users from the Unsynced from directory tab?

Christoffer Bromberg _K15t_ June 14, 2022

@Dabin Daniel Sundaram Exactly.

It is JavaScript code that needs to be executed in the context of the page /admin/users/showallunsyncedusers.action and will select the available data from the HTML (DOM) and then use that data to delete the user via a POST operation.

The HTML also contains the user name and email (if available) so if you add a condition for that or you retrieve additional information via the REST API you can also filter, e.g.

AJS.$('#unsynced-pane #user-search #browse-user-table tbody > tr').each(
function (ie) {
var id = $(e).find('a:not(.confluence-userlink)').attr('href').split('=')[1];    
var email = $(e).find('td:eq(2)').text();
var username = $(e).find('td:eq(1)').text();
if (email.indexOf('@domain.com') > 0) {
AJS.$.post('/admin/users/removeunsynceduser-confirm.action',userKey: id'atl_token': AJS.Meta.get('atl-token') }, 
function () { console.info('Deleted ' + id) });
} else {
console.info('Ignored ' + id + ' ' + username);
}
})


Cheers, Chris 

Christoffer Bromberg _K15t_ June 14, 2022

Note though that it only uses visible data on the page - thus if you repeat that process the users that do not satisfy your deletion criteria will fill up the page after some iterations (depending of course on what the ratio of users that should be deleted and users that should remain is)

Dabin Daniel Sundaram June 14, 2022

Hello @Christoffer Bromberg _K15t_

Thank you for your response.
I have a list of users who left the company long back. I just want to delete those users only. Recent users I do not want to delete. Is there any possibility to upload the file and delete the user based on the file?

Regards, Dabin

Christoffer Bromberg _K15t_ June 14, 2022

Hi, 

as you can see this is custom scripting and leveraging parts of the Confluence frontend as API that are not intended for that use, but it does serve its (limited) purpose. 
If you need a readymade feature I am afraid you need to deal with Confluence DC product management 
Best, Chris

Dabin Daniel Sundaram June 15, 2022

Hello @Christoffer Bromberg _K15t_

Great, thanks!

Regards, Dabin

Dabin Daniel Sundaram June 27, 2022

Hi @Christoffer Bromberg _K15t_

We have stored all the user details in a specific Ldap connection for confluence. The masking of the data would be done in the ldap as well. Do this deletion of the users from unsynced directory will delete the data in the ldap which has been masked?

Regards, Dabin

Claire Berry June 29, 2023

Hi, sorry to add on to this thread. We have a similar issue where there is one user with the same username with over 1000 entries in the 'Unsynced from Directory' section. I tried this script, although not sure it is working because I don't know how many duplicates there are of this user. I have toggled through the pages and there is at least 12 pages of 100 of the same user (1200+). So I really don't know how many there are and running this script for each page could still take a long time depending on how many pages of 100 there are. Do you know if there is a way to check the DB to see how many of these users there are? We are using Confluence Data Center and I checked various tables, cwd_user etc and can't find the user in there. Not sure if there is another way to search for unsynced users. Google is not giving me anything. 
Thanks.

0 votes
Capi [resolution]
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 15, 2022

This is an old thread but the javascript code has been updated, so I'm hoping to update it with a solid reference as well.

@Lutz Faber mentioned that Techtime's User Management app does not deactivate unsynced users, since it actually doesn't lookup the Identity Provider.

At resolution we do have two apps that can do this:

Essentially the functionality is the same. You can sync users via API and if the user doesn't show up in the IdP anymore (either because it was removed or because it was dropped from a mandatory group) then it will be disabled in the Confluence directory. 

There are different cleanup behaviors depending on your use case, here's a good reference on it: Disable users not found in the connector

For full disclosure, I work for resolution, the Gold Marketplace Partner behind the two quoted apps. 

Apologies for necroposting, but I feared customers would otherwise not find a solution to the stated problem.

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 7, 2019

Hello there Lutz! Is this the Suggestion that you mentioned:

CONFSERVER-57857 | Provide the functionality to perform bulk delete for unsynced users

The user deletion process can be quite taxing for your instance. As of today, there is no built-in feature or Atlassian Made script that takes care of start the deletion processes automatically. Each deletion process should be started individually and will only start after the previous one has ended.

However, there are some plugins that claim being capable of bulk user deletion, such as:

User Management for Confluence

Further, you could vote and watch this suggestion. Voting increases the visibility of this report and watching will keep you up to date with anything new there.

Let us know your thoughts Lutz!

Lutz Faber February 7, 2019

Hello Diego,

Yes that is the suggestion. If You have around 1500 Students per Year, who are unsynced, You don't want to remove them manually.

The Plugin You mentioned does not work on unsynced users.

Do You know a plugin, which do so.

I have voted already.

Best regards, Lutz

Christoffer Bromberg _K15t_ October 15, 2019

Hi Lutz,

the world is small. I meant that for me and my instance this operation is pretty light-weight, because the selects/deletes the database has to perform will not find anything to change (other than the user record itself). I did not see any performance hits that Diego mentioned, if your users did in fact create spaces, author pages, upload attachments etc. that might have a bigger impact (and your instance might also be much bigger).

For me the script running with a page size of 50 worked fine without causing any problems. The code that is run on the server is the same as if you click through every single user - the script is just triggering that code without all the clicking and waiting ...

ViswanathanR July 3, 2020

I guess copying to Custom HTML <end of body section> and keep running multiple times until users deleted?

 

is this way to run the java script?

Christoffer Bromberg _K15t_ July 4, 2020

No, open the Developer Console of your browser when on the Unsynced Users page. Don't put that in Custom HTML of your Confluence instance, this will swamp the browser console and possibly even break pages from rendering correctly.

Like ViswanathanR likes this
ViswanathanR July 6, 2020

Cool, thanks Christoffer.

ViswanathanR July 8, 2020

May be helpful, the script works, but I get warning too

 

DEPRECATED JS - Dialog has been deprecated since 6.0.6 and will be removed in a future release. Use require('confluence-create-content/space-blueprint')
at HTMLDocument.<anonymous> (https://<MyconfluenceURL>/_/download/contextbatch/js/_super/batch.js?locale=en-GB:860:136)

 

I'm on 6.13 version and planning to upgrade. 

Christoffer Bromberg _K15t_ July 9, 2020

Hi Viswanathan,

this is not from the script - but from Confluence UI packages that run when you visit a page, it means that either a third-party app vendor or the Atlassian team is using a JS component (Dialog) that has been marked as deprecated by the maintainer (Atlassian).
This is nothing that you have to worry about, but the Atlassian Confluence team and app vendors need to take care of that. Cheers, Chris

ViswanathanR July 10, 2020

Cool thanks for the response.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events