------------------------------------------------------------ revno: 14754 committer: Lars Helge Ă˜verland <larshe...@gmail.com> branch nick: dhis2 timestamp: Tue 2014-04-08 21:36:25 +0200 message: Implemented function for constraining users on dimensions for analytics modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2014-04-08 18:25:25 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java 2014-04-08 19:36:25 +0000 @@ -98,6 +98,7 @@ /** * Category option group set dimensions to constrain data analytics aggregation. */ + @Scanned private Set<CategoryOptionGroupSet> cogsDimensionConstraints = new HashSet<CategoryOptionGroupSet>(); /** === modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2014-04-08 18:25:25 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2014-04-08 19:36:25 +0000 @@ -295,16 +295,13 @@ { User user = currentUserService.getCurrentUser(); - if ( params == null || user == null || user.getUserCredentials() == null ) - { - return; - } - - if ( !user.getUserCredentials().hasDimensionConstraints() ) - { - return; - } - + if ( params == null || user == null || + user.getUserCredentials() == null || !user.getUserCredentials().hasDimensionConstraints() ) + { + log.debug( "No dimension constraint applied" ); + return; + } + Set<DimensionalObject> dimensionConstraints = user.getUserCredentials().getDimensionConstraints(); for ( DimensionalObject dimension : dimensionConstraints ) @@ -338,7 +335,9 @@ DimensionalObject constraint = new BaseDimensionalObject( dimension.getDimension(), dimension.getDimensionType(), null, dimension.getDisplayName(), canReadItems ); - params.getFilters().add( constraint ); + params.getFilters().add( constraint ); + + log.info( "User: " + user.getUsername() + " constrained by dimension: " + constraint.getDimension() ); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2014-03-05 05:52:03 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/UserCredentials.hbm.xml 2014-04-08 19:36:25 +0000 @@ -33,7 +33,15 @@ <set name="userAuthorityGroups" table="userrolemembers" cascade="save-update"> <cache usage="read-write" /> <key column="userid" foreign-key="fk_userrolemembers_userid" /> - <many-to-many column="userroleid" class="org.hisp.dhis.user.UserAuthorityGroup" foreign-key="fk_userrolemembers_userroleid" /> + <many-to-many column="userroleid" class="org.hisp.dhis.user.UserAuthorityGroup" + foreign-key="fk_userrolemembers_userroleid" /> + </set> + + <set name="cogsDimensionConstraints" table="users_cogsdimensionconstraints"> + <cache usage="read-write" /> + <key column="userid" foreign-key="fk_users_cogsconstraints_userid" /> + <many-to-many column="categoryoptiongroupsetid" class="org.hisp.dhis.dataelement.CategoryOptionGroupSet" + foreign-key="fk_fk_users_cogsconstraints_categoryoptiongroupsetid" /> </set> <property name="lastLogin" /> === modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml' --- dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2014-04-06 09:44:34 +0000 +++ dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/ehcache.xml 2014-04-08 19:36:25 +0000 @@ -368,7 +368,9 @@ <cache name="org.hisp.dhis.user.UserGroup.userGroupAccesses" maxElementsInMemory="200" /> - <cache name="org.hisp.dhis.user.UserCredentials.userAuthorityGroups" maxElementsInMemory="200" /> + <cache name="org.hisp.dhis.user.UserCredentials.userAuthorityGroups" maxElementsInMemory="2000" /> + + <cache name="org.hisp.dhis.user.UserCredentials.cogsDimensionConstraints" maxElementsInMemory="2000" /> <cache name="org.hisp.dhis.user.UserAuthorityGroup.authorities" maxElementsInMemory="500" /> === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2014-04-06 12:57:33 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2014-04-08 19:36:25 +0000 @@ -28,11 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.google.common.collect.Lists; -import com.opensymphony.xwork2.Action; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.struts2.ServletActionContext; import org.hisp.dhis.api.utils.ContextUtils; import org.hisp.dhis.attribute.AttributeService; +import org.hisp.dhis.dataelement.CategoryOptionGroupSet; +import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.oust.manager.SelectionTreeManager; import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; @@ -52,9 +57,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.opensymphony.xwork2.Action; /** * @author Torgeir Lorange Ostby @@ -89,9 +92,6 @@ this.userService = userService; } - @Autowired - private UserGroupService userGroupService; - private SecurityService securityService; public void setSecurityService( SecurityService securityService ) @@ -113,6 +113,12 @@ this.attributeService = attributeService; } + @Autowired + private UserGroupService userGroupService; + + @Autowired + private DataElementCategoryService categoryService; + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -213,20 +219,27 @@ this.localeDb = localeDb; } - private List<String> urSelected = Lists.newArrayList(); + private List<String> urSelected = new ArrayList<String>(); public void setUrSelected( List<String> urSelected ) { this.urSelected = urSelected; } - private List<String> ugSelected = Lists.newArrayList(); + private List<String> ugSelected = new ArrayList<String>(); public void setUgSelected( List<String> ugSelected ) { this.ugSelected = ugSelected; } + private List<String> dcSelected = new ArrayList<String>(); + + public void setDcSelected( List<String> dcSelected ) + { + this.dcSelected = dcSelected; + } + private List<String> jsonAttributeValues; public void setJsonAttributeValues( List<String> jsonAttributeValues ) @@ -315,6 +328,16 @@ userCredentials.setUserAuthorityGroups( userAuthorityGroups ); + // --------------------------------------------------------------------- + // Dimension constraints + // --------------------------------------------------------------------- + + for ( String id : dcSelected ) + { + CategoryOptionGroupSet cogs = categoryService.getCategoryOptionGroupSet( id ); + userCredentials.getCogsDimensionConstraints().add( cogs ); + } + userService.addUser( user ); userService.addUserCredentials( userCredentials ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2014-04-06 12:57:33 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2014-04-08 19:36:25 +0000 @@ -28,9 +28,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.google.common.collect.Lists; -import com.opensymphony.xwork2.Action; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.hisp.dhis.attribute.AttributeService; +import org.hisp.dhis.dataelement.CategoryOptionGroupSet; +import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.oust.manager.SelectionTreeManager; import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; @@ -49,9 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.opensymphony.xwork2.Action; /** * @author Torgeir Lorange Ostby @@ -70,9 +73,6 @@ this.userService = userService; } - @Autowired - private UserGroupService userGroupService; - private PasswordManager passwordManager; public void setPasswordManager( PasswordManager passwordManager ) @@ -108,6 +108,12 @@ this.attributeService = attributeService; } + @Autowired + private UserGroupService userGroupService; + + @Autowired + private DataElementCategoryService categoryService; + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -175,20 +181,27 @@ this.localeDb = localeDb; } - private List<String> urSelected = Lists.newArrayList(); + private List<String> urSelected = new ArrayList<String>(); public void setUrSelected( List<String> urSelected ) { this.urSelected = urSelected; } - private List<String> ugSelected = Lists.newArrayList(); + private List<String> ugSelected = new ArrayList<String>(); public void setUgSelected( List<String> ugSelected ) { this.ugSelected = ugSelected; } + private List<String> dcSelected = new ArrayList<String>(); + + public void setDcSelected( List<String> dcSelected ) + { + this.dcSelected = dcSelected; + } + private List<String> jsonAttributeValues; public void setJsonAttributeValues( List<String> jsonAttributeValues ) @@ -270,6 +283,18 @@ userCredentials.setUserAuthorityGroups( userAuthorityGroups ); + // --------------------------------------------------------------------- + // Dimension constraints + // --------------------------------------------------------------------- + + userCredentials.getCogsDimensionConstraints().clear(); + + for ( String id : dcSelected ) + { + CategoryOptionGroupSet cogs = categoryService.getCategoryOptionGroupSet( id ); + userCredentials.getCogsDimensionConstraints().add( cogs ); + } + userService.updateUserCredentials( userCredentials ); userService.updateUser( user ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-04-08 11:37:59 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2014-04-08 19:36:25 +0000 @@ -326,4 +326,8 @@ enable=Enable data_capture_maintenance_org_units=Data capture and maintenance organisation units data_output_analysis_org_units=Data output and analysis organisation units -data_capture_organisation_unit_required_for_user=User must be assigned to at least one data capture organisation unit \ No newline at end of file +data_capture_organisation_unit_required_for_user=User must be assigned to at least one data capture organisation unit +available_dimension_restrictions_for_data_analytics=Available dimension restrictions for data analytics +selected_dimension_restrictions_for_data_analytics=Selected dimension restrictions for data analytics +show_more_options=Show more options +show_less_options=Show less options \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm 2014-04-07 02:08:51 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm 2014-04-08 19:36:25 +0000 @@ -3,6 +3,7 @@ validation2('addUserForm', function( form ) { jQuery("#urSelected").children().attr("selected", "selected"); jQuery("#ugSelected").children().attr("selected", "selected"); + jQuery("#dcSelected").children().attr("selected", "selected"); if( $('#orgUnitTree').find('.selected').size() == 0 ) { setHeaderDelayMessage('$encoder.jsEncode( $i18n.getString( "data_capture_organisation_unit_required_for_user" ) )'); @@ -41,6 +42,13 @@ search: $('#ugAvailableSearch'), iterator: 'userGroups' }); + + $('#dcAvailable').selected({ + url: '../api/categoryOptionGroupSets.json', + target: $('#dcSelected'), + search: $('#dcAvailableSearch'), + iterator: 'categoryOptionGroupSets' + }); }); </script> @@ -160,13 +168,7 @@ "i18n_selected": "selected_roles" }) -#jqSelected({ - "prefix": "ug", - "i18n_available": "available_user_groups", - "i18n_selected": "selected_user_groups" -}) - -<table> +<table style="margin-bottom: 20px;"> <tr> <th>$i18n.getString( "data_capture_maintenance_org_units" )</th> <th></th> @@ -183,6 +185,26 @@ </tr> </table> +<div id="showMoreOptions" style="margin-bottom: 20px;"><a href="javascript:showUserOptions()">$i18n.getString( "show_more_options" )</a></div> + +<div id="moreOptions" style="display:none"> + +#jqSelected({ + "prefix": "ug", + "i18n_available": "available_user_groups", + "i18n_selected": "selected_user_groups" +}) + +#jqSelected({ + "prefix": "dc", + "i18n_available": "available_dimension_restrictions_for_data_analytics", + "i18n_selected": "selected_dimension_restrictions_for_data_analytics" +}) + +<div id="showLessOptions" style="margin-bottom: 20px;"><a href="javascript:showUserOptions()">$i18n.getString( "show_less_options" )</a></div> + +</div> + <p> <input type="submit" value="$i18n.getString( 'add' )" style="width:10em" /> <input type="button" id="cancel" value="$i18n.getString( 'cancel' )" style="width:10em" /> === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2014-02-14 14:09:37 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2014-04-08 19:36:25 +0000 @@ -156,3 +156,9 @@ }); } } + +function showUserOptions() +{ + $( "#showMoreOptions" ).toggle(); + $( "#moreOptions" ).toggle(); +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm 2014-04-07 07:19:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm 2014-04-08 19:36:25 +0000 @@ -8,6 +8,7 @@ validation2('updateUserForm', function( form ) { jQuery("#urSelected").children().attr("selected", "selected"); jQuery("#ugSelected").children().attr("selected", "selected"); + jQuery("#dcSelected").children().attr("selected", "selected"); if( $('#orgUnitTree').find('.selected').size() == 0 ) { setHeaderDelayMessage('$i18n.getString( "data_capture_organisation_unit_required_for_user" )'); @@ -49,6 +50,13 @@ search: $('#ugAvailableSearch'), iterator: 'userGroups' }); + + $('#dcAvailable').selected({ + url: '../api/categoryOptionGroupSets.json', + target: $('#dcSelected'), + search: $('#dcAvailableSearch'), + iterator: 'categoryOptionGroupSets' + }); }); </script> @@ -153,14 +161,7 @@ "objects": $userCredentials.userAuthorityGroups }) -#jqSelected({ - "prefix": "ug", - "i18n_available": "available_user_groups", - "i18n_selected": "selected_user_groups", - "objects": $user.groups -}) - -<table> +<table style="margin-bottom: 20px;"> <tr> <th>$i18n.getString( "data_capture_maintenance_org_units" )</th> <th></th> @@ -177,6 +178,28 @@ </tr> </table> +<div id="showMoreOptions" style="margin-bottom: 20px;"><a href="javascript:showUserOptions()">$i18n.getString( "show_more_options" )</a></div> + +<div id="moreOptions" style="display:none"> + +#jqSelected({ + "prefix": "ug", + "i18n_available": "available_user_groups", + "i18n_selected": "selected_user_groups", + "objects": $user.groups +}) + +#jqSelected({ + "prefix": "dc", + "i18n_available": "available_dimension_restrictions_for_data_analytics", + "i18n_selected": "selected_dimension_restrictions_for_data_analytics", + "objects": $userCredentials.cogsDimensionConstraints +}) + +<div id="showLessOptions" style="margin-bottom: 20px;"><a href="javascript:showUserOptions()">$i18n.getString( "show_less_options" )</a></div> + +</div> + <p> <input type="submit" value="$i18n.getString( 'save' )" style="width:10em" /> <input type="button" id="cancel" value="$i18n.getString( 'cancel' )" style="width:10em" />
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp