Improve collaboration mail.

This commit is contained in:
Paulo Gustavo Veiga 2012-06-13 23:04:29 -03:00
parent c4d2acec7b
commit 226a7a0ff9
23 changed files with 260 additions and 137 deletions

View File

@ -36,8 +36,7 @@ public class UserManagerImpl
private PasswordEncoder passwordEncoder;
public void setEncoder(PasswordEncoder passwordEncoder)
{
public void setEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
@ -47,14 +46,12 @@ public class UserManagerImpl
@Override
public User getUserBy(final String email) {
final User user;
final List users = getHibernateTemplate().find("from com.wisemapping.model.User colaborator where email=?", email);
public User getUserBy(@NotNull final String email) {
User user = null;
final List<User> users = getHibernateTemplate().find("from com.wisemapping.model.User colaborator where email=?", email);
if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same email!";
user = (User) users.get(0);
} else {
user = null;
user = users.get(0);
}
return user;
}
@ -100,13 +97,13 @@ public class UserManagerImpl
@Override
public void createUser(User user) {
assert user != null : "Trying to store a null user";
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
getHibernateTemplate().saveOrUpdate(user);
}
@Override
public User createUser(@NotNull User user, @NotNull Collaborator col) {
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
assert user != null : "Trying to store a null user";
final Set<Collaboration> set = col.getCollaborations();
@ -139,7 +136,7 @@ public class UserManagerImpl
public void updateUser(User user) {
assert user != null : "user is null";
user.setPassword(passwordEncoder.encodePassword(user.getPassword(),null));
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
getHibernateTemplate().update(user);
}

View File

@ -39,19 +39,16 @@ public final class Mailer {
//~ Methods ..............................................................................................
public Mailer(String registrationEmail, String siteEmail)
{
public Mailer(String registrationEmail, String siteEmail) {
this.registrationEmail = registrationEmail;
this.siteEmail = siteEmail;
}
public String getRegistrationEmail()
{
public String getRegistrationEmail() {
return registrationEmail;
}
public String getSiteEmail()
{
public String getSiteEmail() {
return siteEmail;
}
@ -66,11 +63,12 @@ public final class Mailer {
message.setFrom(from);
message.setSubject(subject);
final String text =
final String messageBody =
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/mail/" + templateMail,
model);
System.out.println(message);
message.setText(text, true);
message.setText(messageBody, true);
}
};

View File

@ -0,0 +1,83 @@
/*
* Copyright [2011] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.wisemapping.mail;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.Map;
final public class NotificationService {
@Autowired
private Mailer mailer;
private String baseUrl;
public NotificationService() {
}
public void newCollaboration(@NotNull Collaboration collaboration, @NotNull MindMap mindmap, @NotNull User user, @Nullable String message) {
try {
// Sent collaboration email ...
final String formMail = mailer.getSiteEmail();
// Is the user already registered user ?.
final String collabEmail = collaboration.getCollaborator().getEmail();
// Build the subject ...
final String subject = user.getFullName() + " has shared a mindmap with you";
// Fill template properties ...
final Map<String, Object> model = new HashMap<String, Object>();
model.put("mindmap", mindmap);
model.put("message", "message");
model.put("ownerName", user.getFirstname());
model.put("mapEditUrl", baseUrl + "/c/maps/" + mindmap.getId() + "/edit");
model.put("baseUrl", baseUrl + "/c/maps/" + mindmap.getId() + "/edit");
mailer.sendEmail(formMail, collabEmail, subject, model, "newCollaboration.vm");
} catch (Exception e) {
handleException(e);
}
}
private void handleException(Exception e) {
e.printStackTrace();
}
public void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
}
public void setMailer(Mailer mailer) {
this.mailer = mailer;
}
}

View File

@ -45,6 +45,10 @@ public class User
return tags;
}
public String getFullName() {
return this.getFirstname() + " " + this.getLastname();
}
public String getFirstname() {
return firstname;
}

View File

@ -238,7 +238,7 @@ public class MindmapController extends BaseController {
// Remove all collaborations that no applies anymore ..
for (final Collaboration collaboration : collabsToRemove) {
mindmapService.removeCollaboration(collaboration);
mindmapService.removeCollaboration(mindMap, collaboration);
}
}

View File

@ -25,6 +25,8 @@ import com.wisemapping.exceptions.UnexpectedArgumentException;
import com.wisemapping.security.Utils;
import com.wisemapping.service.MindmapService;
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class BaseSecurityAdvice {
private MindmapService mindmapService = null;
@ -47,9 +49,9 @@ public abstract class BaseSecurityAdvice {
}
}
protected abstract boolean isAllowed(User user, MindMap map);
protected abstract boolean isAllowed(@Nullable User user, MindMap map);
protected abstract boolean isAllowed(User user, int mapId);
protected abstract boolean isAllowed(@Nullable User user, int mapId);
protected MindmapService getMindmapService() {
return mindmapService;

View File

@ -25,6 +25,7 @@ import com.wisemapping.model.MindMap;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class UpdateSecurityAdvise
extends BaseSecurityAdvice
@ -35,7 +36,7 @@ public class UpdateSecurityAdvise
return methodInvocation.proceed();
}
protected boolean isAllowed(@NotNull User user, @NotNull MindMap map) {
protected boolean isAllowed(@Nullable User user, @NotNull MindMap map) {
boolean result;
if (map.getCreator() == null) {
// This means that the map is new and is an add operation.
@ -46,7 +47,7 @@ public class UpdateSecurityAdvise
return result;
}
protected boolean isAllowed(User user, int mapId) {
protected boolean isAllowed(@Nullable User user, int mapId) {
return getMindmapService().hasPermissions(user, mapId, CollaborationRole.EDITOR);
}
}

View File

@ -34,11 +34,11 @@ public class ViewBaseSecurityAdvise
return methodInvocation.proceed();
}
protected boolean isAllowed(User user, MindMap map) {
protected boolean isAllowed(@NotNull User user, MindMap map) {
return getMindmapService().hasPermissions(user, map, CollaborationRole.VIEWER);
}
protected boolean isAllowed(User user, int mapId) {
protected boolean isAllowed(@NotNull User user, int mapId) {
return getMindmapService().hasPermissions(user, mapId, CollaborationRole.VIEWER);
}
}

View File

@ -21,6 +21,7 @@ package com.wisemapping.service;
import com.wisemapping.model.*;
import com.wisemapping.exceptions.WiseMappingException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.io.IOException;
@ -42,7 +43,7 @@ public interface MindmapService {
public void addCollaboration(@NotNull MindMap mindmap, @NotNull String email, @NotNull CollaborationRole role)
throws CollaborationException;
public void removeCollaboration(@NotNull Collaboration collaboration) throws CollaborationException;
public void removeCollaboration(@NotNull MindMap mindmap, @NotNull Collaboration collaboration) throws CollaborationException;
public void addTags(MindMap mindmap, String tags);
@ -52,9 +53,9 @@ public interface MindmapService {
public List<MindMapHistory> getMindMapHistory(int mindmapId);
public boolean hasPermissions(User user, MindMap map, CollaborationRole allowedRole);
public boolean hasPermissions(@Nullable User user, MindMap map, CollaborationRole allowedRole);
public boolean hasPermissions(User user, int mapId, CollaborationRole allowedRole);
public boolean hasPermissions(@Nullable User user, int mapId, CollaborationRole allowedRole);
public void addWelcomeMindmap(User user) throws WiseMappingException;

View File

@ -21,9 +21,13 @@ package com.wisemapping.service;
import com.wisemapping.dao.MindmapManager;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.mail.Mailer;
import com.wisemapping.mail.NotificationService;
import com.wisemapping.model.*;
import com.wisemapping.security.Utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.io.IOException;
import java.util.*;
@ -32,9 +36,15 @@ import java.util.*;
public class MindmapServiceImpl
implements MindmapService {
@Autowired
private MindmapManager mindmapManager;
@Autowired
@Qualifier("userService")
private UserService userService;
private Mailer mailer;
@Autowired
private NotificationService notificationService;
@Override
public boolean hasPermissions(@NotNull User user, int mapId, @NotNull CollaborationRole grantedRole) {
@ -89,7 +99,7 @@ public class MindmapServiceImpl
}
@Override
public void removeCollaboration(@NotNull Collaboration collaboration) throws CollaborationException {
public void removeCollaboration(@NotNull MindMap mindmap, @NotNull Collaboration collaboration) throws CollaborationException {
// remove collaborator association
final MindMap mindMap = collaboration.getMindMap();
final Set<Collaboration> collaborations = mindMap.getCollaborations();
@ -110,7 +120,7 @@ public class MindmapServiceImpl
} else {
final Collaboration collaboration = mindmap.findCollaboration(user);
if (collaboration != null) {
this.removeCollaboration(collaboration);
this.removeCollaboration(mindmap, collaboration);
}
}
}
@ -166,16 +176,9 @@ public class MindmapServiceImpl
mindmap.getCollaborations().add(collaboration);
mindmapManager.saveMindmap(mindmap);
try {
// Sent collaboration email ...
final Map<String, Object> model = new HashMap<String, Object>();
model.put("role", role);
model.put("map", mindmap);
model.put("message", "message");
mailer.sendEmail(mailer.getSiteEmail(), email, "Collaboration", model, "newColaborator.vm");
} catch (Exception e) {
e.printStackTrace();
}
// Notify by email ...
final User user = Utils.getUser();
notificationService.newCollaboration(collaboration, mindmap, user, null);
} else if (collaboration.getRole() != role) {
// If the relationship already exists and the role changed then only update the role
@ -264,7 +267,7 @@ public class MindmapServiceImpl
this.userService = userService;
}
public void setMailer(Mailer mailer) {
this.mailer = mailer;
public void setNotificationService(NotificationService notificationService) {
this.notificationService = notificationService;
}
}

View File

@ -24,33 +24,21 @@ database.password=
#------------------------
# Plain SMTP Server Configuration
#------------------------
#mail.smtp.socketFactory.class=javax.net.DefaultSocketFactory
#mail.smtp.socketFactory.port=25
#mail.smtp.auth = false
#mail.host=localhost
#mail.user=
#mail.password=
#------------------------
# SSL SMTP Server Configuration
#------------------------
# mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
#mail.smtp.socketFactory.port=465
#mail.smtp.auth = false
#mail.host=localhost
#mail.user=
#mail.password=
#------------------------
# GMAIL SMTP Configuration
#------------------------
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.socketFactory.port=587
mail.smtp.auth = true
mail.host=smtp.gmail.com
mail.user=example@gmail.com
mail.password=
mail.smtp.port=587
mail.smtp.host=smtp.gmail.com
mail.username=pveiga@gmail.com
mail.password=p0w3rwdgg
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp.quitwait=false
#------------------------
# Domain address

View File

@ -1,6 +1,6 @@
log4j.rootLogger=WARN, stdout, R
log4j.logger.com.wisemapping=WARN,stdout,R
log4j.logger.org.springframework=DEBUG,stdout,R
log4j.logger.org.springframework=WARN,stdout,R
log4j.logger.org.codehaus.jackson=WARN,stdout,R
log4j.additivity.org.hibernate.SQL=false

View File

@ -1,22 +1,41 @@
<html>
<body>
<h3>Welcome to WiseMapping!</h3>
<p>
Your account has been activated.
First Name: ${user.firstname}
Last Name: ${user.lastname}
Username: ${user.username}
</p>
<p>
Thank you for using WiseMapping.
</p>
<p>
For questions or concerns regarding your account, send us an email to support@wisemapping.com.
</p>
<p>
Best regards, <br/>
WiseMapping Team
<a href="http://www.wisemapping.com">WiseMapping Site</a>
</p>
<div style="background-color: #d1e4f0; max-width: 650px; font-family: Arial, sans-serif; color: #000; padding: 5px;">
<div style="height: 36px; font-size: 14px; font-weight: bold; padding-bottom: 4px;">
<table style="display: inline;width: 100%;">
<tbody>
<tr>
<td height="35px" width="2px" style="padding: 0; padding-right: 5px; text-align:center">
<img src="https://ssl.gstatic.com/docs/documents/share/images/services/document-1.png"
alt="Document"/>
</td>
<td valign="middle" height="32px" style="padding: 0;">I've shared <a
href='https://docs.google.com/document/d/1kx48Yhpt01y2LZnIVGJNgKTg_IlvQMh=47R2NIwRn4Hg/edit'>Untitled
document
</a>
</td>
</tr>
</tbody>
</table>
</div>
<div style="font-size: 13px; background-color: #FFF; padding: 10px 7px 7px 7px;">
Click to open:
<ul style="list-style-type: none; padding: 0; margin: 0;">
<li style="margin: 0;">
<a href="https://docs.google.com/document/d/1kx48Yhpt01y2LZnIVG=JNgKTg_IlvQMh47R2NIwRn4Hg/edit">Untitled
document</a></li>
</ul>
<span style="color: #898989;">Google Docs makes it easy to create, store and share online documents, spreadsheets and presentations.</span>
<div style="text-align: right;">
<a href="https://docs.google.com">
<img style="border: 0;margin-top: 10px;"
src="https://ssl.gstatic.com/docs/documents/share/images/services/docs_logo-1.gif"
alt="Logo for Google Docs"/>
</a>
</div>
</div>
</div>
</body>
</html>

View File

@ -1,24 +1,29 @@
<html>
<body>
<h3>Welcome to WiseMapping!</h3>
<p>
To active your account and verify your e-mail address, please click on the following link.
To active your account and verify your e-mail address, please click on the following link.
</p>
<a href="${emailcheck}">${emailcheck}</a>
<a href="${emailcheck}">${emailcheck}</a>
</p>
<p>
If you have received this mail by error, you do not need to take any action to cancel the account. The account will not be activated, and you will not receive any futher emails.
If you have received this mail by error, you do not need to take any action to cancel the account. The account will
not be activated, and you will not receive any futher emails.
</p>
<p>
If clicking the link above does not work, copy and paste the URL in a new browser window instead.
If clicking the link above does not work, copy and paste the URL in a new browser window instead.
</p>
<p>
For questions or concerns regarding your account, send us an email to support@wisemapping.com.
For questions or concerns regarding your account, send us an email to support@wisemapping.com.
</p>
<p>
Cheers, <br/>
The WiseMapping Team.
<a href="http://www.wisemapping.com">WiseMapping Site</a>
Cheers, <br/>
The WiseMapping Team.
<a href="http://www.wisemapping.com">WiseMapping Site</a>
</p>
</body>
</html>
</html>

View File

@ -1,7 +0,0 @@
<html>
<body>
<p>
${message}
</p>
</body>
</html>

View File

@ -0,0 +1,37 @@
<html>
<body>
<div style="background-color: #fbeed5; max-width: 650px; font-family: Arial, sans-serif; color: #000; padding: 5px;">
<div style="height: 36px; font-size: 14px; font-weight: bold; padding-bottom: 4px;">
<table style="display: inline;width: 100%;">
<tbody>
<tr>
<td height="35px" width="2px" style="padding: 0; padding-right: 5px; text-align:center">
<img src="${mapEditUrl}" alt="Mindmap"/>
</td>
<td valign="middle" height="32px" style="padding: 0;">I've shared <a href='${mapEditUrl}'>
${mindmap.title}</a> mindmap with you.
</td>
</tr>
</tbody>
</table>
</div>
<div style="font-size: 13px; background-color: #FFF; padding: 10px 7px 7px 7px;">
#if( ! $message )
<p>${message}</p>
#end
<p>Click to open: <a href="${mapEditUrl}">${mindmap.title}</a></p>
<span style="color: #898989;">WiseMapping makes it easy to create, store and share online mindmap.</span>
<div style="text-align: right;">
<a href="${baseUrl}">
<img style="border: 0;margin-top: 10px;"
src="${baseUrl}/images/logo-small.png"
alt="WiseMapping Log"/>
</a>
</div>
</div>
</div>
</body>
</html>

View File

@ -2,6 +2,12 @@
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="mailer" class="com.wisemapping.mail.Mailer" singleton="true">
<constructor-arg index="0" value="${mail.registrationEmail}"/>
<constructor-arg index="1" value="${mail.siteEmail}"/>
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
<bean id="userServiceTarget" class="com.wisemapping.service.UserServiceImpl">
<property name="userManager" ref="userManager"/>
@ -24,7 +30,7 @@
<bean id="mindMapServiceTarget" class="com.wisemapping.service.MindmapServiceImpl">
<property name="mindmapManager" ref="mindmapManager"/>
<property name="userService" ref="userService"/>
<property name="mailer" ref="mailer"/>
<property name="notificationService" ref="notificationService"/>
</bean>
<bean id="mindmapService"
@ -40,37 +46,19 @@
<property name="target" ref="mindMapServiceTarget"/>
</bean>
<bean id="smtpAuthenticator" class="com.wisemapping.mail.SmtpAuthenticator">
<constructor-arg value="${mail.user}"/>
<constructor-arg value="${mail.password}"/>
</bean>
<bean id="mailSession" class="javax.mail.Session" factory-method="getInstance">
<constructor-arg>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.smtp.host}"/>
<property name="port" value="${mail.smtp.port}"/>
<property name="protocol" value="smtp"/>
<property name="username" value="${mail.username}"/>
<property name="password" value="${mail.password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
<prop key="mail.smtp.socketFactory.port">${mail.smtp.socketFactory.port}</prop>
<prop key="mail.smtp.socketFactory.class">${mail.smtp.socketFactory.class}</prop>
<prop key="mail.smtp.socketFactory.fallback">false</prop>
<prop key="mail.smtp.quitwait">false</prop>
<prop key="mail.smtp.debug">true</prop>
<prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
<prop key="mail.smtp.quitwait">${mail.smtp.quitwait}</prop>
</props>
</constructor-arg>
<constructor-arg ref="smtpAuthenticator"/>
</bean>
<bean id="mailer" class="com.wisemapping.mail.Mailer" singleton="true">
<constructor-arg index="0" value="${mail.registrationEmail}"/>
<constructor-arg index="1" value="${mail.siteEmail}"/>
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}"/>
<property name="session" ref="mailSession"/>
</property>
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
@ -81,4 +69,10 @@
</value>
</property>
</bean>
<bean id="notificationService" class="com.wisemapping.mail.NotificationService" singleton="true">
<property name="baseUrl" value="${site.baseurl}"/>
<property name="mailer" ref="mailer"/>
</bean>
</beans>

View File

@ -136,7 +136,7 @@ $(function() {
success : function(data, textStatus, jqXHR) {
// Owner roles is the first in the table ...
var collabs = data.collaborations.sort(function(a, b) {
return a.role > b.role;
return a.role <= b.role;
});
// Add all the colums in the table ...

View File

@ -29,12 +29,11 @@ public class JsonTest {
@Test
void serialize() throws IOException {
ObjectMapper mapper = new ObjectMapper();
final RestMindmap value = new RestMindmap();
value.setTitle("titl");
value.setTitle("desck");
final String restMindmap = mapper.writeValueAsString(value);
System.out.println(restMindmap);
//
// final RestMindmap value = new RestMindmap();
// value.setTitle("titl");
// value.setTitle("desck");
// final String restMindmap = mapper.writeValueAsString(value);
}
@Test

View File

@ -31,7 +31,6 @@ editor_properties varchar(512)
--FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id)
);
CREATE TABLE MINDMAP_HISTORY
(id INTEGER NOT NULL IDENTITY,
xml LONGVARBINARY NOT NULL,
@ -41,7 +40,7 @@ creator_user varchar(255));
CREATE TABLE COLLABORATION_PROPERTIES
(id INTEGER NOT NULL IDENTITY,
starred BOOLEAN NOT NULL,
starred BOOLEAN NOT NULL
);
CREATE TABLE COLLABORATION

View File

@ -1,6 +1,6 @@
DROP TABLE TAG;
DROP TABLE COLLABORATION_PROPERTIES;
DROP TABLE COLLABORATION;
DROP TABLE COLLABORATION_PROPERTIES;
DROP TABLE MINDMAP_HISTORY;
DROP TABLE MINDMAP;
DROP TABLE USER;

View File

@ -43,7 +43,7 @@ creator_user varchar(255) CHARACTER SET utf8
CREATE TABLE COLLABORATION_PROPERTIES(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
starred BOOL NOT NULL default 0,
starred BOOL NOT NULL default 0
) CHARACTER SET utf8;
CREATE TABLE COLLABORATION (

View File

@ -1,6 +1,6 @@
DROP TABLE TAG;
DROP TABLE COLLABORATION_PROPERTIES;
DROP TABLE COLLABORATION;
DROP TABLE COLLABORATION_PROPERTIES;
DROP TABLE MINDMAP_HISTORY;
DROP TABLE MINDMAP;
DROP TABLE USER;