dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06260
Re: [Branch ~dhis2-devs-core/dhis2/trunk] Rev 1795: Added code for Deleting self user
Sorry for remind a very old commit. Just code convention related, but butter
if it was solved.
On Wed, Apr 21, 2010 at 5:44 PM, <noreply@xxxxxxxxxxxxx> wrote:
> ------------------------------------------------------------
> revno: 1795
> committer: Administrator <Administrator@NAM-LAPPY>
> branch nick: trunk
> timestamp: Wed 2010-04-21 16:12:20 +0530
> message:
> Added code for Deleting self user
> added:
>
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/DeleteCurrentUserAction.java
>
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/deleteCurrentUser.vm
> modified:
>
> 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/META-INF/dhis/beans.xml
>
> 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/menu.vm
>
>
> --
> lp:dhis2
> https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk<https://code.launchpad.net/%7Edhis2-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<https://code.launchpad.net/%7Edhis2-devs-core/dhis2/trunk/+edit-subscription>
>
> === added file
> 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/DeleteCurrentUserAction.java'
> ---
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/DeleteCurrentUserAction.java
> 1970-01-01 00:00:00 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/DeleteCurrentUserAction.java
> 2010-04-21 10:42:20 +0000
> @@ -0,0 +1,152 @@
> +/*
> + * To change this template, choose Tools | Templates
> + * and open the template in the editor.
> + */
>
These lines should not be here.
> +package org.hisp.dhis.user.action;
> +
>
DHIS 2 license should be here.
> +
> +import com.opensymphony.xwork2.Action;
> +import java.util.Collection;
> +import org.hisp.dhis.i18n.I18n;
> +import org.hisp.dhis.security.PasswordManager;
> +import org.hisp.dhis.user.CurrentUserService;
> +import org.hisp.dhis.user.User;
> +import org.hisp.dhis.user.UserCredentials;
> +import org.hisp.dhis.user.UserService;
> +import org.hisp.dhis.user.UserSetting;
> +import org.hisp.dhis.user.UserStore;
> +
> +/**
> + *
> + * @author Administrator
> + */
>
We have no developer named Administrator. Should be fixed too.
> +public class DeleteCurrentUserAction implements Action
> +{
> +
> + private UserStore userStore;
> +
> + public void setUserStore( UserStore userStore )
> + {
> + this.userStore = userStore;
> + }
> +
> + private CurrentUserService currentUserService;
> +
> + public void setCurrentUserService( CurrentUserService
> currentUserService )
> + {
> + this.currentUserService = currentUserService;
> + }
> +
> + private PasswordManager passwordManager;
> +
> + public void setPasswordManager( PasswordManager passwordManager )
> + {
> + this.passwordManager = passwordManager;
> + }
> +
> + private UserService userService;
> +
> + public void setUserService( UserService userService )
> + {
> + this.userService = userService;
> + }
> +
> +
> + private Integer id;
> +
> + public void setId( Integer id )
> + {
> + this.id = id;
> + }
> +
> + private I18n i18n;
> +
> + public void setI18n( I18n i18n )
> + {
> + this.i18n = i18n;
> + }
> +
> + private String message;
> +
> + public String getMessage()
> + {
> + return message;
> + }
> +
> + private String username;
> +
> + public void setUsername( String username )
> + {
> + this.username = username;
> + }
> +
> + public String getUsername()
> + {
> + return username;
> + }
> +
> + private String oldPassword;
> +
> + public String getOldPassword()
> + {
> + return oldPassword;
> + }
> +
> + public void setOldPassword( String oldPassword )
> + {
> + this.oldPassword = oldPassword;
> + }
> +
> + @Override
> + public String execute() throws Exception
> + {
> + message = " ";
> + User user = userStore.getUser(
> currentUserService.getCurrentUser().getId() );
> +
> + UserCredentials userCredentials = userStore.getUserCredentials(
> user );
> +
> + username = userCredentials.getUsername();
> + String oldPasswordFromDB = userCredentials.getPassword();
> +
> + if ( oldPassword == null )
> + {
> + return INPUT;
> + }
> +
> + oldPassword = oldPassword.trim();
> +
> + if ( oldPassword.length() == 0 )
> + {
> + return INPUT;
> + }
> + //System.out.println( "oldPasswordFromDB = " + oldPasswordFromDB
> + " encoded old password = " + passwordManager.encodePassword(
> userCredentials.getUsername(), oldPassword ) );
> + String oldEncodedPassword = passwordManager.encodePassword(
> userCredentials.getUsername(), oldPassword ) ;
> + if ( !oldEncodedPassword.equals( oldPasswordFromDB ) )
> + {
> + message = i18n.getString( "wrong_password" );
> + return INPUT;
> + }
> + else
> + {
> + Collection<UserSetting> userSettings =
> userStore.getAllUserSettings( user );
> +
> + for ( UserSetting userSetting : userSettings )
> + {
> + userStore.deleteUserSetting( userSetting );
> + }
> +
> + if ( userService.isLastSuperUser( userCredentials ) )
> + {
> + message = i18n.getString( "can_not_remove_last_super_user"
> );
> + return INPUT;
> + } else
> + {
> + userStore.deleteUserCredentials(
> userStore.getUserCredentials( user ) );
> + userStore.deleteUser( user );
> + }
> +
> +
> + return "logout";
> + }
> + }
> +}
>
> === 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
> 2010-04-12 21:23:33 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java
> 2010-04-21 10:42:20 +0000
> @@ -38,6 +38,7 @@
> import org.hisp.dhis.user.comparator.UsernameComparator;
>
> import com.opensymphony.xwork2.Action;
> +import org.hisp.dhis.user.CurrentUserService;
>
> /**
> * @author Torgeir Lorange Ostby
> @@ -57,6 +58,12 @@
> this.userStore = userStore;
> }
>
> + private CurrentUserService currentUserService;
> +
> + public void setCurrentUserService( CurrentUserService
> currentUserService )
> + {
> + this.currentUserService = currentUserService;
> + }
> //
> -------------------------------------------------------------------------
> // Output
> //
> -------------------------------------------------------------------------
> @@ -68,6 +75,14 @@
> return userCredentialsList;
> }
>
> + private String currentUserName;
> +
> + public String getCurrentUserName()
> + {
> + return currentUserName;
> + }
> +
> +
> //
> -------------------------------------------------------------------------
> // Action implemantation
> //
> -------------------------------------------------------------------------
> @@ -89,7 +104,10 @@
> }
>
> Collections.sort( userCredentialsList, new UsernameComparator() );
> + User currentUser = userStore.getUser(
> currentUserService.getCurrentUser().getId() );
> + UserCredentials userCredentials = userStore.getUserCredentials(
> currentUser );
>
> + currentUserName = userCredentials.getUsername();
> return SUCCESS;
> }
> }
>
> === modified file
> 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml'
> ---
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml
> 2010-03-31 03:07:10 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml
> 2010-04-21 10:42:20 +0000
> @@ -25,6 +25,24 @@
> </property>
> </bean>
>
> + <bean id="org.hisp.dhis.user.action.DeleteCurrentUserAction"
> + class="org.hisp.dhis.user.action.DeleteCurrentUserAction"
> + scope="prototype">
> + <property name="userStore">
> + <ref bean="org.hisp.dhis.user.UserStore"/>
> + </property>
> + <property name="currentUserService">
> + <ref bean="org.hisp.dhis.user.CurrentUserService"/>
> + </property>
> + <property name="passwordManager">
> + <ref bean="org.hisp.dhis.security.PasswordManager"/>
> + </property>
> + <property name="userService">
> + <ref bean="org.hisp.dhis.user.UserService" />
> + </property>
> + </bean>
> +
> +
> <bean id="org.hisp.dhis.user.action.GetUserAction"
> class="org.hisp.dhis.user.action.GetUserAction"
> scope="prototype">
> <property name="userStore">
> @@ -50,6 +68,9 @@
> <property name="userStore">
> <ref bean="org.hisp.dhis.user.UserStore" />
> </property>
> + <property name="currentUserService">
> + <ref bean="org.hisp.dhis.user.CurrentUserService"/>
> + </property>
> </bean>
>
> <bean id="org.hisp.dhis.user.action.RemoveUserAction"
> class="org.hisp.dhis.user.action.RemoveUserAction"
>
> === 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
> 2010-04-04 11:24:12 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
> 2010-04-21 10:42:20 +0000
> @@ -204,4 +204,6 @@
> user_use_group = There are users used this role
> can_not_remove_last_super_user = Can not remove the last super user.
> can_not_remove_last_super_user_role = Can not remove the last super user
> role.
> -excel_importing = Excel Importing
> \ No newline at end of file
> +excel_importing = Excel Importing
> +delete_current_user = Delete Current User
> +wrong_password = Wrong Password
> \ 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
> 2010-03-31 03:07:10 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml
> 2010-04-21 10:42:20 +0000
> @@ -44,6 +44,7 @@
> <result name="error"
> type="velocity-json">/dhis-web-commons/ajax/jsonResponseError.vm</result>
> <param name="requiredAuthorities">F_USER_DELETE</param>
> </action>
> +
>
> <action name="showAddUserForm"
> class="org.hisp.dhis.user.action.SetupTreeAction">
> <result name="success" type="velocity">/main.vm</result>
> @@ -151,6 +152,18 @@
> <result name="input"
> type="velocity-xml">/dhis-web-maintenance-user/responseInput.vm</result>
> <param name="onExceptionReturn">plainTextError</param>
> </action>
> +
> + <!--Delete current user-->
> + <action name="deleteCurrentUser"
> class="org.hisp.dhis.user.action.DeleteCurrentUserAction">
> + <!--<result name="error"
> type="velocity">/dhis-web-maintenance-user/responseError.vm</result>-->
> + <result name="input" type="velocity">/main.vm</result>
> + <param
> name="page">/dhis-web-maintenance-user/deleteCurrentUser.vm</param>
> + <param name="menu">/dhis-web-maintenance-user/menu.vm</param>
> + <result name="success"
> type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
> + <result name="logout"
> type="redirect">/dhis-web-commons-security/logout.action</result>
> + <param
> name="javascripts">../dhis-web-commons/util/validate/jquery.validate.js,../dhis-web-commons/util/jquery.metadata.js
> +
> ,../dhis-web-commons/util/validate/messages_locale.js,../dhis-web-commons/util/validate/additional-methods.js</param>
> + </action>
>
> </package>
> </struts>
>
> === 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
> 2010-02-25 03:10:07 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm
> 2010-04-21 10:42:20 +0000
> @@ -33,9 +33,15 @@
> <td onclick="showUserDetails(
> $userCredentials.id )">$!encoder.htmlEncode( $
> userCredentials.user.organisationUnit.name )</td>
> <td style="text-align:center">
> <a
> href="showUpdateUserForm.action?id=$userCredentials.id"
> title="$i18n.getString( "edit" )"><img src="../images/edit.png"
> alt="$i18n.getString( "edit" )"></a></td>
> - <td style="text-align:center">
> - <a href="javascript:removeUser(
> $userCredentials.id, '$encoder.jsEncode( $userCredentials.username )' )"
> title="$i18n.getString( "remove" )"><img src="../images/delete.png"
> alt="$i18n.getString( "remove" )"></a>
> - </td>
> +
> + #if($currentUserName != $userCredentials.username)
> + <td style="text-align:center">
> + <a href="javascript:removeUser(
> $userCredentials.id, '$encoder.jsEncode( $userCredentials.username )' )"
> title="$i18n.getString( "remove" )"><img src="../images/delete.png"
> alt="$i18n.getString( "remove" )"></a>
> + </td>
> + #else
> + <td style="text-align:center">
> + </td>
> + #end
> <td style="text-align:center"><a
> href="javascript:showUserDetails( $userCredentials.id )"
> title="$i18n.getString( "show_details" )"><img
> src="../images/information.png" alt="$i18n.getString( "show_details"
> )"></a></td>
> </tr>
> #end
>
> === added file
> 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/deleteCurrentUser.vm'
> ---
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/deleteCurrentUser.vm
> 1970-01-01 00:00:00 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/deleteCurrentUser.vm
> 2010-04-21 10:42:20 +0000
> @@ -0,0 +1,34 @@
> +
> +<h3>$i18n.getString( "delete_current_user" )</h3>
> +<input type="hidden" id="curLocaleCode"
> value="$locale.getLanguage()_$locale.getCountry()"/>
> +<form id="deleteCurrentUser" action="deleteCurrentUser.action"
> method="post" >
> +
> +<table>
> + <tr>
> + <th colspan="2"> </th>
> + </tr>
> + <tr>
> + <td><label for="username">$i18n.getString( "username"
> )</label></td>
> + <td><input type="text" id="username" name="username"
> style="width:20em" disabled="" value="$username"></td>
> + </tr>
> + <tr>
> + <td><label for="oldPassword">$i18n.getString( "password" )
> <em title="$i18n.getString( "required" )"
> class="required">*</em></label></td>
> + <td><input type="password" id="oldPassword"
> name="oldPassword" style="width:20em"></td>
> + </tr>
> +
> + <tr>
> + <td colspan="4" height="10">
> + <span id="message"></span>
> + </td>
> + </tr>
> + <tr>
> + <td></td>
> + <td valign="top"><input type="submit"
> value="$i18n.getString( "Delete" )" style="width:10em"><input type="button"
> value="$i18n.getString( "cancel" )"
> onclick="window.location.href='deleteCurrentUser.action'"
> style="width:10em"></td>
> + </tr>
> +</table>
> +
> +</form>
> +
> +<span id="message" style="display:#if($message.trim().equals(""))none
> #else block #end">$message</span>
> +
> +
>
> === 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
> 2010-03-31 03:07:10 +0000
> +++
> dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/menu.vm
> 2010-04-21 10:42:20 +0000
> @@ -3,4 +3,5 @@
> <li><a href="alluser.action" title="$i18n.getString( "user"
> )">$i18n.getString( "user" ) </a></li>
> <li><a href="user.action" title="$i18n.getString( "user_by_orgunit"
> )">$i18n.getString( "user_by_orgunit" ) </a></li>
> <li><a href="allRole.action" title="$i18n.getString( "user_role"
> )">$i18n.getString( "user_role" ) </a></li>
> + <li><a href="deleteCurrentUser.action" title="Delete Current
> User">Delete Current User</a></li>
> </ul>
> \ No newline at end of file
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs<https://launchpad.net/%7Edhis2-devs>
> Post to : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs<https://launchpad.net/%7Edhis2-devs>
> More help : https://help.launchpad.net/ListHelp
>
>
Bert regards,
Quang
Follow ups
References