Skip to content

Commit

Permalink
chore: include hotfix-17250 (#26140)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolistorres committed Sep 17, 2023
1 parent f68fa30 commit 594c8df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.dotcms.util.ConversionUtils;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.Role;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.portlets.workflows.model.MultiUserReferenceParameter;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClassParameter;
Expand All @@ -15,6 +16,8 @@
import com.dotmarketing.portlets.workflows.util.WorkflowEmailUtil;
import com.dotmarketing.util.Logger;
import com.liferay.portal.model.User;
import io.vavr.Tuple2;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -126,8 +129,9 @@ public void executeAction(final WorkflowProcessor processor,
final String emailSubject = getParameterValue(params.get(PARAM_EMAIL_SUBJECT));
final String emailBody = getParameterValue(params.get(PARAM_EMAIL_BODY));
final boolean isHtml = getParameterValue(params.get(PARAM_IS_HTML), true);
final Set<User> requiredContentApprovers = getUsersFromIds(userIds, ID_DELIMITER);
// Add this approval to the history
final Tuple2<Set<User>, Set<Role>> usersAndRoles = getUsersFromIds(userIds, ID_DELIMITER);
final Set<Role> approverRoles = usersAndRoles._2();
final Set<User> requiredContentApprovers = usersAndRoles._1(); // Add this approval to the history
final WorkflowHistory history = new WorkflowHistory();
history.setActionId(processor.getAction().getId());
history.setMadeBy(processor.getUser().getUserId());
Expand All @@ -146,6 +150,15 @@ public void executeAction(final WorkflowProcessor processor,
// email ONLY to the users who have NOT approved
final List<String> emails = new ArrayList<>();
boolean setNextAssign = Boolean.TRUE;

for (final Role role : approverRoles) {
if (setNextAssign) {
processor.setNextAssign(role);
setNextAssign = Boolean.FALSE;
break;
}
}

for (final User user : requiredContentApprovers) {
if (!hasApproved.contains(user)) {
emails.add(user.getEmailAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import com.dotmarketing.portlets.workflows.model.WorkflowHistory;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.fasterxml.jackson.databind.introspect.AnnotationMap;
import com.liferay.portal.model.User;
import com.liferay.util.Validator;
import io.vavr.Tuple;
import io.vavr.Tuple2;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -43,8 +47,10 @@ private WorkflowActionletUtil() {
*
* @return The list of {@link User} objects based on the specified IDs.
*/
public static Set<User> getUsersFromIds(final String ids, final String delimiter) {
public static Tuple2<Set<User>, Set<Role>> getUsersFromIds(final String ids, final String delimiter) {

final Set<User> userSet = new HashSet<>();
final Set<Role> roleSet = new HashSet<>();
final StringTokenizer tokenizer = new StringTokenizer(ids, delimiter);
while (tokenizer.hasMoreTokens()) {
boolean idNotFound = Boolean.FALSE;
Expand Down Expand Up @@ -72,11 +78,13 @@ public static Set<User> getUsersFromIds(final String ids, final String delimiter
idNotFound = Boolean.TRUE;
exception = e;
}

try {
final Role role = APILocator.getRoleAPI().loadRoleByKey(token);
final List<User> approvingUsersInRole = APILocator.getRoleAPI()
.findUsersForRole(role);
userSet.addAll(approvingUsersInRole);
roleSet.add(role);
idNotFound = Boolean.FALSE;
} catch (DotSecurityException e) {
Logger.warn(WorkflowActionletUtil.class,
Expand All @@ -88,13 +96,15 @@ public static Set<User> getUsersFromIds(final String ids, final String delimiter
exception = e;
}
}

if (idNotFound) {
Logger.warn(WorkflowActionletUtil.class,
"The following email/userID/role key could not be found: " + token,
exception);
}
}
return userSet;

return Tuple.of(userSet, roleSet);
}

/**
Expand Down

0 comments on commit 594c8df

Please sign in to comment.