001    package org.kuali.ole.catalog.rule;
002    
003    import org.kuali.ole.OLEConstants;
004    import org.kuali.rice.kim.api.identity.Person;
005    import org.kuali.rice.kim.api.permission.PermissionService;
006    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
007    import org.kuali.rice.krad.maintenance.MaintenanceViewAuthorizerBase;
008    import org.kuali.rice.krad.uif.field.Field;
009    import org.kuali.rice.krad.uif.view.View;
010    import org.kuali.rice.krad.uif.view.ViewModel;
011    import org.kuali.rice.krad.util.KRADConstants;
012    
013    /**
014     * OleLocationLevelAuthoriser  class authorises permission for Location Level Maintenance Document
015     */
016    public class OleLocationLevelAuthoriser extends MaintenanceViewAuthorizerBase {
017    
018        /**
019         *  This method  is used to check whether that particular field is editable or not.
020         * @param view
021         * @param model
022         * @param field
023         * @param propertyName
024         * @param user
025         * @return boolean
026         */
027         @Override
028        public  boolean canEditField(View view, ViewModel model, Field field, String propertyName, Person user) {
029            PermissionService service= KimApiServiceLocator.getPermissionService();
030            // Checking whether the user has permission
031            boolean canEdit=service.hasPermission(user.getPrincipalId(),KRADConstants.KRAD_NAMESPACE, OLEConstants.OleLocationLevel.Edit_Location_Level_perm);
032    
033            //for disabling the code and parent level id
034    
035            if(!field.getComponentSecurity().isEditAuthz() && field.getFieldLabel()!=null && field.getFieldLabel().getLabelText()!=null){
036                    String fieldName = field.getFieldLabel().getLabelText();
037                        if(fieldName.equalsIgnoreCase(OLEConstants.OleLocationLevel.CODE) || fieldName.equalsIgnoreCase(OLEConstants.OleLocationLevel.PARENT_ID))
038                             return false;
039                             }
040            else if(field.getComponentSecurity().isEditAuthz() && canEdit){
041                return true;
042            }
043            else{
044                return false;
045            }
046            return true;
047        }
048    
049    }
050    
051