Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,389
Community Members
 
Community Events
165
Community Groups

bulk delete for unsynced users

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

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.

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

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

Thank you for your javascript. Worked perfectly. 

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? =(

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.

Works like a charm! Many THX!

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?

@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 

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)

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

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

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

0 votes
Capi _resolution_ Marketplace Partner Jun 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 Feb 07, 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!

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

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 ...

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?

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

Cool, thanks Christoffer.

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. 

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

Cool thanks for the response.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

32 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you