Fórum

Change the default permission for documents

thumbnail
Alain Dresse, modificado 12 Anos atrás.

Change the default permission for documents

Junior Member Postagens: 95 Data de Entrada: 18/07/11 Postagens Recentes
Hi,

I would like to change the default default selected item in the permission input field created by liferay-ui:input-permissions when adding a new document in the document library (using a hook).

I would like the default permission for a newly added file in a folder to be based on the permissions of the folder: if guests can see the folder, I would like guests to see the file by default.

Two specific questions:
  • How do I see if the folder in which the folder is added has view permission
  • How do I set the default view permission (in the input select) to Guest, i.e. how to get ParamUtil.getString(request, "inputPermissionsViewRole") in page.jsp for liferay-ui:input-permissions to return RoleConstants.GUEST).


Best regards,
Alain
thumbnail
Alain Dresse, modificado 12 Anos atrás.

RE: Change the default permission for documents

Junior Member Postagens: 95 Data de Entrada: 18/07/11 Postagens Recentes
Solved !

The idea is basically to implement some form of permission inheritance at the gui level: if a folder gives guests a view permission, the documents created in that folder will also give guests a view permission.

The solution is a hook to modify html/portlet/document_library/add_button.jsp

First check the guest view permissions on the folder in which the user is adding the document, using the following code:


Role guestRole = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), RoleConstants.GUEST);
ResourcePermission folderGuestPermission = ResourcePermissionLocalServiceUtil.getResourcePermission(themeDisplay.getCompanyId(), DLFolder.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(folderId), guestRole.getRoleId());


Then, in the calls to the struts actions implementing the 'adds', insert the following (conditional) parameter:


<c:if test="<%= folderGuestPermission.hasActionId(ActionKeys.VIEW) %>">
	<portlet:param name="inputPermissionsViewRole" value="<%= RoleConstants.GUEST %>" />
</c:if>


The inputPermissionsViewRole is used in the <liferay-ui:input-permissions> tag to select the default entry when assigning the view permissions.

Thanks to Nicolas Parvais for helping me find and implement this solution.

Alain
thumbnail
Rob Caljouw, modificado 11 Anos atrás.

RE: Change the default permission for documents

New Member Postagens: 14 Data de Entrada: 03/06/09 Postagens Recentes
Hi Alain,

I'm trying to accomplish the same thing you described but I'm having trouble with the JSP hook, it's throwing a NoSuchResourcePermissionException.

I was wondering if you would be so kind as to share your implementation of add_button.jsp so I can see where I'm going wrong. I'm running 6.1 GA1 if that makes a difference.

Thank you and best regards.

Rob
thumbnail
Alain Dresse, modificado 11 Anos atrás.

RE: Change the default permission for documents

Junior Member Postagens: 95 Data de Entrada: 18/07/11 Postagens Recentes
Hi Rob,

I don't have the file at hand: there were side effects of my approach (or implementation) that I didn't have the time to solve, and we decided to postpone this and to rely on users to set the permissions correctly.

Since then, we have moved from svn to git for our source code control, and didn't import the history, so I'm afraid I can't send you the file...

Best regards,
Alain
thumbnail
Rob Caljouw, modificado 11 Anos atrás.

RE: Change the default permission for documents

New Member Postagens: 14 Data de Entrada: 03/06/09 Postagens Recentes
Hi Alain,

thanks for the response, I appreciate it. I'll likely take the same approach for now.

Best regards.

Rob
thumbnail
Esa Hekmat, modificado 11 Anos atrás.

RE: Change the default permission for documents

New Member Postagens: 13 Data de Entrada: 13/03/12 Postagens Recentes
I finally solve the problem.
to show the input permission tag value as it's parent folder permission I wrote a hook which override add_button.jsp.
the point is input permission tag parameters which set it's value. as Alain said inputPermissionsViewRole set the role which has access to view the document or folder
I found some additional parameters for advanced permission setting feature, guestPermissions and groupPermissions.
I summarize the solution:
1. define a list of all action keys you want to inherent


	//list of all actions inherit by subFolder or Documents
	List<string> supportedActions = new ArrayList<string>();
	supportedActions.add(ActionKeys.ACCESS);
	supportedActions.add(ActionKeys.UPDATE);
	supportedActions.add(ActionKeys.PERMISSIONS);
	supportedActions.add(ActionKeys.DELETE);
	supportedActions.add(ActionKeys.ADD_DOCUMENT);
	supportedActions.add(ActionKeys.ADD_SHORTCUT);
	supportedActions.add(ActionKeys.ADD_SUBFOLDER);
	supportedActions.add(ActionKeys.ADD_DISCUSSION);
	supportedActions.add(ActionKeys.DELETE_DISCUSSION);

</string></string>


2. fetch the parent folder permissions

	//permissions of the parrentFolder as a list for all roles
	List<resourcepermission> parrentFolderPermissions = null;
	try {
		parrentFolderPermissions = ResourcePermissionLocalServiceUtil
				.getResourcePermissions(themeDisplay.getCompanyId(),
						DLFolder.class.getName(),
						ResourceConstants.SCOPE_INDIVIDUAL,
						String.valueOf(folderId));
	} catch (Exception e) {
		e.printStackTrace();
	}
</resourcepermission>

3.adding additonal parameter to all section you want to inherent permission from parent folder. for example for subfolder I use this code:

<portlet:renderurl var="addFolderURL">
			<portlet:param name="struts_action" value="/document_library/edit_folder" />
			<portlet:param name="redirect" value="<%=currentURL%>" />
			<portlet:param name="repositoryId" value="<%=String.valueOf(repositoryId)%>" />
			<portlet:param name="parentFolderId" value="<%=String.valueOf(folderId)%>" />

			&lt;%--additional Parameter for Document inheritance --%&gt;

			&lt;%-- set the viewable part of permission input --%&gt;
			&lt;%
				for (ResourcePermission rp : parrentFolderPermissions) {
			%&gt;
			<c:if test="<%=rp.hasActionId(ActionKeys.VIEW)%>">
				<portlet:param name="inputPermissionsViewRole" value="<%=RoleLocalServiceUtil.getRole(
										rp.getRoleId()).getName()%>" />

			</c:if>

			&lt;%--set checkBoxes --%&gt;
			&lt;%
				for (String action : supportedActions) {
			%&gt;
			<c:if test="<%=rp.hasActionId(action)%>">
				<c:if test="<%=RoleLocalServiceUtil
												.getRole(rp.getRoleId())
												.getName()
												.equals(RoleConstants.GUEST)%>">
					<portlet:param name="guestPermissions" value="<%=action%>" />
				</c:if>
				<c:if test="<%=!RoleLocalServiceUtil
												.getRole(rp.getRoleId())
												.getName()
												.equals(RoleConstants.GUEST)%>">
					<portlet:param name="groupPermissions" value="<%=action%>" />
				</c:if>
			</c:if>
			&lt;%
				}

							}
			%&gt;
			&lt;%--end of additonal parameters --%&gt;
		</portlet:renderurl>
Armando Ramirez, modificado 7 Anos atrás.

RE: Change the default permission for documents

New Member Postagens: 14 Data de Entrada: 05/10/16 Postagens Recentes
it's working, that's great! thank you, Finally I find it