This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git

commit 751df91356447ee3df48a0f34d7a65b1ba651114
Author: Maxim Solodovnik <solomax...@gmail.com>
AuthorDate: Mon Apr 16 22:33:33 2018 +0700

    [OPENMEETINGS-1864] basic purge is implemented
---
 .../apache/openmeetings/db/dao/user/UserDao.java   | 34 ++++++++++++++++++++++
 .../openmeetings/db/entity/basic/ChatMessage.java  |  1 +
 .../openmeetings/db/entity/basic/MailMessage.java  |  1 +
 .../org/apache/openmeetings/util/OmFileHelper.java |  6 +++-
 .../openmeetings/web/admin/AdminSavePanel.java     |  4 +--
 .../openmeetings/web/admin/users/UserForm.java     | 26 +++++++++++++++++
 6 files changed, 69 insertions(+), 3 deletions(-)

diff --git 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/user/UserDao.java
 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/user/UserDao.java
index fe8cd60..b0221c0 100644
--- 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/user/UserDao.java
+++ 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/dao/user/UserDao.java
@@ -24,6 +24,7 @@ import static 
org.apache.openmeetings.util.OpenmeetingsVariables.PARAM_USER_ID;
 import static 
org.apache.openmeetings.util.OpenmeetingsVariables.getDefaultLang;
 import static 
org.apache.openmeetings.util.OpenmeetingsVariables.getMinLoginLength;
 
+import java.io.File;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -47,6 +48,7 @@ import org.apache.openjpa.persistence.OpenJPAQuery;
 import org.apache.openmeetings.db.dao.IGroupAdminDataProviderDao;
 import org.apache.openmeetings.db.dao.label.LabelDao;
 import org.apache.openmeetings.db.entity.user.Address;
+import org.apache.openmeetings.db.entity.user.AsteriskSipUser;
 import org.apache.openmeetings.db.entity.user.User;
 import org.apache.openmeetings.db.entity.user.User.Right;
 import org.apache.openmeetings.db.entity.user.User.Salutation;
@@ -54,6 +56,7 @@ import org.apache.openmeetings.db.entity.user.User.Type;
 import org.apache.openmeetings.db.util.AuthLevelUtil;
 import org.apache.openmeetings.util.DaoHelper;
 import org.apache.openmeetings.util.OmException;
+import org.apache.openmeetings.util.OmFileHelper;
 import org.apache.openmeetings.util.crypt.CryptProvider;
 import org.apache.openmeetings.util.crypt.ICrypt;
 import org.apache.wicket.util.string.Strings;
@@ -325,6 +328,37 @@ public class UserDao implements 
IGroupAdminDataProviderDao<User> {
                }
        }
 
+       // created here so this action would be executed in Transaction
+       public void purge(User u, Long userId) {
+               if (u != null && u.getId() != null) {
+                       em.createNamedQuery("purgeChatUserName")
+                               .setParameter("purged", "Purged User")
+                               .setParameter("userId", u.getId())
+                               .executeUpdate();
+                       if (!Strings.isEmpty(u.getAddress().getEmail())) {
+                               em.createNamedQuery("purgeMailMessages")
+                                       .setParameter("email", 
String.format("%%%s%%", u.getAddress().getEmail()))
+                                       .executeUpdate();
+                       }
+                       u.setDeleted(true);
+                       u.setSipUser(new AsteriskSipUser());
+                       u.setAddress(new Address());
+                       u.setAge(new Date());
+                       u.setExternalId(null);
+                       final String purged = String.format("Purged %s", 
UUID.randomUUID());
+                       u.setFirstname(purged);
+                       u.setLastname(purged);
+                       u.setLogin(purged);
+                       File pic = 
OmFileHelper.getUserProfilePicture(u.getId(), u.getPictureuri(), null);
+                       u.setPictureuri(null);
+                       update(u, userId);
+                       // this should be last action, so file will be deleted 
in case there were no errors
+                       if (pic != null) {
+                               pic.delete();
+                       }
+               }
+       }
+
        public List<User> get(Collection<Long> ids) {
                return em.createNamedQuery("getUsersByIds", 
User.class).setParameter("ids", ids).getResultList();
        }
diff --git 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/ChatMessage.java
 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/ChatMessage.java
index 13d6824..8c812f7 100644
--- 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/ChatMessage.java
+++ 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/ChatMessage.java
@@ -53,6 +53,7 @@ import org.simpleframework.xml.Root;
        , @NamedQuery(name = "deleteChatGlobal", query = "DELETE FROM 
ChatMessage c WHERE c.toUser IS NULL AND c.toRoom IS NULL")
        , @NamedQuery(name = "deleteChatRoom", query = "DELETE FROM ChatMessage 
c WHERE c.toUser IS NULL AND c.toRoom.id = :roomId")
        , @NamedQuery(name = "deleteChatUser", query = "DELETE FROM ChatMessage 
c WHERE c.toRoom IS NULL AND c.toUser.id = :userId")
+       , @NamedQuery(name = "purgeChatUserName", query = "UPDATE ChatMessage c 
SET c.fromName = :purged WHERE c.toUser.id = :userId")
 })
 @Table(name = "chat")
 @Root(name = "ChatMessage")
diff --git 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/MailMessage.java
 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/MailMessage.java
index 671a060..bff9218 100644
--- 
a/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/MailMessage.java
+++ 
b/openmeetings-db/src/main/java/org/apache/openmeetings/db/entity/basic/MailMessage.java
@@ -40,6 +40,7 @@ import org.apache.openmeetings.db.entity.HistoricalEntity;
        , @NamedQuery(name = "countMailMessages", query = "SELECT COUNT(m) FROM 
MailMessage m")
        , @NamedQuery(name = "resetMailStatusByDate", query = "UPDATE 
MailMessage m SET m.status = :noneStatus WHERE m.status = :sendingStatus AND 
m.updated < :date")
        , @NamedQuery(name = "resetMailStatusById", query = "UPDATE MailMessage 
m SET m.errorCount = 0, m.status = :noneStatus WHERE m.id = :id")
+       , @NamedQuery(name = "purgeMailMessages", query = "DELETE FROM 
MailMessage m WHERE m.recipients LIKE :email OR m.replyTo LIKE :email")
 })
 @Table(name = "email_queue")
 public class MailMessage extends HistoricalEntity {
diff --git 
a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
 
b/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
index 00fd05f..ea4b10e 100644
--- 
a/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
+++ 
b/openmeetings-util/src/main/java/org/apache/openmeetings/util/OmFileHelper.java
@@ -143,6 +143,10 @@ public class OmFileHelper {
        }
 
        public static File getUserProfilePicture(Long userId, String uri) {
+               return getUserProfilePicture(userId, uri, 
getDefaultProfilePicture());
+       }
+
+       public static File getUserProfilePicture(Long userId, String uri, File 
def) {
                File img = null;
                if (SIP_USER_ID.equals(userId)) {
                        img = new File(getImagesDir(), SIP_PICTURE_URI);
@@ -150,7 +154,7 @@ public class OmFileHelper {
                        img = new File(getUploadProfilesUserDir(userId), uri == 
null ? "" : uri);
                }
                if (img == null || !img.exists() || img.isDirectory()) {
-                       img = getDefaultProfilePicture();
+                       img = def;
                }
                return img;
        }
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/AdminSavePanel.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/AdminSavePanel.java
index 21eaf7e..24098c4 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/AdminSavePanel.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/AdminSavePanel.java
@@ -31,7 +31,7 @@ public abstract class AdminSavePanel<T> extends 
FormSaveRefreshPanel<T> {
        private final Label newRecord = new Label("newRecord", Model.of(""));
        private final Form<T> form;
        private ConfirmableAjaxBorder delBtn;
-       private AjaxButton purgeBtn;
+       private ConfirmableAjaxBorder purgeBtn;
        private AjaxButton restoreBtn;
 
        public AdminSavePanel(String id, final Form<T> form) {
@@ -86,7 +86,7 @@ public abstract class AdminSavePanel<T> extends 
FormSaveRefreshPanel<T> {
                                onDeleteSubmit(target, form);
                        }
                };
-               purgeBtn = new AjaxButton("btn-purge", form) {
+               purgeBtn = new ConfirmableAjaxBorder("btn-purge", 
getString("80"), getString("833"), cForm) {
                        private static final long serialVersionUID = 1L;
 
                        @Override
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/users/UserForm.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/users/UserForm.java
index 2083660..f179143 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/users/UserForm.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/admin/users/UserForm.java
@@ -27,8 +27,10 @@ import static 
org.apache.openmeetings.web.app.WebSession.getRights;
 import static org.apache.openmeetings.web.app.WebSession.getUserId;
 import static 
org.apache.wicket.validation.validator.StringValidator.minimumLength;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -42,11 +44,14 @@ import org.apache.openmeetings.db.dao.server.OAuth2Dao;
 import org.apache.openmeetings.db.dao.user.UserDao;
 import org.apache.openmeetings.db.entity.server.LdapConfig;
 import org.apache.openmeetings.db.entity.server.OAuthServer;
+import org.apache.openmeetings.db.entity.user.Address;
+import org.apache.openmeetings.db.entity.user.AsteriskSipUser;
 import org.apache.openmeetings.db.entity.user.User;
 import org.apache.openmeetings.db.entity.user.User.Right;
 import org.apache.openmeetings.db.entity.user.User.Type;
 import org.apache.openmeetings.db.util.AuthLevelUtil;
 import org.apache.openmeetings.service.mail.EmailManager;
+import org.apache.openmeetings.util.OmFileHelper;
 import org.apache.openmeetings.web.admin.AdminBaseForm;
 import org.apache.openmeetings.web.common.ComunityUserForm;
 import org.apache.openmeetings.web.common.GeneralUserForm;
@@ -200,6 +205,27 @@ public class UserForm extends AdminBaseForm<User> {
        }
 
        @Override
+       protected void onPurgeSubmit(AjaxRequestTarget target, Form<?> form) {
+               User u = getModelObject();
+               u.setDeleted(true);
+               u.setSipUser(new AsteriskSipUser());
+               u.setAddress(new Address());
+               u.setAge(new Date());
+               u.setExternalId(null);
+               final String purged = String.format("Purged %s", 
UUID.randomUUID());
+               u.setFirstname(purged);
+               u.setLastname(purged);
+               u.setLogin(purged);
+               File pic = OmFileHelper.getUserProfilePicture(u.getId(), 
u.getPictureuri(), null);
+               if (pic != null) {
+                       pic.delete();
+               }
+               //u.
+               //User fields "age, externaluserid, firstname, lastname, login, 
pictureuri" will be replaced with "Purged_some_hash"
+               //onSaveSubmit(target, form);
+       }
+
+       @Override
        protected void onSaveSubmit(AjaxRequestTarget target, Form<?> form) {
                if (isAdminPassRequired()) {
                        
adminPass.setAction((SerializableConsumer<AjaxRequestTarget>)t -> saveUser(t, 
password.getModelObject()));

-- 
To stop receiving notification emails like this one, please contact
solo...@apache.org.

Reply via email to