Date now = new Date();
String action = "delete group";
User loggedInUser = getLoggedInUser();
if (authorizer.isAuthorized(loggedInUser, Function.DELETE_GROUP.name()))
{
Group group = groupDAO.findById(updateGroup.getId());
if (group != null)
{
// remove associated password permissions
List<Password> passwords = passwordDAO.findPasswordsByPermissionSubject(group);
for (Password password : passwords)
{
password.removePermissionsBySubject(group);
passwordDAO.makePersistent(password);
}
// remove associated template details
List<Template> templates = templateDAO.findTemplatesByDetailSubject(group);
for (Template template : templates)
{
template.removeDetailsBySubject(group);
templateDAO.makePersistent(template);
}
// remove associated users
group.removeUsers();
// actually remove group
groupDAO.flush();
groupDAO.makeTransient(group);
auditLogger.log(now, loggedInUser.getUsername(), ServerSessionUtil.getIP(), action, groupTarget(group), true, "");
}