← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17950: User module, impl UI for replicating user

 

------------------------------------------------------------
revno: 17950
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-01-12 19:53:15 +0100
message:
  User module, impl UI for replicating user
modified:
  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/resources/org/hisp/dhis/user/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml
  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/javascript/user.js


--
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-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	2015-01-12 17:23:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2015-01-12 18:53:15 +0000
@@ -38,6 +38,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.common.Pager;
@@ -50,6 +51,7 @@
 import org.hisp.dhis.security.RestoreOptions;
 import org.hisp.dhis.security.SecurityService;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.hisp.dhis.system.util.ValidationUtils;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserAuthorityGroup;
@@ -279,22 +281,34 @@
         }
         
         Map<String, String> auth = renderService.fromJson( request.getInputStream(),Map.class );
+
+        String username = StringUtils.trimToNull( auth != null ? auth.get( KEY_USERNAME ) : null );
+        String password = StringUtils.trimToNull( auth != null ? auth.get( KEY_PASSWORD ) : null );
         
-        if ( auth == null || !auth.containsKey( KEY_USERNAME ) || !auth.containsKey( KEY_PASSWORD ) )
+        if ( auth == null || username == null )
         {
-            ContextUtils.conflictResponse( response, "Username and password must be specified" );
+            ContextUtils.conflictResponse( response, "Username must be specified" );
             return;
         }
-        
-        String username = auth.get( KEY_USERNAME );
-        String password = auth.get( KEY_PASSWORD );
-        
+
         if ( userService.getUserCredentialsByUsername( username ) != null )
         {
             ContextUtils.conflictResponse( response, "Username already taken: " + username );
             return;
         }
         
+        if ( password == null )
+        {
+            ContextUtils.conflictResponse( response, "Password must be specified" );
+            return;            
+        }
+        
+        if ( !ValidationUtils.passwordIsValid( password ) )
+        {
+            ContextUtils.conflictResponse( response, "Password must have at least 8 characters, one digit, one uppercase" );
+            return;
+        }
+        
         User userReplica = new User();
         userReplica.mergeWith( existingUser );
         userReplica.setUid( CodeGenerator.generateCode() );
@@ -304,7 +318,7 @@
         credentialsReplica.mergeWith( existingUser.getUserCredentials() );
         
         credentialsReplica.setUsername( username );
-        credentialsReplica.setPassword( password );
+        userService.encodeAndSetPassword( credentialsReplica, password );
         
         userReplica.setUserCredentials( credentialsReplica );
         credentialsReplica.setUser( userReplica );

=== 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	2015-01-02 11:34:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties	2015-01-12 18:53:15 +0000
@@ -133,7 +133,7 @@
 F_REPORT_PRIVATE_ADD=Add/Update Private Report
 F_REPORT_DELETE=Delete Report
 F_REPORTTABLE_PUBLIC_ADD=Add/Update Public Report Table
-F_REPORTTABLE_EXTERNAL=Report Table External Access
+F_REPORTTABLE_EXTERNAL=Report Table External Accessreplicate
 F_REPORTTABLE_DELETE=Delete Report Table
 F_REPORT_VIEW=View Report
 F_CHART_PUBLIC_ADD=Add/Update Public Chart
@@ -375,4 +375,5 @@
 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
+self_registered_users = Self-registered users
+replicate=Replicate
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml	2014-12-18 11:41:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml	2015-01-12 18:53:15 +0000
@@ -15,7 +15,7 @@
       <param name="page">/dhis-web-maintenance-user/index.vm</param>
       <param name="menu">/dhis-web-maintenance-user/menu.vm</param>
     </action>
-
+    
     <action name="user" class="org.hisp.dhis.user.action.GetOrgunitUserListAction">
       <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-user/user.vm</param>

=== 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-30 14:29:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm	2015-01-12 18:53:15 +0000
@@ -13,6 +13,8 @@
 	var currentUserName = '$currentUsername';
 </script>
 
+#set( $hasAllAuth = $currentUser.getUserCredentials().isAuthorized( 'ALL' ) )
+
 <h3>$i18n.getString( "user_management" ) #openHelp( "user_management" )</h3>
 
 <div id="contextMenu" class="contextMenu">
@@ -20,8 +22,8 @@
     <li><a data-target-fn="showUserProfile"><i class="fa fa-user"></i>&nbsp;&nbsp;$i18n.getString( "profile" )</a></li>
     <li data-enabled="canUpdate"><a data-target-fn="showUpdateUserForm"><i class="fa fa-edit"></i>&nbsp;&nbsp;$i18n.getString( "edit" )</a></li>
     <li data-enabled="canDelete"><a data-target-fn="removeUser"><i class="fa fa-trash-o"></i>&nbsp;&nbsp;$i18n.getString( "remove" )</a></li>
+    <li data-enabled="canReplicate"><a data-target-fn="showReplicateUserDialog"><i class="fa fa-copy"></i>&nbsp;&nbsp;$i18n.getString( "replicate" )</a></li>
     <li><a data-target-fn="showUserDetails"><i class="fa fa-info-circle"></i>&nbsp;&nbsp;$i18n.getString( "show_details" )</a></li>
-
     <li data-enabled="userEnabled"><a data-target-fn="disableUser"><i class="fa fa-ban"></i>&nbsp;&nbsp;$i18n.getString( "disable")</a></li>
     <li data-enabled="userDisabled"><a data-target-fn="enableUser"><i class="fa fa-ban"></i>&nbsp;&nbsp;$i18n.getString( "enable" )</a></li>
   </ul>
@@ -75,6 +77,7 @@
 				    data-can-manage="$security.canManage( $user.userCredentials )"
 				    data-can-update="$security.canUpdate( $user.userCredentials )"
 				    data-can-delete="$security.canDelete( $user.userCredentials )"
+				    data-can-replicate="$hasAllAuth"
                     data-user-enabled="#if( !$user.userCredentials.disabled )true#{else}false#end"
                     data-user-disabled="$user.userCredentials.disabled">
 				    <td>$encoder.htmlEncode( $!user.surname ), $encoder.htmlEncode( $!user.firstName )</td>
@@ -90,9 +93,10 @@
 		</td>
 
 		<td id="detailsData">
-      <div id="detailsArea">
-        <div id="hideDetailsArea">
-          <a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/hide.png" alt="$i18n.getString( 'hide_details' )"/></a>
+        
+        	<div id="detailsArea">
+        		<div id="hideDetailsArea">
+          			<a href="javascript:hideDetails()" title="$i18n.getString( 'hide_details' )"><img src="../images/hide.png" alt="$i18n.getString( 'hide_details' )"/></a>
 				</div>
 				<p><label>$i18n.getString( "username" ):</label><br><span id="usernameField"></span></p>
 				<p><label>$i18n.getString( "fullname" ):</label><br><span id="fullNameField"></span></p>
@@ -116,3 +120,23 @@
 		</td>
 	</tr>
 </table>
+
+<div id="replicateUserForm" class="inputForm" style="display:none">
+	<table>
+		<tr>
+	        <td><label>$i18n.getString( "username" )</label></td>
+			<td><input type="text" id="replicaUsername" autocomplete="off"></td>
+		</tr>
+		<tr>
+			<td><label>$i18n.getString( "password" )</label></td>
+			<td><input type="password" id="replicaPassword" autocomplete="off"></td>
+		</tr>
+		<tr>
+			<td></td>
+			<td>
+				<input type="button" value="$i18n.getString( "replicate" )" onclick="replicateUser()" style="width:100px">
+				<input type="button" value="$i18n.getString( "cancel" )" onclick="cancelReplicateUser()" style="width:100px">
+				<input type="hidden" id="replicaId">
+		</tr>
+	</table>
+</div>

=== 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-12-30 14:29:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js	2015-01-12 18:53:15 +0000
@@ -155,8 +155,6 @@
 	return def.promise();
 }
 
-
-
 // -----------------------------------------------------------------------------
 // Remove user
 // -----------------------------------------------------------------------------
@@ -198,3 +196,46 @@
 	$( "#showMoreOptions" ).toggle();
 	$( "#moreOptions" ).toggle();
 }
+
+// -----------------------------------------------------------------------------
+// Replicate user
+// -----------------------------------------------------------------------------
+
+function showReplicateUserDialog( context ) {
+	$( "#replicaId" ).val( context.uid );
+	
+	$( "#replicateUserForm" ).dialog( {
+		modal: true,
+		width: 415,
+		height: 170,
+		resizable: false,
+		title: "Replicate user"
+	});
+}
+
+function replicateUser() {
+	var replica = {
+		"username": $( "#replicaUsername" ).val(),
+		"password": $( "#replicaPassword" ).val()
+	};
+	
+	var id = $( "#replicaId" ).val();
+	
+	$.ajax({
+		url: "../api/users/" + id + "/replica", 
+		data: JSON.stringify( replica ),
+		type: "post",
+		contentType: "application/json; charset=utf-8",
+		success: function() {
+			$( "#replicateUserForm" ).dialog( "destroy" );
+			window.location.href = "alluser.action";
+		},
+		error: function( xhr, status, error ) {
+			setHeaderDelayMessage( xhr.responseText );
+		}
+	});
+}
+
+function cancelReplicateUser() {
+	$( "#replicateUserForm" ).dialog( "destroy" );
+}