Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Ticket #804: openmrs-804.patch

File openmrs-804.patch, 10.6 kB (added by bwolfe, 2 months ago)
  • /home/ben/workspace/openmrs-trunk/metadata/api/hibernate/org/openmrs/api/db/hibernate/PersonAttributeType.hbm.xml

    old new  
    4545                        column="retire_reason" length="255" /> 
    4646                <property name="retired" type="boolean" column="retired" 
    4747                        length="1" not-null="true" /> 
    48  
     48                         
     49                <property name="editPrivilege" type="java.lang.String" column="edit_privilege" 
     50                        length="50" /> 
    4951        </class> 
    5052         
    5153</hibernate-mapping> 
  • /home/ben/workspace/openmrs-trunk/metadata/model/update-to-latest-db.mysqldiff.sql

    old new  
    12131213call diff_procedure('1.4.0.02'); 
    12141214 
    12151215 
     1216#---------------------------------------- 
     1217# OpenMRS Datamodel version 1.4.0.03 
     1218# Upul Godage               July 4, 2008 
     1219# Adding edit_privilege column to PersonAttributeType 
     1220#---------------------------------------- 
     1221 
     1222DROP PROCEDURE IF EXISTS diff_procedure; 
     1223 
     1224delimiter // 
     1225 
     1226CREATE PROCEDURE diff_procedure (IN new_db_version VARCHAR(10)) 
     1227 BEGIN 
     1228    IF (SELECT REPLACE(property_value, '.', '0') < REPLACE(new_db_version, '.', '0') FROM global_property WHERE property = 'database_version') THEN 
     1229    SELECT CONCAT('Updating to ', new_db_version) AS 'Datamodel Update:' FROM dual; 
     1230 
     1231        ALTER TABLE `person_attribute_type` ADD COLUMN `edit_privilege` varchar(255) default NULL; 
     1232 
     1233        ALTER TABLE `person_attribute_type` ADD CONSTRAINT `privilege_which_can_edit` FOREIGN KEY (`edit_privilege`) REFERENCES `privilege` (`privilege`); 
     1234 
     1235    UPDATE `global_property` SET property_value=new_db_version WHERE property = 'database_version'; 
     1236     
     1237    END IF; 
     1238 END; 
     1239// 
     1240 
     1241delimiter ; 
     1242call diff_procedure('1.4.0.03'); 
     1243 
    12161244#----------------------------------- 
    12171245# Clean up - Keep this section at the very bottom of diff script 
    12181246#----------------------------------- 
  • /home/ben/workspace/openmrs-trunk/src/api/org/openmrs/PersonAttributeType.java

    old new  
    4646        private Date dateRetired; 
    4747        private String retireReason; 
    4848         
     49        private String editPrivilege; 
     50         
    4951        /** default constructor */ 
    5052        public PersonAttributeType() {} 
    5153 
     
    308310        public String toString() { 
    309311                return this.name; 
    310312        } 
     313 
     314        public String getEditPrivilege() { 
     315        return editPrivilege; 
     316    } 
     317 
     318        public void setEditPrivilege(String editPrivilege) { 
     319                if("".equals(editPrivilege)) { 
     320                        this.editPrivilege = null; 
     321                } else { 
     322                        this.editPrivilege = editPrivilege; 
     323                } 
     324    } 
    311325         
    312326} 
  • /home/ben/workspace/openmrs-trunk/src/web/org/openmrs/web/controller/person/PersonAttributeTypeFormController.java

    old new  
    1313 */ 
    1414package org.openmrs.web.controller.person; 
    1515 
     16import java.util.ArrayList; 
     17import java.util.HashMap; 
     18import java.util.List; 
     19import java.util.Map; 
     20 
    1621import javax.servlet.ServletException; 
    1722import javax.servlet.http.HttpServletRequest; 
    1823import javax.servlet.http.HttpServletResponse; 
     
    2126import org.apache.commons.logging.Log; 
    2227import org.apache.commons.logging.LogFactory; 
    2328import org.openmrs.PersonAttributeType; 
     29import org.openmrs.Privilege; 
    2430import org.openmrs.api.PersonService; 
    2531import org.openmrs.api.context.Context; 
    2632import org.openmrs.web.WebConstants; 
     
    2632import org.openmrs.web.WebConstants; 
    2733import org.springframework.beans.propertyeditors.CustomNumberEditor; 
    2834import org.springframework.validation.BindException; 
     35import org.springframework.validation.Errors; 
    2936import org.springframework.web.bind.ServletRequestDataBinder; 
    3037import org.springframework.web.servlet.ModelAndView; 
    3138import org.springframework.web.servlet.mvc.SimpleFormController; 
     
    97104        return attrType; 
    98105    } 
    99106     
     107        protected Map referenceData(HttpServletRequest request, Object obj, 
     108                        Errors errors) throws Exception { 
     109 
     110                Map<String, Object> map = new HashMap<String, Object>(); 
     111 
     112                List<Privilege> privileges = new ArrayList<Privilege>(); 
     113 
     114                if (Context.isAuthenticated()) { 
     115                        privileges = Context.getUserService().getAllPrivileges(); 
     116                } 
     117 
     118                map.put("privileges", privileges); 
     119 
     120                return map; 
     121        }     
    100122} 
  • /home/ben/workspace/openmrs-trunk/web/WEB-INF/messages.properties

    old new  
    11501150PersonAttributeType.user.listing.help=Attributes shown when users are displayed in a list 
    11511151PersonAttributeType.user.viewing=User Viewing Attributes 
    11521152PersonAttributeType.user.viewing.help=Attributes shown when viewing a user's metadata 
    1153  
    1154  
     1153PersonAttributeType.editPrivilege=Edit privilege 
     1154PersonAttributeType.editPrivilege.help=The privilege needed by a user to edit this person attribute 
    11551155 
    11561156PersonAttributeType.Mother'sName=Mother's Name 
    11571157PersonAttributeType.HealthCenter=Health Center 
  • /home/ben/workspace/openmrs-trunk/web/WEB-INF/view/admin/person/include/editPersonInfo.jsp

    old new  
    166166                </td> 
    167167        </tr> 
    168168</c:if> 
     169 
    169170<openmrs:forEachDisplayAttributeType personType="" displayType="all" var="attrType"> 
    170         <tr> 
    171                 <td><spring:message code="PersonAttributeType.${fn:replace(attrType.name, ' ', '')}" text="${attrType.name}"/></td> 
    172                 <td> 
    173                         <spring:bind path="attributeMap"> 
    174                                 <openmrs:fieldGen  
    175                                         type="${attrType.format}"  
    176                                         formFieldName="${attrType.personAttributeTypeId}"  
    177                                         val="${status.value[attrType.name].hydratedObject}"  
    178                                         parameters="optionHeader=[blank]|showAnswers=${attrType.foreignKey}" /> 
    179                         </spring:bind> 
    180                 </td> 
    181         </tr> 
     171        <c:set var="authorized" value="false" /> 
     172        <c:choose> 
     173                <c:when test="${not empty attrType.editPrivilege}"> 
     174                        <openmrs:hasPrivilege privilege="${attrType.editPrivilege}"> 
     175                                <c:set var="authorized" value="true" /> 
     176                        </openmrs:hasPrivilege> 
     177                </c:when> 
     178                 
     179                <c:otherwise> 
     180                        <c:set var="authorized" value="true" /> 
     181                </c:otherwise> 
     182        </c:choose> 
     183 
     184        <c:choose> 
     185                <c:when test="${authorized == true}"> 
     186                        <tr> 
     187                                <td><spring:message code="PersonAttributeType.${fn:replace(attrType.name, ' ', '')}" text="${attrType.name}"/></td> 
     188                                <td> 
     189                                        <spring:bind path="attributeMap"> 
     190                                                <openmrs:fieldGen  
     191                                                        type="${attrType.format}"  
     192                                                        formFieldName="${attrType.personAttributeTypeId}"  
     193                                                        val="${status.value[attrType.name].hydratedObject}"  
     194                                                        parameters="optionHeader=[blank]|showAnswers=${attrType.foreignKey}" /> 
     195                                        </spring:bind> 
     196                                </td> 
     197                        </tr> 
     198                </c:when> 
     199                 
     200                <c:otherwise> 
     201                        <td><spring:message code="PersonAttributeType.${fn:replace(attrType.name, ' ', '')}" text="${attrType.name}"/></td> 
     202                        <td><spring:bind path="attributeMap">${status.value[attrType.name].hydratedObject}</spring:bind></td>            
     203                </c:otherwise> 
     204        </c:choose> 
     205 
    182206</openmrs:forEachDisplayAttributeType> 
     207 
    183208<tr> 
    184209        <td><spring:message code="Person.dead"/></td> 
    185210        <td> 
  • /home/ben/workspace/openmrs-trunk/web/WEB-INF/view/admin/person/personAttributeTypeForm.jsp

    old new  
    6060                        </spring:bind> 
    6161                </td> 
    6262        </tr> 
     63        <tr> 
     64                <td><spring:message code="PersonAttributeType.editPrivilege"/></td> 
     65                <td> 
     66                        <spring:bind path="personAttributeType.editPrivilege"> 
     67                                <select name="editPrivilege"> 
     68                                        <option value=""></option> 
     69                                        <c:forEach items="${privileges}" var="privilege"> 
     70                                                <option value="${privilege.privilege}" <c:if test="${privilege.privilege == status.value}">selected</c:if>>${privilege.privilege}</option> 
     71                                        </c:forEach> 
     72                                </select> 
     73                                <c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if> 
     74                        </spring:bind> 
     75                </td> 
     76                <td><i><spring:message code="PersonAttributeType.editPrivilege.help"/></i></td> 
     77        </tr>    
    6378        <c:if test="${personAttributeType.creator != null}"> 
    6479                <tr> 
    6580                        <td><spring:message code="general.createdBy" /></td> 
  • /home/ben/workspace/openmrs-trunk/web/WEB-INF/view/admin/person/personAttributeTypeList.jsp

    old new  
    2020                        <th> <spring:message code="PersonAttributeType.format"/> </th> 
    2121                        <th> <spring:message code="PersonAttributeType.searchable"/> </th> 
    2222                        <th> <spring:message code="general.description"/> </th> 
     23                        <th> <spring:message code="PersonAttributeType.editPrivilege"/> </th> 
    2324                </tr> 
    2425                <c:forEach var="personAttributeType" items="${personAttributeTypeList}"> 
    2526                        <tr> 
     
    3132                                <td valign="top">${personAttributeType.format}</td> 
    3233                                <td valign="top"><c:if test="${personAttributeType.searchable == true}"><spring:message code="general.yes"/></c:if></td> 
    3334                                <td valign="top">${personAttributeType.description}</td> 
     35                                <td valign="top">${personAttributeType.editPrivilege}</td> 
    3436                        </tr> 
    3537                </c:forEach> 
    3638        </table>