-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 28579 add way to bulk reset permissions (#30352)
New feature added to allow bulk reset permissions. The approach taken was to create a new actionlet, this way now the user can create a step and add a sub-action to it called "Reset Permissions". This subaction doesn't need any parameter, and to execute it the user firing the action should have edit permissions on the contentlet. To be able to fire this action you should add it to a step as a sub-action: https://github.com/user-attachments/assets/1955851c-2f93-4c00-b007-d7c7bf389901 Then (and after adding any setting that you want) you can fire the step. Here I show a case of an unlimited user, such as admin, in where I reset the permission of several contentlets, first I show that the contentlets have had their permissions modified. **Case admin user** https://github.com/user-attachments/assets/d915a00d-89e9-47cd-95a6-9c0c2971e5d3 Then there is the case in where the user doesn't have the permissions to edit permissions in some of the contentlets, so here I select some contentlets and show that they have only publish permissions to the Publisher role and some others that have the edit permissions, these last contentlets are going to be the ones that executes the action successfully. **Case limited user** https://github.com/user-attachments/assets/4269bec3-7d2e-41ea-8c21-8a41ebc0b2d5 **Note***: Apart from the issue, an error was found and fixed. When firing some action, **if the first contentlet throws a fail**, the flow doesn't keep trying to execute the action in the remaining contentlets because it was throwing an exception unrelated to the action itself, here I show how was the error happening with another subaction (Unlock) https://github.com/user-attachments/assets/8cde0540-c36b-4d1f-b6cb-4aa33434a6c5 --------- Co-authored-by: erickgonzalez <[email protected]>
- Loading branch information
1 parent
8d0762a
commit e42386d
Showing
6 changed files
with
208 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...rc/main/java/com/dotmarketing/portlets/workflows/actionlet/ResetPermissionsActionlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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; | ||
|
||
|
||
/** | ||
* This Actionlet allows the user to reset the permissions of a contentlet | ||
* The user must have edit permissions to fire this action. | ||
*/ | ||
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."; | ||
} | ||
|
||
/* | ||
* This method will reset the permissions of the contentlet after checking that the user has edit permissions to modify it. | ||
* */ | ||
@Override | ||
public void executeAction(WorkflowProcessor processor, Map<String, WorkflowActionClassParameter> params) throws WorkflowActionFailureException { | ||
|
||
try { | ||
|
||
User user = processor.getUser(); | ||
|
||
PermissionAPI permissionAPI = APILocator.getPermissionAPI(); | ||
PermissionBitAPIImpl api = (PermissionBitAPIImpl) APILocator.getPermissionAPI(); | ||
Permissionable asset = processor.getContentlet(); | ||
if (!user.isAdmin() && !api.doesUserHavePermission(asset, PermissionAPI.PERMISSION_EDIT_PERMISSIONS, user) && | ||
!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); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.