How to automate deletion of users which no longer use the app (are no longer associated with any entity)?

0
My question is a little bit less specific and highly general.   So in most of the apps I make use of the AccountManangement module (Picture below)    Which has the following domain model  (for one example only) The domain model differs from app to app.    What I want to do is to develop a microflow, maybe that calls a java action that does delete contacts which are no longer associated with  primary entities from other modules. But this has to be as generic as possible such that it can be used in other apps and can work regardless of  the other domain models.   I’m not looking for a specific implementation, but for as many ideas as possible, maybe even hints or known Core Api methods that should help me get this done.   I’ve tried  to get all references of the contact using:   List<? extends MendixObjectReference> references = contact.getMendixObject().getReferences(this.getContext()); But it only gives me back the associations which are starting from this domain module and that are linked to other domain modules not the other way around. So in my case, this method was only aware of the first 4 association (counting from the upside) and not to the rest of them.  
asked
2 answers
0

You AccountUser is associated with Administation.Account and in-turn with System.User.

System.User has LastLogin attribute.

With a scheduled event, you will be able to find users who are not logged in for “N” days and delete the users.

For associations, I am not sure if there are ways to get the associations in which the AccountUser is not a owner. May be you can try DB queries to know that. 

But, simple way is: set the delete behavior on AccountUser. https://docs.mendix.com/refguide8/association-properties#delete-behavior 

- Delete AccountUser only if it is not associated with 

- Ofcourse you must do this for all primary associations

answered
0

Hi Marcian,

In this case I do not think it is necessary to use a Java action. I would opt to use a scheduled event which runs every week.

In the scheduled event I would do a retrieve on contacts where the important associations are empty, or which haven't logged in for a while, whatever your condition is. If you want to reuse this in a different app, you'll only have to change this retrieve.

From there you can retrieve their accounts and delete both lists from the database. 

Hope this helps!

answered