From 6e5b87622f14e8a593b1b78577cbe573b8f3d694 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 29 Aug 2016 12:03:43 +0200 Subject: [PATCH] Continued with deleting user accounts: (please cherry-pick) - added form with delete reason - added method in controller (managed bean) which fires an event after the EJB deleted the user - added activity log for deleting users (based on fired event) - added missing i18n strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../user/JobsAdminUserWebRequestBean.java | 60 ++++++++ .../JobsAdminUserWebRequestController.java | 23 +++ .../beans/user/JobsUserWebSessionBean.java | 135 ++++++++++++------ .../user/JobsUserWebSessionController.java | 8 ++ .../JobsUserActivityWebApplicationBean.java | 22 +++ ...sUserActivityWebApplicationController.java | 8 ++ .../localization/bundle_de_DE.properties | 6 + .../localization/bundle_en_US.properties | 6 + web/admin/user/admin_user_delete.xhtml | 34 ++++- 9 files changed, 259 insertions(+), 43 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index f8158ea5..0bcf903e 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -35,10 +35,13 @@ import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; import org.mxchange.jjobs.beans.helper.JobsWebViewHelperController; +import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; import org.mxchange.jusercore.container.login.UserLoginContainer; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.add.AdminUserAddedEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminUserDeletedEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminUserLinkedEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; @@ -106,6 +109,19 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J @Inject private JobsContactWebSessionController contactController; + /** + * Event being fired when admin has deleted user + */ + @Inject + @Any + private Event deleteUserEvent; + + /** + * Localization controller + */ + @Inject + private JobsLocalizationSessionController localizationController; + /** * An event fired when the administrator has updated a new user */ @@ -124,6 +140,11 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J @Inject private JobsUserWebSessionController userController; + /** + * Delete reason + */ + private String userDeleteReason; + /** * An event fired when the administrator has linked a user with existing * contact data. @@ -338,6 +359,35 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J //* NOISY-DEBUG: */ System.out.println("UserWebBean:afterRegistration: EXIT!"); //NOI18N } + @Override + public String deleteUserData (final User user) { + // Is the user instance valid and CONFIRMED? + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Throw again + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is not valid", user.getUserId())); //NOI18N + } + + try { + // All fine, delete it + this.adminUserBean.deleteUser(user, this.getUserDeleteReason()); + } catch (final UserNotFoundException ex) { + // Should not happen, so throw again + throw new FaceletException(ex); + } + + // Fire event + this.deleteUserEvent.fire(new AdminUserDeletedEvent(user, this.getUserDeleteReason())); + + // Redirect + return "admin_list_user"; //NOI18N + } + @Override public String editUserData () { // Get user instance @@ -403,6 +453,16 @@ public class JobsAdminUserWebRequestBean extends BaseJobsController implements J return "admin_list_user"; //NOI18N } + @Override + public String getUserDeleteReason () { + return this.userDeleteReason; + } + + @Override + public void setUserDeleteReason (final String userDeleteReason) { + this.userDeleteReason = userDeleteReason; + } + @Override public String getUserLockReason () { return this.userLockReason; diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java index 2a99cf32..69598ed4 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestController.java @@ -43,6 +43,15 @@ public interface JobsAdminUserWebRequestController extends Serializable { */ String addUser (); + /** + * Deletes given user account + *

+ * @param user User instance to delete + *

+ * @return Redirect outcome + */ + String deleteUserData (final User user); + /** * Edits cuirrently loaded user's data in database. *

@@ -140,4 +149,18 @@ public interface JobsAdminUserWebRequestController extends Serializable { */ void setUserLockReason (final String userLockReason); + /** + * Getter for user delete reason + *

+ * @return User delete reason + */ + String getUserDeleteReason (); + + /** + * Setter for user delete reason + *

+ * @param userDeleteReason User delete reason + */ + void setUserDeleteReason (final String userDeleteReason); + } diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java index ee16e15b..87295f81 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionBean.java @@ -42,6 +42,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; @@ -195,6 +196,30 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.setUserId(event.getAddedUser().getUserId()); } + @Override + public void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedUser is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N + } + + // Update user list + this.removeFromList(event.getDeletedUser()); + + // Clear all data + this.clear(); + } + @Override public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) { // event should not be null @@ -288,48 +313,6 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.clear(); } - @Override - public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getRegisteredUser() == null) { - // Throw NPE again - throw new NullPointerException("event.registeredUser is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N - } else if (event.getRegisteredUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N - } - - // Get user instance - User registeredUser = event.getRegisteredUser(); - - // Copy all data from registered->user - this.copyUser(registeredUser); - - // Clear all data - this.clear(); - - // Update user list - this.updateList(registeredUser); - - // Add user name - this.addUserName(registeredUser); - - // Is the account public? - if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { - // Also add it to this list - this.visibleUserList.add(registeredUser); - } - - // Set user id again - this.setUserId(registeredUser.getUserId()); - } - @Override public void afterUserConfirmedAccountEvent (@Observes final UserConfirmedAccountEvent event) { // event should not be null @@ -381,6 +364,48 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs } } + @Override + public void afterUserRegistrationEvent (@Observes final UserRegisteredEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getRegisteredUser() == null) { + // Throw NPE again + throw new NullPointerException("event.registeredUser is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N + } else if (event.getRegisteredUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N + } + + // Get user instance + User registeredUser = event.getRegisteredUser(); + + // Copy all data from registered->user + this.copyUser(registeredUser); + + // Clear all data + this.clear(); + + // Update user list + this.updateList(registeredUser); + + // Add user name + this.addUserName(registeredUser); + + // Is the account public? + if (Objects.equals(registeredUser.getUserProfileMode(), ProfileMode.PUBLIC)) { + // Also add it to this list + this.visibleUserList.add(registeredUser); + } + + // Set user id again + this.setUserId(registeredUser.getUserId()); + } + @Override public void afterUserUpdatedPasswordEvent (@Observes final UpdatedUserPasswordEvent event) { // Check parameter @@ -861,6 +886,32 @@ public class JobsUserWebSessionBean extends BaseJobsController implements JobsUs this.setUserProfileMode(user.getUserProfileMode()); } + /** + * Removes user from all lists + *

+ * @param user User to remove + */ + private void removeFromList (final User user) { + // The user should be valid + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // ... again NPE + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Invalid id + throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N + } + + // Remove it from lists + this.userList.remove(user); + this.visibleUserList.remove(user); + + // Remove name from list + this.userNameList.remove(user.getUserName()); + } + /** * Updates list with given user instance *

diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java index e1c24182..d8c45f6e 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebSessionController.java @@ -23,6 +23,7 @@ import org.mxchange.jusercore.events.confirmation.UserConfirmedAccountEvent; import org.mxchange.jusercore.events.login.UserLoggedInEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; @@ -53,6 +54,13 @@ public interface JobsUserWebSessionController extends Serializable { */ void afterAdminAddedUserEvent (final AdminAddedUserEvent event); + /** + * Event observer for deleted user accounts (by administrator) + *

+ * @param event Event being fired + */ + void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event); + /** * Event observer for linked users with existing contact data *

diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java index c6cc8c0b..104f3cf3 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -40,6 +40,7 @@ import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; @@ -190,6 +191,27 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple this.addUserActivity(event.getAddedUser(), "ADMIN_ADDED_USER_ACCOUNT"); //NOI18N } + @Override + public void afterAdminDeletedUserEvent (@Observes final AdminDeletedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getDeletedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.deletedUser is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N + } else if (event.getDeletedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N + } + + // Add acitivity + this.addUserActivity(event.getDeletedUser(), "ADMIN_DELETED_USER_ACCOUNT", event.getUserDeleteReason()); //NOI18N + } + @Override public void afterAdminLinkedUserEvent (@Observes final AdminLinkedUserEvent event) { // event should not be null diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java index 4bc30ada..86db2690 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationController.java @@ -25,6 +25,7 @@ import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent; import org.mxchange.jusercore.events.registration.UserRegisteredEvent; import org.mxchange.jusercore.events.resendlink.UserResendLinkAccountEvent; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; +import org.mxchange.jusercore.events.user.delete.AdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.AdminLinkedUserEvent; import org.mxchange.jusercore.events.user.locked.AdminLockedUserEvent; import org.mxchange.jusercore.events.user.password_change.UpdatedUserPasswordEvent; @@ -49,6 +50,13 @@ public interface JobsUserActivityWebApplicationController extends Serializable { */ void afterAdminAddedUserEvent (final AdminAddedUserEvent event); + /** + * Event observer for deleted user accounts (by administrator) + *

+ * @param event Event being fired + */ + void afterAdminDeletedUserEvent (final AdminDeletedUserEvent event); + /** * Event observer for linked users with existing contact data *

diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index dacc22aa..090a1afa 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -769,3 +769,9 @@ ADMIN_ACTIVITY_USER_LOGGED_OUT=Benutzer hat sich ausgeloggt. USER_ACTIVITY_USER_LOGGED_OUT=Sie haben sich ausgeloggt. ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Fehler: Die Anwendung verwendet keine Benutzernamen, dennoch wurde dieses Template geladen. ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login: +ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Listet Aktivit\u00e4tslogbuch des Benutzers auf. +ADMIN_DELETE_USER_TITLE=Wollen Sie den Benutzer {0} (Id-Nummer {1}) wirklich l\u00f6schen? +BUTTON_ADMIN_DELETE_USER=Benutzeraccount l\u00f6schen +ADMIN_DELETE_USER_NOTICE=Durch das L\u00f6schen des Benutzeraccounts werden nur die Benutzerdaten, jedoch nicht Kontaktdaten. +ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Benutzeraccount gel\u00f6scht vom Administrator. +USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Ihr Benutzeraccount wurde von einem Administrator gel\u00f6scht. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 1f38285f..8b9f10c1 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -770,3 +770,9 @@ ADMIN_ACTIVITY_USER_LOGGED_OUT=User has logged out. USER_ACTIVITY_USER_LOGGED_OUT=You have logged out. ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Error: This application requires no user name, still this template has been loaded. ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login: +ADMIN_LINK_SHOW_USER_ACTIVITY_LOG_TITLE=Lists all user's activity. +ADMIN_DELETE_USER_TITLE=Do you really want to delete user account {0} (id number {1})? +BUTTON_ADMIN_DELETE_USER=Delete user account +ADMIN_DELETE_USER_NOTICE=By deleting the user's account, only user data is deleted but not contact data. +ADMIN_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=User account has been deleted by administrator. +USER_ACTIVITY_ADMIN_DELETED_USER_ACCOUNT=Your account has been deleted by an administrator. diff --git a/web/admin/user/admin_user_delete.xhtml b/web/admin/user/admin_user_delete.xhtml index b2e157aa..6a2931c5 100644 --- a/web/admin/user/admin_user_delete.xhtml +++ b/web/admin/user/admin_user_delete.xhtml @@ -31,7 +31,39 @@ - Here goes your content. + + +

+ + + + +
+ +
+ +
+ + + +
+
+ +
+ +
+ +
+ +
+
+ + + + -- 2.39.5