Sometimes we need to change the permission of a document to Guest in Liferay. For this we can change this by Groovy Script or programatically. Today we will change this programatically:-
So lets start this:-
You can simply use this code to change the permission to guest. In this first we check the folder permission and then file permission:-
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
public static void changeFileEntryToGuest(DLFileEntry file) throws SystemException { | |
final long companyId = Long.parseLong(PropsUtil.get(LifemartMobileAppConstants.LIFEMART_COMPANY_ID)); | |
String dlFileFolderResourceName = DLFolder.class.getName(); | |
String folderId = String.valueOf(file.getFolderId()); | |
String[] actionIds = new String[] { ActionKeys.VIEW }; | |
String dlFileEntryResourceName = DLFileEntry.class.getName(); | |
String fileEntryId = String.valueOf(file.getFileEntryId()); | |
LOG.debug("changeFileEntryToGuest companyId:" + companyId + " folderId: " + folderId + " fileEntryId:" + fileEntryId); | |
try { | |
Role guestRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST); | |
// Change Folder Permission to Guest View | |
if (!ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, dlFileFolderResourceName, ResourceConstants.SCOPE_INDIVIDUAL, folderId, guestRole.getRoleId(), ActionKeys.VIEW)) { | |
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, dlFileFolderResourceName, ResourceConstants.SCOPE_INDIVIDUAL, folderId, guestRole.getRoleId(), actionIds); | |
} | |
// Change File Permission To Guest View | |
if (!ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, dlFileEntryResourceName, ResourceConstants.SCOPE_INDIVIDUAL, fileEntryId, guestRole.getRoleId(), ActionKeys.VIEW)) { | |
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, dlFileEntryResourceName, ResourceConstants.SCOPE_INDIVIDUAL, fileEntryId, guestRole.getRoleId(), actionIds); | |
} | |
} catch (PortalException e) { | |
LOG.error(e.getMessage(), e); | |
} | |
} |
No comments:
Post a Comment