← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16698: fixed to add user, store and return to previously selected OU when saving

 

------------------------------------------------------------
revno: 16698
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-09-12 13:24:17 +0700
message:
  fixed to add user, store and return to previously selected OU when saving
modified:
  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/webapp/dhis-web-maintenance-user/addUserForm.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-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-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java	2014-09-12 06:24:17 +0000
@@ -28,14 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import com.google.common.collect.Lists;
+import com.opensymphony.xwork2.Action;
 import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.attribute.AttributeService;
+import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -49,8 +46,8 @@
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.AttributeUtils;
 import org.hisp.dhis.system.util.LocaleUtils;
+import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.UserAuthorityGroup;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserGroup;
@@ -58,10 +55,14 @@
 import org.hisp.dhis.user.UserService;
 import org.hisp.dhis.user.UserSetting;
 import org.hisp.dhis.user.UserSettingService;
+import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 
-import com.opensymphony.xwork2.Action;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import static org.hisp.dhis.setting.SystemSettingManager.KEY_ONLY_MANAGE_WITHIN_USER_GROUPS;
 
@@ -127,6 +128,9 @@
     }
 
     @Autowired
+    private IdentifiableObjectManager manager;
+
+    @Autowired
     private CurrentUserService currentUserService;
 
     @Autowired
@@ -266,6 +270,13 @@
         this.jsonAttributeValues = jsonAttributeValues;
     }
 
+    private String ouwtSelected;
+
+    public void setOuwtSelected( String ouwtSelected )
+    {
+        this.ouwtSelected = ouwtSelected;
+    }
+
     private String message;
 
     public String getMessage()
@@ -296,7 +307,7 @@
         // ---------------------------------------------------------------------
 
         boolean canManageGroups = (Boolean) systemSettingManager.getSystemSetting( KEY_ONLY_MANAGE_WITHIN_USER_GROUPS, false );
-        
+
         if ( canManageGroups && !currentUser.getUserCredentials().getAllAuthorities().contains( "ALL" ) )
         {
             boolean groupFound = false;
@@ -452,6 +463,15 @@
             userGroupService.updateUserGroup( userGroup );
         }
 
+        if ( ouwtSelected != null && manager.search( OrganisationUnit.class, ouwtSelected ) != null )
+        {
+            selectionManager.setSelectedOrganisationUnits( Lists.newArrayList( manager.search( OrganisationUnit.class, ouwtSelected ) ) );
+        }
+        else
+        {
+            selectionManager.setSelectedOrganisationUnits( currentUser.getOrganisationUnits() );
+        }
+
         return SUCCESS;
     }
 

=== 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-09-11 12:33:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java	2014-09-12 06:24:17 +0000
@@ -236,6 +236,13 @@
         this.jsonAttributeValues = jsonAttributeValues;
     }
 
+    private String ouwtSelected;
+
+    public void setOuwtSelected( String ouwtSelected )
+    {
+        this.ouwtSelected = ouwtSelected;
+    }
+
     private String message;
 
     public String getMessage()
@@ -243,13 +250,6 @@
         return message;
     }
 
-    private String ouwtSelected;
-
-    public void setOuwtSelected( String ouwtSelected )
-    {
-        this.ouwtSelected = ouwtSelected;
-    }
-
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------

=== 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-07-03 05:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm	2014-09-12 06:24:17 +0000
@@ -1,4 +1,6 @@
 <script type="text/javascript">
+  var ouwtSelected = [];
+
   jQuery(function() {
     validation2('addUserForm', function( form ) {
       jQuery("#urSelected").children().attr("selected", "selected");
@@ -8,6 +10,8 @@
       if( $('#orgUnitTree').find('.selected').size() == 0 ) {
         setHeaderDelayMessage('$encoder.jsEncode( $i18n.getString( "data_capture_organisation_unit_required_for_user" ) )');
       } else {
+        $('#ouwtSelected').val( ouwtSelected[0] );
+        selection.setSelected( ouwtSelected !== undefined ? ouwtSelected : [] );
         form.submit();
       }
     }, {
@@ -21,6 +25,7 @@
     checkValueIsExist("username", "validateUser.action");
     checkValueIsExist("openId", "validateUser.action");
 
+    ouwtSelected = selection.getSelected();
     selection.setMultipleSelectionAllowed( true );
     selection.setUnselectAllowed( true );
     selection.setAutoSelectRoot( false );
@@ -62,6 +67,7 @@
 
 <h3>$i18n.getString( "create_new_user" )</h3>
 <form id="addUserForm" action="addUser.action" method="post" class="inputForm">
+<input type="hidden" id="ouwtSelected" name="ouwtSelected" value=""/>
 
 <table>
     <col style="width: 120px"/>