Skip to content

Commit b4f86c4

Browse files
committed
LUT-27605 : check access form within workgroup control with single function
1 parent df6e622 commit b4f86c4

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/java/fr/paris/lutece/plugins/forms/service/FormsMultiviewAuthorizationService.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
import fr.paris.lutece.portal.service.admin.AdminUserService;
5656
import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
5757
import fr.paris.lutece.plugins.forms.business.Form;
58-
import fr.paris.lutece.plugins.forms.business.FormResponse;
59-
import fr.paris.lutece.plugins.forms.business.FormResponseHome;
60-
import fr.paris.lutece.plugins.forms.business.FormHome;
6158

6259
import java.util.HashMap;
6360
import java.util.Map;
@@ -123,17 +120,28 @@ public boolean isUserAuthorizedOnFormResponse( HttpServletRequest request, int n
123120
List<Integer> listIdFormResponse = listFormResponseItem.stream( ).map( FormResponseItem::getIdFormResponse ).collect( Collectors.toList( ) );
124121
bIsUserAuthorizedOnFormResponse = listIdFormResponse.contains( nIdFormResponse );
125122
}
126-
if(bIsUserAuthorizedOnFormResponse) {
127-
User user = AdminUserService.getAdminUser(request);
128-
FormResponse formResponse = FormResponseHome.findByPrimaryKey(nIdFormResponse);
129-
Form form = FormHome.findByPrimaryKey(formResponse.getFormId());
130-
bIsUserAuthorizedOnFormResponse = AdminWorkgroupService.isAuthorized(form, user);
131-
}
132123
}
133124

134125
return bIsUserAuthorizedOnFormResponse;
135126
}
136127

128+
/**
129+
* Check if the user is authorized to access the form response within workgroup constraints
130+
*
131+
* @param request
132+
* The request to use to determine if the user can access the details of the given form response
133+
* @param form
134+
* The Form
135+
* @return true if the user is authorized to access the form response, false otherwise
136+
*/
137+
@Override
138+
public boolean isUserAuthorizedOnFormResponseWithinWorkgroup(HttpServletRequest request, Form form)
139+
{
140+
User user = AdminUserService.getAdminUser(request);
141+
return AdminWorkgroupService.isAuthorized(form, user);
142+
}
143+
144+
137145
/**
138146
* Build a form response id filter from an id response
139147
*

src/java/fr/paris/lutece/plugins/forms/service/IFormsMultiviewAuthorizationService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
package fr.paris.lutece.plugins.forms.service;
3535

3636
import javax.servlet.http.HttpServletRequest;
37+
import fr.paris.lutece.plugins.forms.business.Form;
3738

3839
/**
3940
* Forms service for managing the authorization on access form response from the multiview page
@@ -51,4 +52,7 @@ public interface IFormsMultiviewAuthorizationService
5152
* @return the boolean which tell if the connected user is authorized to access the form response or not
5253
*/
5354
boolean isUserAuthorizedOnFormResponse( HttpServletRequest request, int nIdFormResponse );
55+
56+
57+
boolean isUserAuthorizedOnFormResponseWithinWorkgroup(HttpServletRequest request, Form form);
5458
}

src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormResponseDetailsJspBean.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@
7777
import fr.paris.lutece.plugins.forms.web.form.response.view.FormResponseViewModelProcessorFactory;
7878
import fr.paris.lutece.plugins.forms.web.form.response.view.IFormResponseViewModelProcessor;
7979
import fr.paris.lutece.plugins.workflowcore.business.state.State;
80-
import fr.paris.lutece.portal.business.user.AdminUser;
8180
import fr.paris.lutece.portal.business.user.AdminUserHome;
8281
import fr.paris.lutece.portal.service.admin.AccessDeniedException;
83-
import fr.paris.lutece.portal.service.admin.AdminUserService;
8482
import fr.paris.lutece.portal.service.rbac.RBACService;
8583
import fr.paris.lutece.portal.service.security.SecurityTokenService;
8684
import fr.paris.lutece.portal.service.spring.SpringContextService;
@@ -178,7 +176,12 @@ public String getResponseDetails( HttpServletRequest request ) throws AccessDeni
178176
boolean bRBACAuthorization = RBACService.isAuthorized( Form.RESOURCE_TYPE, Integer.toString( formResponse.getFormId( ) ),
179177
FormsResourceIdService.PERMISSION_VIEW_FORM_RESPONSE, (User) getUser( ) );
180178
boolean bAuthorizedRecord = _formsMultiviewAuthorizationService.isUserAuthorizedOnFormResponse( request, nIdFormResponse );
181-
179+
if(bAuthorizedRecord)
180+
{
181+
int nIdForm = formResponse.getFormId( );
182+
Form form = FormHome.findByPrimaryKey(nIdForm);
183+
bAuthorizedRecord = _formsMultiviewAuthorizationService.isUserAuthorizedOnFormResponseWithinWorkgroup( request, form );
184+
}
182185
if ( !bRBACAuthorization || !bAuthorizedRecord )
183186
{
184187
throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );

0 commit comments

Comments
 (0)