Skip to content

Commit

Permalink
feat(actionlet): creation of new actionlet and addition to workflow (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gortiz-dotcms committed Oct 15, 2024
1 parent a12617a commit 9e26621
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ public EventOutput fireBulkActions(@Context final HttpServletRequest request,
eventBuilder.name("failure");
eventBuilder.data(Map.class,
Map.of("failure", inode));
eventBuilder.mediaType(MediaType.APPLICATION_JSON_TYPE);
final OutboundEvent event = eventBuilder.build();
try {
eventOutput.write(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ private void checkCopyPermissions(Permissionable permissionable, User user) thro
* @return boolean
* @throws DotDataException
*/
private boolean checkIfContentletTypeHasEditPermissions(final Permissionable permissionable, final User user) throws DotDataException {
public boolean checkIfContentletTypeHasEditPermissions(final Permissionable permissionable, final User user) throws DotDataException {

return permissionable instanceof Contentlet? // we can check if the content type has edit permissions
doesUserHavePermission(Contentlet.class.cast(permissionable).getContentType(), PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user):false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void resetAssetPermissions (String assetId, Long languageId) throws DotDa
}

@CloseDBIfOpened
private Permissionable retrievePermissionable (String assetId, Long language, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {
public static Permissionable retrievePermissionable (String assetId, Long language, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException {

HostAPI hostAPI = APILocator.getHostAPI();
Permissionable perm = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.dotmarketing.portlets.workflows.actionlet;

import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.PermissionBitAPIImpl;
import com.dotmarketing.business.Permissionable;
import com.dotmarketing.business.ajax.PermissionAjax;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClassParameter;
import com.dotmarketing.portlets.workflows.model.WorkflowActionFailureException;
import com.dotmarketing.portlets.workflows.model.WorkflowActionletParameter;
import com.dotmarketing.portlets.workflows.model.WorkflowProcessor;
import com.dotmarketing.util.Logger;
import com.liferay.portal.model.User;

import java.util.List;
import java.util.Map;

public class ResetPermissionsActionlet extends WorkFlowActionlet{
@Override
public List<WorkflowActionletParameter> getParameters() {
return List.of();
}

@Override
public String getName() {
return "Reset Permissions";
}

@Override
public String getHowTo() {
return "This actionlet will reset permissions of the selected contentlets. It does not require any parameters.";
}

@Override
public void executeAction(WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params) throws WorkflowActionFailureException {

try {

User user = processor.getUser();
boolean respectFrontendRoles = user.isBackendUser();

PermissionAPI permissionAPI = APILocator.getPermissionAPI();
Permissionable asset = PermissionAjax.retrievePermissionable(processor.getContentlet().getIdentifier(), processor.getContentlet().getLanguageId(), user, respectFrontendRoles);
PermissionBitAPIImpl api = (PermissionBitAPIImpl) APILocator.getPermissionAPI();
if (!api.doesUserHavePermission(asset, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user)) {
if (!api.checkIfContentletTypeHasEditPermissions(asset, user)) {
throw new DotSecurityException("User id: " + user.getUserId() + " does not have permission to alter permissions on asset " + asset.getPermissionId());
}
}
permissionAPI.removePermissions(asset);
} catch ( Exception e) {
Logger.debug(ResetPermissionsActionlet.class, e.getMessage());
throw new WorkflowActionFailureException(e.getMessage(), e);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,7 @@
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.workflows.LargeMessageActionlet;
import com.dotmarketing.portlets.workflows.MessageActionlet;
import com.dotmarketing.portlets.workflows.actionlet.Actionlet;
import com.dotmarketing.portlets.workflows.actionlet.ArchiveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.AsyncEmailActionlet;
import com.dotmarketing.portlets.workflows.actionlet.BatchAction;
import com.dotmarketing.portlets.workflows.actionlet.CheckURLAccessibilityActionlet;
import com.dotmarketing.portlets.workflows.actionlet.CheckinContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.CheckoutContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.CommentOnWorkflowActionlet;
import com.dotmarketing.portlets.workflows.actionlet.CopyActionlet;
import com.dotmarketing.portlets.workflows.actionlet.DeleteContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.DestroyContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.EmailActionlet;
import com.dotmarketing.portlets.workflows.actionlet.FourEyeApproverActionlet;
import com.dotmarketing.portlets.workflows.actionlet.MoveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.MultipleApproverActionlet;
import com.dotmarketing.portlets.workflows.actionlet.NotifyAssigneeActionlet;
import com.dotmarketing.portlets.workflows.actionlet.NotifyUsersActionlet;
import com.dotmarketing.portlets.workflows.actionlet.PublishContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.PushNowActionlet;
import com.dotmarketing.portlets.workflows.actionlet.PushPublishActionlet;
import com.dotmarketing.portlets.workflows.actionlet.ReindexContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.ResetApproversActionlet;
import com.dotmarketing.portlets.workflows.actionlet.ResetTaskActionlet;
import com.dotmarketing.portlets.workflows.actionlet.SaveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.SaveContentAsDraftActionlet;
import com.dotmarketing.portlets.workflows.actionlet.SendFormEmailActionlet;
import com.dotmarketing.portlets.workflows.actionlet.SetValueActionlet;
import com.dotmarketing.portlets.workflows.actionlet.TranslationActionlet;
import com.dotmarketing.portlets.workflows.actionlet.TwitterActionlet;
import com.dotmarketing.portlets.workflows.actionlet.UnarchiveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.UnpublishContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.VelocityScriptActionlet;
import com.dotmarketing.portlets.workflows.actionlet.WorkFlowActionlet;
import com.dotmarketing.portlets.workflows.actionlet.*;
import com.dotmarketing.portlets.workflows.model.SystemActionWorkflowActionMapping;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClass;
Expand Down Expand Up @@ -263,6 +231,7 @@ public WorkflowAPIImpl() {
NotifyAssigneeActionlet.class,
UnarchiveContentActionlet.class,
ResetTaskActionlet.class,
ResetPermissionsActionlet.class,
MultipleApproverActionlet.class,
FourEyeApproverActionlet.class,
TwitterActionlet.class,
Expand Down

0 comments on commit 9e26621

Please sign in to comment.