dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15115
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5332: Fixed bug https://bugs.launchpad.net/dhis2/+bug/901732
------------------------------------------------------------
revno: 5332
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-12-08 17:02:16 +0100
message:
Fixed bug https://bugs.launchpad.net/dhis2/+bug/901732
User role restriction on assigned datasets now works in mobile browser
added:
dhis-2/dhis-web/dhis-web-light/src/test/
dhis-2/dhis-web/dhis-web-light/src/test/java/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/
dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java
modified:
dhis-2/dhis-web/dhis-web-light/pom.xml
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java
dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml
--
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-web/dhis-web-light/pom.xml'
--- dhis-2/dhis-web/dhis-web-light/pom.xml 2011-11-21 12:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-light/pom.xml 2011-12-08 16:02:16 +0000
@@ -46,6 +46,11 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-mobile</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-support-test</artifactId>
+ </dependency>
+
<!-- Other -->
<dependency>
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java 2011-10-14 09:23:59 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java 2011-12-08 16:02:16 +0000
@@ -29,10 +29,15 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.springframework.beans.factory.annotation.Required;
import com.opensymphony.xwork2.Action;
@@ -46,6 +51,14 @@
// Dependencies
// -------------------------------------------------------------------------
+ private CurrentUserService currentUserService;
+
+ @Required
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
private OrganisationUnitService organisationUnitService;
public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
@@ -86,9 +99,19 @@
if ( organisationUnitId != null )
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
+
dataSets = new ArrayList<DataSet>( organisationUnit.getDataSets() );
+
+ UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
+
+ if ( !userCredentials.isSuper() )
+ {
+ dataSets.retainAll( userCredentials.getAllDataSets() );
+ }
+
}
return SUCCESS;
}
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-12-02 16:45:53 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2011-12-08 16:02:16 +0000
@@ -26,6 +26,7 @@
<bean id="org.hisp.dhis.light.dataentry.action.GetDataSetsAction" class="org.hisp.dhis.light.dataentry.action.GetDataSetsAction"
scope="prototype">
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
</bean>
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry'
=== added directory 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action'
=== added file 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java'
--- dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java 2011-12-08 16:02:16 +0000
@@ -0,0 +1,99 @@
+package org.hisp.dhis.light.dataentry.action;
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserCredentials;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GetDataSetsActionTest
+{
+ private GetDataSetsAction getDataSetsAction;
+
+ private DataSet ds2;
+
+ private DataSet ds3;
+
+ @Before
+ public void setup()
+ {
+ getDataSetsAction = new GetDataSetsAction();
+
+ // Shared dataSets
+ ds2 = new DataSet( "2" );
+ ds3 = new DataSet( "3" );
+
+ Set<DataSet> unitDataSets = createUnitDataSets();
+ Set<DataSet> userDataSets = createUserDataSets();
+
+ // Initializing action
+ getDataSetsAction.setOrganisationUnitId( 1 );
+ CurrentUserService currentUserService = mock( CurrentUserService.class );
+ getDataSetsAction.setCurrentUserService( currentUserService );
+ OrganisationUnitService organisationUnitService = mock( OrganisationUnitService.class );
+ getDataSetsAction.setOrganisationUnitService( organisationUnitService );
+
+ // Populating mocks
+ OrganisationUnit unit = new OrganisationUnit();
+ unit.setDataSets( unitDataSets );
+
+ when( organisationUnitService.getOrganisationUnit( anyInt() ) ).thenReturn( unit );
+
+ UserCredentials credentials = mock( UserCredentials.class );
+ when( credentials.isSuper() ).thenReturn( false );
+ when( credentials.getAllDataSets() ).thenReturn( userDataSets );
+
+ User user = new User();
+ user.setUserCredentials( credentials );
+
+ when( currentUserService.getCurrentUser() ).thenReturn( user );
+ }
+
+ private Set<DataSet> createUserDataSets()
+ {
+ Set<DataSet> userDataSets;
+ userDataSets = new HashSet<DataSet>();
+ userDataSets.add( ds2 );
+ userDataSets.add( ds3 );
+ userDataSets.add( new DataSet( "5" ) );
+ return userDataSets;
+ }
+
+ private Set<DataSet> createUnitDataSets()
+ {
+ Set<DataSet> unitDataSets;
+ unitDataSets = new HashSet<DataSet>();
+ unitDataSets.add( new DataSet( "1" ) );
+ unitDataSets.add( ds2 );
+ unitDataSets.add( ds3 );
+ unitDataSets.add( new DataSet( "4" ) );
+ return unitDataSets;
+ }
+
+ @Test
+ public void testUserDataSetsFiltering()
+ {
+
+ getDataSetsAction.execute();
+
+ List<DataSet> dataSets = getDataSetsAction.getDataSets();
+ assertEquals( 2, dataSets.size() );
+
+ DataSet dataSet1 = dataSets.get( 0 );
+ DataSet dataSet2 = dataSets.get( 1 );
+
+ assertTrue( (dataSet1.equals( ds2 ) && dataSet2.equals( ds3 ))
+ || (dataSet2.equals( ds2 ) && dataSet1.equals( ds3 )) );
+ }
+
+}