View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.rice.kim.api.identity.Person;
5   import org.kuali.rice.kim.api.permission.PermissionService;
6   import org.kuali.rice.kim.api.services.KimApiServiceLocator;
7   import org.kuali.rice.krad.maintenance.MaintenanceViewAuthorizerBase;
8   import org.kuali.rice.krad.uif.field.Field;
9   import org.kuali.rice.krad.uif.view.View;
10  import org.kuali.rice.krad.uif.view.ViewModel;
11  import org.kuali.rice.krad.util.KRADConstants;
12  
13  /**
14   * OleLocationLevelAuthoriser  class authorises permission for Location Level Maintenance Document
15   */
16  public class OleLocationLevelAuthoriser extends MaintenanceViewAuthorizerBase {
17  
18      /**
19       * This method  is used to check whether that particular field is editable or not.
20       *
21       * @param view
22       * @param model
23       * @param field
24       * @param propertyName
25       * @param user
26       * @return boolean
27       */
28      @Override
29      public boolean canEditField(View view, ViewModel model, Field field, String propertyName, Person user) {
30          PermissionService service = KimApiServiceLocator.getPermissionService();
31          // Checking whether the user has permission
32          boolean canEdit = service.hasPermission(user.getPrincipalId(), KRADConstants.KRAD_NAMESPACE, OLEConstants.OleLocationLevel.EDIT_LOCATION_LEVEL_PERM);
33  
34          //for disabling the code and parent level id
35  
36          if (!field.getComponentSecurity().isEditAuthz() && field.getFieldLabel() != null && field.getFieldLabel().getLabelText() != null) {
37              String fieldName = field.getFieldLabel().getLabelText();
38              if (fieldName.equalsIgnoreCase(OLEConstants.OleLocationLevel.CODE) || fieldName.equalsIgnoreCase(OLEConstants.OleLocationLevel.PARENT_ID))
39                  return false;
40          } else if (field.getComponentSecurity().isEditAuthz() && canEdit) {
41              return true;
42          } else {
43              return false;
44          }
45          return true;
46      }
47  
48  }
49  
50