001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.authorization; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.hr.time.roles.UserRoles; 020 import org.kuali.hr.time.util.TKContext; 021 import org.kuali.hr.time.util.TkConstants; 022 023 public class AuthorizationValidationUtils { 024 025 /** 026 * Indicates whether or not the current user can wildcard the work area 027 * of the specified DepartmentalRule. 028 * 029 * @param dr The DepartmentalRule we are investigating. 030 * 031 * @return true if you can wildcard the WorkArea, false otherwise. 032 */ 033 public static boolean canWildcardWorkArea(DepartmentalRule dr) { 034 // Sysadmins and (Departmental OrgAdmins for their Department) 035 if (TKContext.getUser().isSystemAdmin()) 036 return true; 037 038 String dept = dr.getDept(); 039 if (StringUtils.equals(dept, TkConstants.WILDCARD_CHARACTER)) { 040 // Only system administrators can wildcard the work area if the 041 // department also has a wildcard. 042 return TKContext.getUser().isSystemAdmin(); 043 } else { 044 return TKContext.getUser().getDepartmentAdminAreas().contains(dept); 045 } 046 } 047 048 /** 049 * Can the current user use a wildcard for the department? 050 * 051 * @param dr The DepartmentalRule we are examining. 052 * 053 * @return true if so, false otherwise. 054 */ 055 public static boolean canWildcardDepartment(DepartmentalRule dr) { 056 return TKContext.getUser().isSystemAdmin(); 057 } 058 }