← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17838: User query, impl query support for user invitations

 

------------------------------------------------------------
revno: 17838
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-30 15:29:14 +0100
message:
  User query, impl query support for user invitations
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.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/allUser.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/index.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/menu.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/UserQueryParams.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java	2014-12-29 12:52:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserQueryParams.java	2014-12-30 14:29:14 +0000
@@ -57,6 +57,8 @@
     
     private boolean selfRegistered;
     
+    private UserInvitationStatus invitationStatus;
+    
     private OrganisationUnit organisationUnit;
     
     private Integer first;
@@ -180,6 +182,16 @@
         this.selfRegistered = selfRegistered;
     }
 
+    public UserInvitationStatus getInvitationStatus()
+    {
+        return invitationStatus;
+    }
+
+    public void setInvitationStatus( UserInvitationStatus invitationStatus )
+    {
+        this.invitationStatus = invitationStatus;
+    }
+
     public OrganisationUnit getOrganisationUnit()
     {
         return organisationUnit;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2014-12-30 13:02:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java	2014-12-30 14:29:14 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.system.util.SqlHelper;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserInvitationStatus;
 import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserStore;
 
@@ -124,6 +125,16 @@
         {
             hql += hlp.whereAnd() + " uc.selfRegistered = true ";
         }
+        
+        if ( UserInvitationStatus.ALL.equals( params.getInvitationStatus() ) )
+        {
+            hql += hlp.whereAnd() + " uc.invitation = true ";
+        }
+        
+        if ( UserInvitationStatus.EXPIRED.equals( params.getInvitationStatus() ) )
+        {
+            hql += hlp.whereAnd() + " uc.invitation = true and uc.restoreExpiry < current_timestamp() ";
+        }
                 
         if ( params.getOrganisationUnit() != null )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	2014-12-28 15:09:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserServiceTest.java	2014-12-30 14:29:14 +0000
@@ -626,4 +626,50 @@
 
         assertEquals( 2, userService.getUserCount( params ) );
     }
+
+    @Test
+    public void testGetInvitations()
+    {
+        User userA = createUser( 'A' );
+        User userB = createUser( 'B' );
+        User userC = createUser( 'C' );
+        User userD = createUser( 'D' );
+
+        UserCredentials credentialsA = createUserCredentials( 'A', userA );
+        UserCredentials credentialsB = createUserCredentials( 'B', userB );
+        UserCredentials credentialsC = createUserCredentials( 'C', userC );
+        UserCredentials credentialsD = createUserCredentials( 'D', userD );
+        
+        credentialsB.setInvitation( true );
+        credentialsD.setInvitation( true );
+        
+        userService.addUser( userA );
+        userService.addUser( userB );
+        userService.addUser( userC );
+        userService.addUser( userD );
+        
+        userService.addUserCredentials( credentialsA );
+        userService.addUserCredentials( credentialsB );
+        userService.addUserCredentials( credentialsC );
+        userService.addUserCredentials( credentialsD );
+
+        UserQueryParams params = new UserQueryParams();
+        params.setInvitationStatus( UserInvitationStatus.ALL );
+        
+        List<User> users = userService.getUsers( params );
+        
+        assertEquals( 2, users.size() );
+        assertTrue( users.contains( userB ) );
+        assertTrue( users.contains( userD ) );
+
+        assertEquals( 2, userService.getUserCount( params ) );
+        
+        params.setInvitationStatus( UserInvitationStatus.EXPIRED );
+        
+        users = userService.getUsers( params );
+        
+        assertEquals( 0, users.size() );
+
+        assertEquals( 0, userService.getUserCount( params ) );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-12-28 15:55:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2014-12-30 14:29:14 +0000
@@ -52,6 +52,7 @@
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserGroupService;
+import org.hisp.dhis.user.UserInvitationStatus;
 import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserService;
 import org.hisp.dhis.user.Users;
@@ -114,6 +115,7 @@
         params.setInactiveMonths( options.getInt( "inactiveMonths" ) );
         params.setInactiveSince( options.getDate( "inactiveSince" ) );
         params.setSelfRegistered( options.isTrue( "selfRegistered" ) );
+        params.setInvitationStatus( UserInvitationStatus.fromValue( options.get( "invitationStatus" ) ) );
         
         String ou = options.get( "ou" );
         

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java	2014-12-28 14:15:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java	2014-12-30 14:29:14 +0000
@@ -33,6 +33,7 @@
 
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserInvitationStatus;
 import org.hisp.dhis.user.UserQueryParams;
 import org.hisp.dhis.user.UserService;
 
@@ -99,6 +100,18 @@
     {
         this.selfRegistered = selfRegistered;
     }
+    
+    private String invitationStatus;
+
+    public String getInvitationStatus()
+    {
+        return invitationStatus;
+    }
+
+    public void setInvitationStatus( String invitationStatus )
+    {
+        this.invitationStatus = invitationStatus;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -113,10 +126,11 @@
         params.setQuery( key );
         params.setInactiveMonths( months );
         params.setSelfRegistered( selfRegistered );
+        params.setInvitationStatus( UserInvitationStatus.fromValue( invitationStatus ) );
         
         int count = userService.getUserCount( params );
         
-        this.paging = createPaging( count );        
+        this.paging = createPaging( count );
         params.setFirst( paging.getStartPos() );
         params.setMax( paging.getPageSize() );
         

=== 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-12-28 17:51:04 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2014-12-30 14:29:14 +0000
@@ -368,4 +368,10 @@
 available_users=Available users
 group_members=Group members
 available_managed_user_groups = Available user groups
-managed_user_groups = Managed user groups
\ No newline at end of file
+managed_user_groups = Managed user groups
+show_by_inactivity = Show by inactivity
+show_invitations = Show invitations
+all_invitations = All invitations
+expired_invitations = Expired invitations
+show_self_registrations = Show self-registrations
+self_registered_users = Self-registered users
\ 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/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm	2014-12-28 14:15:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm	2014-12-30 14:29:14 +0000
@@ -35,18 +35,28 @@
 					<td>
 						#filterDiv( "alluser" )
 					</td>
-					<td>						
-						<label>$i18n.getString( "inactive_for" ):</label><br>
-						<select id="months" style="width:85px" onchange="getInactiveUsers()">
-							<option value="0">[ $i18n.getString( "select" ) ]</option>
-							<option value="1"#if( $months && $months == 1 ) selected="selected"#end>1 $i18n.getString( "month" )</option>
+					<td colspan="3" style="text-align:right">
+						<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/>
+					</td>
+				</tr>
+				<tr>
+					<td>
+						<select id="months" style="width:155px" onchange="filterUsers()">
+							<option value="">[$i18n.getString( "show_by_inactivity" )]</option>
+							<option value="1"#if( $months == 1 ) selected="selected"#end>1 $i18n.getString( "month" )</option>
 							#foreach( $m in [2..12] )
-							<option value="${m}"#if( $months && $months == $m ) selected="selected"#end>${m} $i18n.getString( "months" )</option>
+							<option value="${m}"#if( $$months == $m ) selected="selected"#end>${m} $i18n.getString( "months" )</option>
 							#end
 						</select>
-					</td>
-					<td colspan="3" style="text-align:right">
-						<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/>
+						<select id="selfRegistered" style="width:155px" onchange="filterUsers()">
+							<option value="false">[$i18n.getString( "show_self_registrations" )]</option>
+							<option value="true"#if( $selfRegistered == true ) selected="selected"#end>$i18n.getString( "self_registered_users" )</option>
+						</select>
+						<select id="invitationStatus" style="width:155px" onchange="filterUsers()">
+							<option value="">[$i18n.getString( "show_invitations" )]</option>
+							<option value="all"#if( $invitationStatus == "all" ) selected="selected"#end>$i18n.getString( "all_invitations" )</option>
+							<option value="expired"#if( $invitationStatus == "expired" ) selected="selected"#end>$i18n.getString( "expired_invitations" )</option>
+						</select>
 					</td>
 				</tr>
 			</table>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/index.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/index.vm	2014-12-18 11:41:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/index.vm	2014-12-30 14:29:14 +0000
@@ -3,7 +3,6 @@
 <ul class="introList">
     #introListImgItem( "user.action" "user_by_orgunit" "user" )
     #introListImgItem( "alluser.action" "user" "user" )
-    #introListImgItem( "alluser.action?selfRegistered=true" "self_registered_user" "user" )
     #introListImgItem( "allRole.action" "user_role" "user" )
     #introListImgItem( "getAllUserGroups.action" "user_group" "user" )
 </ul>

=== 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-10-17 11:13:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js	2014-12-30 14:29:14 +0000
@@ -25,10 +25,18 @@
   }
 }
 
-function getInactiveUsers() {
+function filterUsers() {
   var months = $('#months').val();
+  var selfRegistered = $('#selfRegistered').val();
+  var invitationStatus = $('#invitationStatus').val();
 
-  window.location.href = 'alluser.action?months=' + months;
+  var url = 'alluser.action?';
+  
+  url += months ? 'months=' + months + '&' : '';
+  url += selfRegistered ? 'selfRegistered=' + selfRegistered + '&' : '';
+  url += invitationStatus ? 'invitationStatus=' + invitationStatus + '&' : '';
+  
+  window.location.href = url;
 }
 
 // -----------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/menu.vm	2014-12-18 11:41:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/menu.vm	2014-12-30 14:29:14 +0000
@@ -2,7 +2,6 @@
 <ul>
 	<li><a href="user.action">$i18n.getString( "user_by_orgunit" )&nbsp;</a></li>
 	<li><a href="alluser.action">$i18n.getString( "user" )&nbsp;</a></li>
-	<li><a href="alluser.action?selfRegistered=true">$i18n.getString( "self_registered_user" )&nbsp;</a></li>
 	<li><a href="allRole.action" title="$i18n.getString( "user_role" )">$i18n.getString( "user_role" )&nbsp;</a></li>
     <li><a href="deleteCurrentUser.action" title="$i18n.getString( "delete_current_user" )">$i18n.getString( "delete_current_user" )</a></li>
 	<li><a href="getAllUserGroups.action">$i18n.getString( "user_group" )</a></li>