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 java.util.Map;
019    
020    import org.kuali.hr.time.roles.TkUserRoles;
021    import org.kuali.rice.kim.api.identity.Person;
022    import org.kuali.rice.krad.bo.BusinessObject;
023    import org.kuali.rice.krad.document.Document;
024    import org.kuali.rice.krad.maintenance.MaintenanceDocument;
025    import org.kuali.rice.krad.util.GlobalVariables;
026    
027    public class DepartmentAdminAuthorizer extends LocationAdminAuthorizer {
028            
029            public boolean isDepartmentAdmin(){
030                    return TkUserRoles.getUserRoles(GlobalVariables.getUserSession().getPrincipalId()).isDepartmentAdmin();
031            }
032            
033            @Override
034            public boolean canInitiate(String documentTypeName, Person user) {
035                    return super.canInitiate(documentTypeName, user) || isDepartmentAdmin();
036            }
037    
038            @Override
039            public boolean canOpen(Document document, Person user) {
040                    return super.canOpen(document, user) || isDepartmentAdmin();
041            }
042    
043            @Override
044            public boolean canReceiveAdHoc(Document document, Person user,
045                            String actionRequestCode) {
046                    return super.canReceiveAdHoc(document, user, actionRequestCode) || isDepartmentAdmin();
047            }
048    
049            @Override
050            public boolean canAddNoteAttachment(Document document,
051                            String attachmentTypeCode, Person user) {
052                    return super.canAddNoteAttachment(document, attachmentTypeCode, user) || isDepartmentAdmin();
053            }
054    
055            @Override
056            public boolean canDeleteNoteAttachment(Document document,
057                            String attachmentTypeCode, String createdBySelfOnly, Person user) {
058                    return super.canDeleteNoteAttachment(document, attachmentTypeCode, createdBySelfOnly, user) || isDepartmentAdmin();
059            }
060            
061            @Override
062            public boolean canViewNoteAttachment(Document document,
063                            String attachmentTypeCode, Person user) {
064                    return super.canViewNoteAttachment(document, attachmentTypeCode, user) || isDepartmentAdmin();
065            }
066    
067            @Override
068            public boolean canViewNoteAttachment(Document document, 
069                            String attachmentTypeCode, String authorUniversalIdentifier, Person user) {
070                    return super.canViewNoteAttachment(document, attachmentTypeCode, authorUniversalIdentifier, user) || isDepartmentAdmin();
071            }
072            
073            @Override
074            public boolean canSendAdHocRequests(Document document,
075                            String actionRequestCd, Person user) {
076                    return super.canSendAdHocRequests(document, actionRequestCd, user) || isDepartmentAdmin();
077            }
078    
079            @Override
080            public boolean isAuthorized(BusinessObject businessObject,
081                            String namespaceCode, String permissionName, String principalId) {
082                    return super.isAuthorized(businessObject, namespaceCode, permissionName, principalId) || isDepartmentAdmin();
083            }
084    
085            @Override
086            public boolean isAuthorizedByTemplate(BusinessObject businessObject,
087                            String namespaceCode, String permissionTemplateName,
088                            String principalId) {
089                    return super.isAuthorizedByTemplate(businessObject, namespaceCode, permissionTemplateName, principalId) || isDepartmentAdmin();
090            }
091    
092            @Override
093            public boolean isAuthorized(BusinessObject businessObject,
094                            String namespaceCode, String permissionName, String principalId,
095                            Map<String, String> additionalPermissionDetails,
096                            Map<String, String> additionalRoleQualifiers) {
097                    return super.isAuthorized(businessObject, namespaceCode, permissionName, principalId, additionalPermissionDetails, additionalRoleQualifiers) || isDepartmentAdmin();
098            }
099    
100            @Override
101            public boolean isAuthorizedByTemplate(Object dataObject,
102                            String namespaceCode, String permissionTemplateName,
103                            String principalId,
104                            Map<String, String> additionalPermissionDetails,
105                            Map<String, String> additionalRoleQualifiers) {
106                    return super.isAuthorizedByTemplate(dataObject, namespaceCode, permissionTemplateName, principalId) || isDepartmentAdmin();
107            }
108    
109            @Override
110            public boolean canCreate(Class boClass, Person user) {
111                    return super.canCreate(boClass, user) || isDepartmentAdmin();
112            }
113    
114            @Override
115            public boolean canMaintain(Object dataObject, Person user) {
116                    return super.canMaintain(dataObject, user) || isDepartmentAdmin();
117            }
118    
119            @Override
120            public boolean canCreateOrMaintain(MaintenanceDocument maintenanceDocument, 
121                            Person user) {
122                    return super.canCreateOrMaintain(maintenanceDocument, user) || isDepartmentAdmin();
123            }
124    
125            @Override
126            public boolean canEdit(Document document, Person user) {
127                    return super.canEdit(document, user) || isDepartmentAdmin();
128            }
129    
130            @Override
131            public boolean canAnnotate(Document document, Person user) {
132                    return super.canAnnotate(document, user) || isDepartmentAdmin();
133            }
134    
135            @Override
136            public boolean canReload(Document document, Person user) {
137                    return super.canReload(document, user) || isDepartmentAdmin();
138            }
139    
140            @Override
141            public boolean canClose(Document document, Person user) {
142                    return super.canClose(document, user) || isDepartmentAdmin();
143            }
144    
145            @Override
146            public boolean canSave(Document document, Person user) {
147                    return super.canSave(document, user) || isDepartmentAdmin();
148            }
149    
150            @Override
151            public boolean canRoute(Document document, Person user) {
152                    return super.canRoute(document, user) || isDepartmentAdmin();
153            }
154    
155            @Override
156            public boolean canCancel(Document document, Person user) {
157                    return super.canCancel(document, user) || isDepartmentAdmin();
158            }
159    
160            @Override
161            public boolean canCopy(Document document, Person user) {
162                    return super.canCopy(document, user) || isDepartmentAdmin();
163            }
164    
165            @Override
166            public boolean canPerformRouteReport(Document document, Person user) {
167                    return super.canCopy(document, user) || isDepartmentAdmin();
168            }
169    
170            @Override
171            public boolean canBlanketApprove(Document document, Person user) {
172                    return super.canBlanketApprove(document, user) || isDepartmentAdmin();
173            }
174    
175            @Override
176            public boolean canApprove(Document document, Person user) {
177                    return super.canApprove(document, user) || isDepartmentAdmin();
178            }
179    
180            @Override
181            public boolean canDisapprove(Document document, Person user) {
182                    return super.canDisapprove(document, user) || isDepartmentAdmin();
183            }
184    
185            @Override
186            public boolean canSendNoteFyi(Document document, Person user) {
187                    return super.canSendNoteFyi(document, user) || isDepartmentAdmin();
188            }
189    
190            @Override
191            public boolean canEditDocumentOverview(Document document, Person user) {
192                    return super.canEditDocumentOverview(document, user) || isDepartmentAdmin();
193            }
194    
195            @Override
196            public boolean canFyi(Document document, Person user) {
197                    return super.canFyi(document, user) || isDepartmentAdmin();
198            }
199    
200            @Override
201            public boolean canAcknowledge(Document document, Person user) {
202                    return super.canAcknowledge(document, user) || isDepartmentAdmin();
203            }
204    
205            @Override
206            public boolean canSendAnyTypeAdHocRequests(Document document, Person user) {
207                    return super.canSendAnyTypeAdHocRequests(document, user) || isDepartmentAdmin();
208            }
209    
210            @Override
211            public boolean canTakeRequestedAction(Document document,
212                            String actionRequestCode, Person user) {
213                    return super.canTakeRequestedAction(document, actionRequestCode, user) || isDepartmentAdmin();
214            }
215    
216            @Override
217            public boolean canRecall(Document document, Person user) {
218                    return super.canRecall(document, user) || isDepartmentAdmin();
219            }
220    
221            @Override
222            public boolean isAuthorized(Object dataObject, String namespaceCode,
223                            String permissionName, String principalId) {
224                    return super.isAuthorized(dataObject, namespaceCode, permissionName, principalId) || isDepartmentAdmin();
225            }
226    
227            @Override
228            public boolean isAuthorizedByTemplate(Object dataObject,
229                            String namespaceCode, String permissionTemplateName,
230                            String principalId) {
231                    return super.isAuthorizedByTemplate(dataObject, namespaceCode, permissionTemplateName, principalId) || isDepartmentAdmin();
232            }
233    
234            @Override
235            public boolean isAuthorized(Object dataObject, String namespaceCode,
236                            String permissionTemplateName, String principalId,
237                            Map<String, String> additionalPermissionDetails,
238                            Map<String, String> additionalRoleQualifiers) {
239                    return super.isAuthorizedByTemplate(dataObject, namespaceCode, permissionTemplateName, principalId, additionalPermissionDetails, additionalRoleQualifiers) || isDepartmentAdmin();
240            }
241    
242    }