In the previous blog we Change the permission of a file to guest programmatically in this blog we change the permission by groovy script.
So Lets start this:-
First go to control panel ->Server Administration->Script->Select Groovy and paste this:-
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
import java.util.ArrayList | |
import java.util.Iterator | |
import java.util.List | |
import java.util.ListIterator | |
import com.liferay.portal.service.ResourcePermissionLocalServiceUtil | |
import com.liferay.portal.service.RoleLocalServiceUtil | |
import com.liferay.portal.model.ResourceConstants | |
import com.liferay.portal.model.ResourcePermission | |
import com.liferay.portal.model.Role | |
import com.liferay.portal.model.RoleConstants | |
import com.liferay.portal.service.ServiceContext; | |
import com.liferay.portlet.documentlibrary.model.*; | |
import com.liferay.portlet.documentlibrary.service.*; | |
import com.liferay.portlet.documentlibrary.service.persistence.*; | |
import com.liferay.portal.security.permission.ActionKeys | |
try { | |
// Replace companyId and fileEntryId | |
long companyId = 10154 | |
long groupId = 10181 | |
start = -1 | |
end = -1 | |
Role guestRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST) | |
String resourceName = DLFileEntry.class.getName() | |
def keys = new String[1] | |
keys[0] = ActionKeys.VIEW | |
def files = DLFileEntryLocalServiceUtil.getDLFileEntries(start, end) | |
println('>> files found:'+ files.size()) | |
for( i=0; i<files.size();i++){ | |
def file = files[i] | |
if(file.getGroupId()==groupId){ | |
String fileEntryId = file.getFileEntryId() | |
if (!ResourcePermissionLocalServiceUtil.hasResourcePermission(companyId, resourceName, ResourceConstants.SCOPE_INDIVIDUAL, fileEntryId, guestRole.getRoleId(), ActionKeys.VIEW)) { | |
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, fileEntryId, guestRole.getRoleId(), keys) | |
out.print(",member"); | |
} | |
out.println(" "); | |
} | |
} | |
}catch (e) { | |
out.println("Error = " + e.getMessage()); | |
} |
and click execute.
Hope this will Help....
Related Post:-
No comments:
Post a Comment