How to automatically create user for email submission

Discuss problems installing or using TrackStudio.

How to automatically create user for email submission

Postby admin » Sat Mar 05, 2005 9:37 pm

The following diff shows how to modify e-mail submission adapter to automatically create new user accounts when required:

Code: Select all
Index: src/gran/app/adapter/store/MailImportTaskStoreAdapter.java
===================================================================
--- src/gran/app/adapter/store/MailImportTaskStoreAdapter.java  (revision 2991)
+++ src/gran/app/adapter/store/MailImportTaskStoreAdapter.java  (working copy)
@@ -3,6 +3,7 @@
 import com.trackstudio.kernel.cache.TaskCacheManager;
 import com.trackstudio.kernel.cache.UserCacheManager;
 import com.trackstudio.kernel.manager.KernelManager;
+import com.trackstudio.kernel.manager.TSPropertyManager;
 import gran.app.Config;
 import gran.app.UdfValue;
 import gran.app.adapter.AdapterManager;
@@ -40,6 +41,8 @@
     }
 
     public boolean processImpl(MimeMessage currentMessage, boolean res) throws GranException {
+        String taskId = null;
+        String userId = null;
         if (res) return res;
         logger.debug("MailImportTaskStoreAdapter process caled");
         try {
@@ -67,8 +70,6 @@
                 logger.debug("not exist mail import for anything task");
                 return false;
             }
-            String taskId = null;
-            String userId = null;
             String sessionId = null;
             sessionId = SessionManager.getInstance().create(UserCacheManager.getInstance().find("1"));
             SessionContext sc = SessionManager.getInstance().getSessionContext(sessionId);
@@ -93,6 +94,11 @@
                 if(mi.getTask() == null)
                     continue;
                 userId = KernelManager.getUser().findUserIdByEmailNameProject(from, name, mi.getTask().getId());
+                if (userId == null) {
+                    userId = AdapterManager.getInstance().getSecuredUserAdapterManager()
+                            .createUser(sc,TSPropertyManager.getProperty("mail.new_user.managerId"),
+                                    name, name, TSPropertyManager.getProperty("mail.new_user.prstatusId"));
+                }
                 if ((mi.getKeywords() == null || mi.getKeywords().length() == 0) && taskId == null && userId !=
null)
                     taskId = mi.getTask().getId();
                 else if (userId != null
@@ -100,12 +106,14 @@
                         && ((mi.getSearchIn().intValue() == 1 && subject != null &&
subject.toLowerCase().indexOf(mi.getKeywords().toLowerCase()) != -1) || (mi.getSearchIn().intValue() == 0 && body
!= null && body.toLowerCase().indexOf(mi.getKeywords().toLowerCase()) != -1))) {
                     sessionId = SessionManager.getInstance().create(UserCacheManager.getInstance().find(userId));
                     sc = SessionManager.getInstance().getSessionContext(sessionId);
-                    addNewTask(sc, subject, mi.getTask().getId(), body, attaches);
+                    addNewTask(sc, subject, mi.getTask().getId(), body, attaches, userId, name, from);
+
                     return true;
                 }
             }
             if (taskId != null && userId != null) {
-                addNewTask(sc, subject, taskId, body, attaches);
+                addNewTask(sc, subject, taskId, body, attaches, userId, name, from);
+
                 return true;
             }
         } catch (Exception e) {
@@ -115,11 +123,11 @@
         return false;
     }
 
-    private void addNewTask(SessionContext sc, String subject, String parentTaskId, String body, HashMap
attaches) throws GranException {
+    private void addNewTask(SessionContext sc, String subject, String parentTaskId, String body, HashMap
attaches, String submitterId, String name, String from) throws GranException {
         logger.debug("taskId: " + parentTaskId);
         logger.debug("attaches: " + attaches);
         if (!(sc.canAction(com.trackstudio.kernel.cache.Action.createTask, parentTaskId)))
-            return;             
+            return ;
         if (subject == null || subject.equals(""))
             subject = "Unnamed";
         if (subject.length() > 200)
@@ -127,7 +135,7 @@
         body = "<pre>" + HTMLEncoder.encode(LongStringFixer.fixLongString(body)) + "</pre>";
         String mailimportid = KernelManager.getMailImport().getMailImportId(parentTaskId);
         SecuredMailImportBean m =
AdapterManager.getInstance().getSecuredFindAdapterManager().findMailImportById(sc, mailimportid);
-        String taskId = KernelManager.getTask().createTask(parentTaskId, sc.getUserId(), m.getCategoryId(),
subject, TaskCacheManager.getInstance().find(parentTaskId).getDeadline());
+        String taskId = KernelManager.getTask().createTask(parentTaskId, submitterId, m.getCategoryId(), subject,
TaskCacheManager.getInstance().find(parentTaskId).getDeadline());
         String defaultHandlerId = null;
         // default handler - inherited from parent task, when available
         if (parentTaskId != null) {
@@ -174,6 +182,18 @@
         }
         //
         logger.debug("TASK ADDED THROUGH MAILIMPORT");
+        AdapterManager.getInstance().getSecuredUserAdapterManager()
+                .updateUser(sc, submitterId, name, "", from,
+                TSPropertyManager.getProperty("mail.new_user.prstatusId"),
+                TSPropertyManager.getProperty("mail.new_user.managerId"),
+                TSPropertyManager.getProperty("mail.new_user.timezone"),
+                TSPropertyManager.getProperty("mail.new_user.locale"),
+                TSPropertyManager.getProperty("mail.new_user.company"),
+                TSPropertyManager.getProperty("mail.new_user.emailTypeId"),
+                taskId, null, true, true, new Integer(1), "olu", "ostm");
+        AdapterManager.getInstance().getSecuredAclAdapterManager().createAcl(sc, taskId, submitterId);
+        AdapterManager.getInstance().getSecuredUserAdapterManager().changePassword(sc, submitterId,
TSPropertyManager.getProperty("mail.new_user.password"), TSPropertyManager.getProperty("mail.new_user.password"));
+        return ;
     }
 
 }
Index: etc/properties/trackstudio.mail.properties
===================================================================
--- etc/properties/trackstudio.mail.properties  (revision 2991)
+++ etc/properties/trackstudio.mail.properties  (working copy)
@@ -91,4 +91,34 @@
 # Other options             #
 #############################
 
-mail.debug false
\ No newline at end of file
+mail.debug false
+
+## Options for autocreated users
+
+# it is can be:
+# 001 department manager       4028969bffaffc3200ffb003d1960010
+# 030 software developer       4028969bffaffc3200ffb0129a6700ba
+# 040 software tester          4028969bffaffc3200ffb01ad09b012d
+# 010 line manager             4028969bffb0213900ffb029b4f60005
+# 020 customer support member  4028969bffb0213900ffb03007b200a6
+# 100 external customer                4028969bffb0fe8500ffb10fb88a009f
+# administrator                        5
+mail.new_user.prstatusId       4028969bffb0fe8500ffb10fb88a009f
+
+# userId who will be parent for new user
+mail.new_user.managerId                4028969bffb0fe8500ffb10f125d009e
+
+# new user's timezone
+mail.new_user.timezone         America/New_York
+
+# new user's local
+mail.new_user.locale           en_US
+
+# new user's company
+mail.new_user.company         
+
+# default e-mail template
+mail.new_user.emailTypeId      1
+
+# password for new user
+mail.new_user.password         63a9f0ea7bb98050796b649e85481845
Maxim Kramarenko (mailto: maximkr@trackstudio.com)
TrackStudio - Hierarchical Bug & Issue Tracking Software
http://www.trackstudio.com
admin
Site Admin
 
Posts: 8148
Joined: Thu Jan 01, 1970 3:00 am
Location: Smolensk, Russia

Return to TrackStudio Support

Who is online

Users browsing this forum: Google [Bot] and 13 guests

cron