Fórum

Guest user not able to view/download document

thumbnail
Raja Seth, modificado 9 Anos atrás.

Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi All,

I am facing a challenge while executing a custom portlet, in which I am displaying all the pdf(s) url which are being uploaded. I haven't changed any permission for guest user. The url is of format : "portalURL + pathContext + /document/ + folderId + title". Now when I click on the url as guest user its landing me to login page. I checked the Document & Media hook there is no such permission for guest user.

Please let me know what I need to change so that guest user will be able to view/download the pdf.

Thanks & Regards,
Raja
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
What Liferay version are you using?
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Juan,

I am using 6.1.20-ee-ga2.
thumbnail
Raju oukanti, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 143 Data de Entrada: 21/02/12 Postagens Recentes
Hi,
The below code may be help for you.When you are uploading a document, make the document available to guest user programmatically by using the following code.After saving the document details, you should add guest user permissions for the saved document programmatically by using the following code.

DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), groupId, folderId, sourceFileName, title, description, changeLog, extraSettings, file, serviceContext);
DLFileEntryLocalServiceUtil.addFileEntryResources(fileEntry, false, true);


Thanks,
Raju
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Raju,

I am using Liferay 6.1.2 and I checked the liferay doc from this url for DLFileEntryLocalServiceUtil, I am not able to see addFileEntryResources() method.

Please suggest me if I am wrong somewhere.

Thanks,
Raja
thumbnail
Raju oukanti, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 143 Data de Entrada: 21/02/12 Postagens Recentes
Hi Seth,

You can use the following code for add guest user permissions for the uploaded document.

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId(
DLFileEntry.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry
.getFileEntryId()),
roleId,
new String[] {ActionKeys.VIEW});


Thanks,
Raju
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
HI Raju,

The below code only sets permission for particular roleId also removes default permission for all other roles.

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId(
DLFileEntry.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry
.getFileEntryId()),
roleId,
new String[] {ActionKeys.VIEW});


But I also need to have by default permissions for other roles.

Thanks & Regards,
Raja
thumbnail
Jitendra Rajput, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Not sure what exact issue is but one thing i can suggest is instead of generating URL manually you can use Liferay APIs to generate document download URLs.

The url is of format : "portalURL + pathContext + /document/ + folderId + title". 


Instead of above manual format you can use below method from DLUtil.

public static String getPreviewURL(
		FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
		String queryString, boolean appendVersion, boolean absoluteURL) {

		return getDL().getPreviewURL(
			fileEntry, fileVersion, themeDisplay, queryString, appendVersion,
			absoluteURL);
	}


Thank you,
Jitendra
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Jitendra,

Thanks for your reply. I guess the issue is not related to URL. Its related to permission level of the document.

Regards,
Raja
thumbnail
Jitendra Rajput, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
If it is related to permission then provide permission on document for Guest user so that they can view and download document.
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Jitendra,

Here is my code for adding a new file entry :

DLFileEntry entry=DLFileEntryLocalServiceUtil.addFileEntry(user.getUserId(),groupId,
repositoryId,folderId,document.getName(),mimeType,documentTitle,description,null,0, null,document, dis,new Long(docSize),serviceContext);


As per the Raju's suggestion,
DLFileEntryLocalServiceUtil.addFileEntryResources(fileEntry, false, true);
need to be added after the addFileEntry() method. But I guess its for liferay ver. 6.0.

Can you suggest what needs to be done for version I mentioned in my above post.

Thanks & Regards,
Raja
thumbnail
Raju oukanti, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 143 Data de Entrada: 21/02/12 Postagens Recentes
Hi Seth,

You can use the following code for add guest user permissions for the uploaded document.

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId(
DLFileEntry.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL,
String.valueOf(fileEntry
.getFileEntryId()),
roleId,
new String[] {ActionKeys.VIEW});


Thanks,
Raju
thumbnail
Jitendra Rajput, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
You can check below example to set resource permission for any role using ResourcePermissionLocalServiceUtil.

http://itsliferay.blogspot.in/2012/11/add-resource-permission-in-lr-61.html

Thank you,
Jitendra
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Jirendra,

Your blog is also doing the same thing the logic which Raju suggested. Below is the logic which I tried referring your blog :

DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(user.getUserId(),groupId,
						repositoryId,folderId,document.getName(),mimeType,documentTitle,description,null,0, null,document, dis,new Long(docSize),serviceContext);
				
				long companyId = PortalUtil.getDefaultCompanyId();
				Role role = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST); 
				
				ResourcePermission resourcePermission = null;
				
				try {
					resourcePermission = ResourcePermissionLocalServiceUtil.getResourcePermission(companyId,
							 DLFileEntry.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(fileEntry.getPrimaryKey()), role.getRoleId());
					
					ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(DLFileEntry.class.getName(), ActionKeys.VIEW);
					if(Validator.isNotNull(resourcePermission) && !ResourcePermissionLocalServiceUtil.hasActionId(resourcePermission,resourceAction)) {
						resourcePermission.setActionIds(resourcePermission.getActionIds() + resourceAction.getBitwiseValue());
						ResourcePermissionLocalServiceUtil.updateResourcePermission(resourcePermission);
					}
				} catch (com.liferay.portal.NoSuchResourcePermissionException e) {
					resourcePermission = ResourcePermissionLocalServiceUtil.createResourcePermission(CounterLocalServiceUtil.increment());
					resourcePermission.setCompanyId(companyId);
					resourcePermission.setName(DLFileEntry.class.getName());
					resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
					resourcePermission.setPrimKey(String.valueOf(fileEntry.getPrimaryKey()));
					resourcePermission.setRoleId(role.getRoleId());
					ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(DLFileEntry.class.getName(), ActionKeys.VIEW);
					resourcePermission.setActionIds(resourceAction.getBitwiseValue());// (ActionKeys.VIEW);
					ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
				}



Thanks & Regards,
Raja
thumbnail
Raja Seth, modificado 9 Anos atrás.

RE: Guest user not able to view/download document

Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi All,

I got the solution. I changed the code from
DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.addFileEntry(user.getUserId(),groupId,
repositoryId,folderId,document.getName(),mimeType,documentTitle,description,null,0, null,document, dis,new Long(docSize),serviceContext);
to
FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(user.getUserId(), repositoryId, folderId, document.getName(), mimeType, documentTitle, description, null, contentDoc, serviceContext);
.

Thanks,
Raja