001    /*
002     * Copyright 2011 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.kfs.sys.document.authorization;
017    
018    import java.util.List;
019    import java.util.Set;
020    
021    import org.kuali.kfs.sys.businessobject.AccountingLine;
022    import org.kuali.kfs.sys.document.AccountingDocument;
023    import org.kuali.kfs.sys.document.web.AccountingLineRenderingContext;
024    import org.kuali.kfs.sys.document.web.AccountingLineViewAction;
025    import org.kuali.rice.kim.bo.Person;
026    
027    /**
028     * Methods used to determine certain permissions associated with an accounting line.
029     */
030    public interface AccountingLineAuthorizer {
031    
032        /**
033         * Determines which, if any, blocks whose children elements should not in any fashion be rendered
034         * 
035         * @param accountingDocument the accounting document the line to authorize is owned by
036         * @param accountingLine the accounting line that is being authorized against
037         * @param newLine whether the line is a new line or not
038         * @return a Set of the names of blocks that should not being in any way rendered
039         */
040        public abstract Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser);
041    
042        /**
043         * Determines what actions are available to act upon the given accounting line
044         * 
045         * @param accountingDocument the accounting document the line to authorize is owned by
046         * @param accountingLineRenderingContext a renderable context wrapping the accounting line that is being authorized against
047         * @param accountingLinePropertyName the name of the property that represents the accounting line
048         * @param lineIndex value, as Integer, of the index of the given accounting line within the group's collection of accounting
049         *        lines; if null, then it is assumed that this is a new line
050         * @param groupTitle title of the group from the data dictionary
051         * @return a List of the Actions that are available for this line
052         */
053        public abstract List<AccountingLineViewAction> getActions(AccountingDocument accountingDocument, AccountingLineRenderingContext accountingLineRenderingContext, String accountingLinePropertyName, Integer lineIndex, Person currentUser, String groupTitle);
054    
055        /**
056         * Determines if new lines should be rendered for the given accounting line group (identified by its property name)
057         * 
058         * @param accountingDocument the document that has accounting lines being authorized
059         * @param accountingGroupProperty the property of this accounting group
060         * @return true if new lines should be displayed, false otherwise
061         */
062        public abstract boolean renderNewLine(AccountingDocument accountingDocument, String accountingGroupProperty);
063    
064        /**
065         * Determines if any entire group is rendered as editable, which means that a new line will appear
066         * 
067         * @param accountingDocument the accounting document which the collection of line are on
068         * @param accountingLineRenderingContexts the accounting lines of the group, wrapped in AccountingLineRenderingContext implementations
069         * @param currentUser the current user
070         * @return true if the group can be edited, false otherwise
071         */
072        public abstract boolean isGroupEditable(AccountingDocument accountingDocument, List<? extends AccountingLineRenderingContext> accountingLineRenderingContexts, Person currentUser);
073    
074        /**
075         * determine whether the current user has permission to edit the given field in the given accounting line
076         * 
077         * @param accountingDocument the given accounting document
078         * @param accountingLine the given accounting line in the document
079         * @param accountingLineCollectionProperty the property of the collection the given accounting line is in
080         * @param fieldName the name of a field in the given accounting line
081         * @param editableLine whether the parent line of this field is editable
082         * @param editablePage whether the parent page of this field is editable
083         * @param currentUser the current user
084         * @return true if the the current user has permission to edit the given field in the given accounting line; otherwsie, false
085         */
086        public abstract boolean hasEditPermissionOnField(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, String fieldName, boolean editableLine, boolean editablePage, Person currentUser);
087        
088        /**
089         * determine whether the current user has permission to edit the given accounting line as a whole
090         * 
091         * @param accountingDocument the given accounting document
092         * @param accountingLine the given accounting line in the document
093         * @param accountingLineCollectionProperty the property of the group that holds these accounting lines
094         * @param currentUser the current user
095         * @param pageIsEditable whether the current page is editable by the current user or not
096         * @return true if the the current user has permission to edit the given accounting line; otherwsie, false
097         */
098        public abstract boolean hasEditPermissionOnAccountingLine(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, Person currentUser, boolean pageIsEditable);
099    }