Browse code

BM-14050 Fix: users are now notified when admin0 share a resource/mailbox/calendar...

Vincent Vignaud authored on 05/03/2019 16:53:11
Showing 6 changed files
... ...
@@ -28,12 +28,11 @@ import org.slf4j.LoggerFactory;
28 28
 import net.bluemind.addressbook.api.AddressBookContainerType;
29 29
 import net.bluemind.core.api.fault.ServerFault;
30 30
 import net.bluemind.core.container.hooks.AbstractEmailHook;
31
-import net.bluemind.core.container.hooks.IAclHook;
32 31
 import net.bluemind.core.container.model.ContainerDescriptor;
33 32
 import net.bluemind.core.container.model.acl.AccessControlEntry;
34 33
 import net.bluemind.core.rest.BmContext;
35 34
 
36
-public class AddressbookEmailHook extends AbstractEmailHook implements IAclHook {
35
+public class AddressbookEmailHook extends AbstractEmailHook {
37 36
 
38 37
 	private static final Logger logger = LoggerFactory.getLogger(AddressbookEmailHook.class);
39 38
 
... ...
@@ -53,7 +52,7 @@ public class AddressbookEmailHook extends AbstractEmailHook implements IAclHook
53 52
 
54 53
 				List<AccessControlEntry> added = new ArrayList<>(current);
55 54
 				added.removeAll(previous);
56
-				notify(context, container.name, "AddressBookSubject.ftl", "AddressBookBody.ftl", added, uid, type);
55
+				notify(context, container.domainUid, container.name, added, uid, type);
57 56
 
58 57
 			} catch (ServerFault e) {
59 58
 				logger.error(e.getMessage(), e);
... ...
@@ -61,4 +60,14 @@ public class AddressbookEmailHook extends AbstractEmailHook implements IAclHook
61 60
 		}
62 61
 	}
63 62
 
63
+	@Override
64
+	protected String getTemplateSubject() {
65
+		return "AddressBookSubject.ftl";
66
+	}
67
+
68
+	@Override
69
+	protected String getTemplateBody() {
70
+		return "AddressBookBody.ftl";
71
+	}
72
+
64 73
 }
... ...
@@ -28,12 +28,11 @@ import org.slf4j.LoggerFactory;
28 28
 import net.bluemind.calendar.api.CalendarContainerType;
29 29
 import net.bluemind.core.api.fault.ServerFault;
30 30
 import net.bluemind.core.container.hooks.AbstractEmailHook;
31
-import net.bluemind.core.container.hooks.IAclHook;
32 31
 import net.bluemind.core.container.model.ContainerDescriptor;
33 32
 import net.bluemind.core.container.model.acl.AccessControlEntry;
34 33
 import net.bluemind.core.rest.BmContext;
35 34
 
36
-public class CalendarEmailHook extends AbstractEmailHook implements IAclHook {
35
+public class CalendarEmailHook extends AbstractEmailHook {
37 36
 
38 37
 	private static final Logger logger = LoggerFactory.getLogger(CalendarEmailHook.class);
39 38
 
... ...
@@ -52,7 +51,7 @@ public class CalendarEmailHook extends AbstractEmailHook implements IAclHook {
52 51
 				List<AccessControlEntry> added = new ArrayList<>(current);
53 52
 				added.removeAll(previous);
54 53
 
55
-				notify(context, container.name, "CalendarSubject.ftl", "CalendarBody.ftl", added, uid, type);
54
+				notify(context, container.domainUid, container.name, added, uid, type);
56 55
 
57 56
 			} catch (ServerFault e) {
58 57
 				logger.error(e.getMessage(), e);
... ...
@@ -60,4 +59,14 @@ public class CalendarEmailHook extends AbstractEmailHook implements IAclHook {
60 59
 		}
61 60
 	}
62 61
 
62
+	@Override
63
+	protected String getTemplateSubject() {
64
+		return "CalendarSubject.ftl";
65
+	}
66
+
67
+	@Override
68
+	protected String getTemplateBody() {
69
+		return "CalendarBody.ftl";
70
+	}
71
+
63 72
 }
... ...
@@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.core.runtime,
17 17
  net.bluemind.addressbook.api,
18 18
  net.bluemind.core.sendmail,
19 19
  net.bluemind.i18n.labels,
20
- net.bluemind.group.api
20
+ net.bluemind.group.api,
21
+ net.bluemind.domain.api
21 22
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
22 23
 Bundle-ActivationPolicy: lazy
23 24
 Export-Package: net.bluemind.core.container.hooks
... ...
@@ -30,10 +30,12 @@ import org.apache.james.mime4j.stream.RawField;
30 30
 import org.slf4j.Logger;
31 31
 import org.slf4j.LoggerFactory;
32 32
 import org.vertx.java.core.eventbus.EventBus;
33
+
33 34
 import freemarker.template.Configuration;
34 35
 import freemarker.template.Template;
35 36
 import freemarker.template.TemplateException;
36 37
 import net.bluemind.core.api.fault.ServerFault;
38
+import net.bluemind.core.container.model.ContainerDescriptor;
37 39
 import net.bluemind.core.container.model.acl.AccessControlEntry;
38 40
 import net.bluemind.core.context.SecurityContext;
39 41
 import net.bluemind.core.rest.BmContext;
... ...
@@ -42,8 +44,8 @@ import net.bluemind.core.rest.ServerSideServiceProvider;
42 44
 import net.bluemind.core.sendmail.Mail;
43 45
 import net.bluemind.core.sendmail.SendMailAddress;
44 46
 import net.bluemind.core.sendmail.SendmailHelper;
45
-import net.bluemind.directory.api.DirEntry;
46 47
 import net.bluemind.directory.api.BaseDirEntry.Kind;
48
+import net.bluemind.directory.api.DirEntry;
47 49
 import net.bluemind.directory.api.IDirectory;
48 50
 import net.bluemind.group.api.IGroup;
49 51
 import net.bluemind.group.api.Member;
... ...
@@ -51,7 +53,7 @@ import net.bluemind.i18n.labels.I18nLabels;
51 53
 import net.bluemind.lib.vertx.VertxPlatform;
52 54
 import net.bluemind.user.api.IUserSettings;
53 55
 
54
-public abstract class AbstractEmailHook {
56
+public abstract class AbstractEmailHook implements IAclHook {
55 57
 
56 58
 	private static final Logger logger = LoggerFactory.getLogger(AbstractEmailHook.class);
57 59
 
... ...
@@ -64,8 +66,11 @@ public abstract class AbstractEmailHook {
64 66
 		eventBus = VertxPlatform.eventBus();
65 67
 	}
66 68
 
67
-	protected void notify(BmContext context, String entityDisplayName, String templateSubjet, String templateBody,
68
-			List<AccessControlEntry> entries, RawField... headers) throws ServerFault {
69
+	public abstract void onAclChanged(BmContext context, ContainerDescriptor container,
70
+			List<AccessControlEntry> previous, List<AccessControlEntry> current);
71
+
72
+	protected void notify(BmContext context, String domainUid, String displayName, List<AccessControlEntry> entries,
73
+			RawField... headers) throws ServerFault {
69 74
 
70 75
 		if (entries.size() == 0) {
71 76
 			logger.error("no one to notify");
... ...
@@ -74,8 +79,10 @@ public abstract class AbstractEmailHook {
74 79
 
75 80
 		SecurityContext sc = context.getSecurityContext();
76 81
 
77
-		IDirectory dirService = context.provider().instance(IDirectory.class, sc.getContainerUid());
78
-		DirEntry fromDE = dirService.findByEntryUid(sc.getSubject());
82
+		IDirectory fromDirService = context.provider().instance(IDirectory.class, sc.getContainerUid());
83
+		DirEntry fromDE = fromDirService.findByEntryUid(sc.getSubject());
84
+
85
+		IDirectory memberDirService = context.provider().instance(IDirectory.class, domainUid);
79 86
 
80 87
 		String fromDN = "";
81 88
 		if (fromDE != null) {
... ...
@@ -99,7 +106,7 @@ public abstract class AbstractEmailHook {
99 106
 				continue;
100 107
 			}
101 108
 
102
-			DirEntry de = dirService.findByEntryUid(entry.subject);
109
+			final DirEntry de = memberDirService.findByEntryUid(entry.subject);
103 110
 
104 111
 			if (de == null) {
105 112
 				logger.error("Cannot find dirEntry {}", entry.subject);
... ...
@@ -109,16 +116,16 @@ public abstract class AbstractEmailHook {
109 116
 			if (de.email == null) {
110 117
 				if (de.kind == Kind.GROUP) {
111 118
 					IGroup g = context.provider().instance(IGroup.class, sc.getContainerUid());
112
-					List<Member> members = g
113
-							.getExpandedUserMembers(de.entryUid);
119
+					List<Member> members = g.getExpandedUserMembers(de.entryUid);
114 120
 					members.forEach(m -> {
115
-						DirEntry memberDE = dirService.findByEntryUid(m.uid);
121
+						DirEntry memberDE = memberDirService.findByEntryUid(m.uid);
116 122
 						if (memberDE.email != null) {
117 123
 							Map<String, String> prefs = settingService.get(memberDE.entryUid);
118 124
 							String lang = prefs.get("lang");
119
-							data.put("entity", I18nLabels.getInstance().translate(lang, entityDisplayName));
125
+							data.put("entity", I18nLabels.getInstance().translate(lang, displayName));
120 126
 							Mailbox from = buildFrom(memberDE, sc);
121
-							sendMessage(from, memberDE, templateSubjet, templateBody, data, lang, headers);
127
+							sendMessage(from, memberDE, this.getTemplateSubject(), this.getTemplateBody(), data, lang,
128
+									headers);
122 129
 						}
123 130
 					});
124 131
 				} else {
... ...
@@ -126,15 +133,15 @@ public abstract class AbstractEmailHook {
126 133
 				}
127 134
 				continue;
128 135
 			}
129
-			
136
+
130 137
 			Mailbox from = buildFrom(de, sc);
131 138
 			Map<String, String> prefs = settingService.get(de.entryUid);
132 139
 			String lang = prefs.get("lang");
133
-			data.put("entity", I18nLabels.getInstance().translate(lang, entityDisplayName));
134
-			sendMessage(from, de, templateSubjet, templateBody, data, lang, headers);
140
+			data.put("entity", I18nLabels.getInstance().translate(lang, displayName));
141
+			sendMessage(from, de, this.getTemplateSubject(), this.getTemplateBody(), data, lang, headers);
135 142
 		}
136 143
 	}
137
-	
144
+
138 145
 	private Mailbox buildFrom(DirEntry de, SecurityContext sc) {
139 146
 		String noreply;
140 147
 		if (de != null && de.email.contains("@")) {
... ...
@@ -196,4 +203,9 @@ public abstract class AbstractEmailHook {
196 203
 			logger.error(e.getMessage(), e);
197 204
 		}
198 205
 	}
206
+
207
+	abstract protected String getTemplateSubject();
208
+
209
+	abstract protected String getTemplateBody();
210
+
199 211
 }
... ...
@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
28 28
 import net.bluemind.config.InstallationId;
29 29
 import net.bluemind.core.api.fault.ServerFault;
30 30
 import net.bluemind.core.container.hooks.AbstractEmailHook;
31
-import net.bluemind.core.container.hooks.IAclHook;
32 31
 import net.bluemind.core.container.model.ContainerDescriptor;
33 32
 import net.bluemind.core.container.model.ItemValue;
34 33
 import net.bluemind.core.container.model.acl.AccessControlEntry;
... ...
@@ -39,9 +38,11 @@ import net.bluemind.mailbox.api.IMailboxes;
39 38
 import net.bluemind.mailbox.api.Mailbox;
40 39
 import net.bluemind.mailbox.api.MailboxAclContainerType;
41 40
 
42
-public class EmailHook extends AbstractEmailHook implements IAclHook {
41
+public class EmailHook extends AbstractEmailHook {
43 42
 
44 43
 	private static final Logger logger = LoggerFactory.getLogger(EmailHook.class);
44
+	private String subjectTpl;
45
+	private String bodyTpl;
45 46
 
46 47
 	public EmailHook() {
47 48
 		super();
... ...
@@ -65,23 +66,23 @@ public class EmailHook extends AbstractEmailHook implements IAclHook {
65 66
 				}
66 67
 				if (boxItem != null) {
67 68
 					RawField rf = new RawField("X-BM-MailboxSharing", mboxUid);
68
-					String subjectTpl = null;
69
-					String bodyTpl = null;
69
+					this.subjectTpl = null;
70
+					this.bodyTpl = null;
70 71
 					switch (boxItem.value.type) {
71 72
 					case mailshare:
72 73
 					case user:
73
-						subjectTpl = "MailshareSubject.ftl";
74
-						bodyTpl = "MailshareBody.ftl";
74
+						this.subjectTpl = "MailshareSubject.ftl";
75
+						this.bodyTpl = "MailshareBody.ftl";
75 76
 						break;
76 77
 					default:
77 78
 						break;
78 79
 
79 80
 					}
80 81
 
81
-					if (subjectTpl != null) {
82
+					if (this.subjectTpl != null) {
82 83
 						List<AccessControlEntry> listCopy = new ArrayList<>(current);
83 84
 						listCopy.removeAll(previous);
84
-						notify(context, boxItem.displayName, subjectTpl, bodyTpl, listCopy, rf);
85
+						notify(context, container.domainUid, boxItem.displayName, listCopy, rf);
85 86
 					}
86 87
 				}
87 88
 			} catch (ServerFault e) {
... ...
@@ -89,4 +90,14 @@ public class EmailHook extends AbstractEmailHook implements IAclHook {
89 90
 			}
90 91
 		}
91 92
 	}
93
+
94
+	@Override
95
+	protected String getTemplateSubject() {
96
+		return this.subjectTpl;
97
+	}
98
+
99
+	@Override
100
+	protected String getTemplateBody() {
101
+		return this.bodyTpl;
102
+	}
92 103
 }
... ...
@@ -27,13 +27,12 @@ import org.slf4j.LoggerFactory;
27 27
 
28 28
 import net.bluemind.core.api.fault.ServerFault;
29 29
 import net.bluemind.core.container.hooks.AbstractEmailHook;
30
-import net.bluemind.core.container.hooks.IAclHook;
31 30
 import net.bluemind.core.container.model.ContainerDescriptor;
32 31
 import net.bluemind.core.container.model.acl.AccessControlEntry;
33 32
 import net.bluemind.core.rest.BmContext;
34 33
 import net.bluemind.todolist.api.TodoListContainerType;
35 34
 
36
-public class TodolistEmailHook extends AbstractEmailHook implements IAclHook {
35
+public class TodolistEmailHook extends AbstractEmailHook {
37 36
 
38 37
 	private static final Logger logger = LoggerFactory.getLogger(TodolistEmailHook.class);
39 38
 
... ...
@@ -52,7 +51,7 @@ public class TodolistEmailHook extends AbstractEmailHook implements IAclHook {
52 51
 				List<AccessControlEntry> added = new ArrayList<>(current);
53 52
 				added.removeAll(previous);
54 53
 
55
-				notify(context, container.name, "TodolistSubject.ftl", "TodolistBody.ftl", added, uid, type);
54
+				notify(context, container.domainUid, container.name, added, uid, type);
56 55
 
57 56
 			} catch (ServerFault e) {
58 57
 				logger.error(e.getMessage(), e);
... ...
@@ -61,4 +60,14 @@ public class TodolistEmailHook extends AbstractEmailHook implements IAclHook {
61 60
 
62 61
 	}
63 62
 
63
+	@Override
64
+	protected String getTemplateSubject() {
65
+		return "TodolistSubject.ftl";
66
+	}
67
+
68
+	@Override
69
+	protected String getTemplateBody() {
70
+		return "TodolistBody.ftl";
71
+	}
72
+
64 73
 }