1 /**
2 * Copyright 2004-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.hr.time.authorization;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.time.roles.UserRoles;
20 import org.kuali.hr.time.util.TKContext;
21 import org.kuali.hr.time.util.TkConstants;
22
23 public class AuthorizationValidationUtils {
24
25 /**
26 * Indicates whether or not the current user can wildcard the work area
27 * of the specified DepartmentalRule.
28 *
29 * @param dr The DepartmentalRule we are investigating.
30 *
31 * @return true if you can wildcard the WorkArea, false otherwise.
32 */
33 public static boolean canWildcardWorkArea(DepartmentalRule dr) {
34 // Sysadmins and (Departmental OrgAdmins for their Department)
35 if (TKContext.getUser().isSystemAdmin())
36 return true;
37
38 String dept = dr.getDept();
39 if (StringUtils.equals(dept, TkConstants.WILDCARD_CHARACTER)) {
40 // Only system administrators can wildcard the work area if the
41 // department also has a wildcard.
42 return TKContext.getUser().isSystemAdmin();
43 } else {
44 return TKContext.getUser().getDepartmentAdminAreas().contains(dept);
45 }
46 }
47
48 /**
49 * Can the current user use a wildcard for the department?
50 *
51 * @param dr The DepartmentalRule we are examining.
52 *
53 * @return true if so, false otherwise.
54 */
55 public static boolean canWildcardDepartment(DepartmentalRule dr) {
56 return TKContext.getUser().isSystemAdmin();
57 }
58 }