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.TKUser;
022 import org.kuali.hr.time.util.TkConstants;
023
024 public class AuthorizationValidationUtils {
025
026 /**
027 * Indicates whether or not the current user can wildcard the work area
028 * of the specified DepartmentalRule.
029 *
030 * @param dr The DepartmentalRule we are investigating.
031 *
032 * @return true if you can wildcard the WorkArea, false otherwise.
033 */
034 public static boolean canWildcardWorkArea(DepartmentalRule dr) {
035 // Sysadmins and (Departmental OrgAdmins for their Department)
036 if (TKUser.isSystemAdmin())
037 return true;
038
039 String dept = dr.getDept();
040 if (StringUtils.equals(dept, TkConstants.WILDCARD_CHARACTER)) {
041 // Only system administrators can wildcard the work area if the
042 // department also has a wildcard.
043 return TKUser.isSystemAdmin();
044 } else {
045 return TKUser.getDepartmentAdminAreas().contains(dept);
046 }
047 }
048
049 /**
050 * Can the current user use a wildcard for the department?
051 *
052 * @param dr The DepartmentalRule we are examining.
053 *
054 * @return true if so, false otherwise.
055 */
056 public static boolean canWildcardDepartment(DepartmentalRule dr) {
057 return TKUser.isSystemAdmin();
058 }
059 }