Skip to content
Snippets Groups Projects
Commit 24963a58 authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Merge branch '#1076531_deleteUserWithHisPrivateTags' into '2021.2'

[Projekt: Entwicklung - Neon][TicketNr.: 1076531][Löschen eines Users muss...

See merge request xrm/basic!1495
parents 893fe60b e368f3c8
No related branches found
No related tags found
No related merge requests found
......@@ -5,14 +5,60 @@ import("system.neon");
import("system.vars");
import("system.tools");
import("Employee_lib");
import("system.tag");
//the current user should not delete himself
if (EmployeeUtils.getCurrentUserName() != vars.get("$field.TITLE") && !EmployeeUtils.hasRelations(vars.get("$field.CONTACT_ID")))
{
tools.deleteUser(vars.get("$field.TITLE"));
new AttributeRelationQuery(EmployeeUtils.sliceUserId(vars.get("$field.UID")), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
var targetUserTitle = vars.get("$field.TITLE");
if (targetUserTitle)
{
untagAllPrivateTaggedObjects(targetUserTitle);
tools.deleteUser(targetUserTitle);
new AttributeRelationQuery(EmployeeUtils.sliceUserId(vars.get("$field.UID")), null, ContextUtils.getCurrentContextId())
.deleteAllAttributes();
WorkflowSignalSender.deleted();
WorkflowSignalSender.deleted();
}
}
/*
* Untags all private tagged objects (default favorites and favorite groups) of the provided user.
*/
function untagAllPrivateTaggedObjects(pTargetUserTitle)
{
var privateTags = [];
var targetUser = tools.getUser([pTargetUserTitle], tools.PROFILE_DEFAULT);
var config = tag.createGetTaggedObjectsConfig();
config.setUserId(targetUser.name);
// get all objects tagged as default favorite
config.setTagType(tag.DEFAULT_FAVORITE_GROUP);
privateTags = privateTags.concat(getAllTaggedObjectIds(config));
// get all objects tagged as favorite group
config.setTagType(tag.FAVORITE_GROUP);
privateTags = privateTags.concat(getAllTaggedObjectIds(config));
// untag all private tags
config = tag.createUntagMultipleByIdConfig();
config.setTaggedObjectsRecordIds(privateTags);
tag.untag(config);
}
/*
* Returns an array containing all ids of private tagged objects (ID of ASYS_RECORD).
*/
function getAllTaggedObjectIds(pConfig)
{
var allTaggedObjectIds = [];
tag.getTaggedObjects(pConfig).forEach(function(taggedObject) {
if (taggedObject.id)
allTaggedObjectIds.push(taggedObject.id);
});
return allTaggedObjectIds;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment