diff --git a/entity/Employee_entity/recordcontainers/jdito/onDelete.js b/entity/Employee_entity/recordcontainers/jdito/onDelete.js index 24ad2b0487705801548cc6654fe9a82e0bdb4322..876381fb501a07aef95ed8946195bd1593c012a4 100644 --- a/entity/Employee_entity/recordcontainers/jdito/onDelete.js +++ b/entity/Employee_entity/recordcontainers/jdito/onDelete.js @@ -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