This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(language team): allow coordinator to contact members
- Loading branch information
Alex Eng
committed
Apr 29, 2016
1 parent
5bf24ba
commit f89b139
Showing
14 changed files
with
464 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
zanata-war/src/main/java/org/zanata/action/ContactLanguageTeamMembersAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.zanata.action; | ||
|
||
import com.google.common.collect.Lists; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.zanata.ApplicationConfiguration; | ||
import org.zanata.common.LocaleId; | ||
import org.zanata.dao.LocaleMemberDAO; | ||
import org.zanata.email.ContactLanguageTeamMembersEmailStrategy; | ||
import org.zanata.email.EmailStrategy; | ||
import org.zanata.i18n.Messages; | ||
import org.zanata.model.HAccount; | ||
import org.zanata.model.HLocale; | ||
import org.zanata.model.HLocaleMember; | ||
import org.zanata.security.annotations.Authenticated; | ||
import org.zanata.security.annotations.CheckLoggedIn; | ||
import org.zanata.service.EmailService; | ||
import org.zanata.service.LocaleService; | ||
import org.zanata.ui.faces.FacesMessages; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
|
||
@Named("contactLanguageTeamMembersAction") | ||
@javax.faces.bean.ViewScoped | ||
|
||
@Slf4j | ||
public class ContactLanguageTeamMembersAction implements Serializable { | ||
|
||
@Inject | ||
@Authenticated | ||
private HAccount authenticatedAccount; | ||
|
||
@Inject | ||
private FacesMessages facesMessages; | ||
|
||
@Inject | ||
private EmailService emailServiceImpl; | ||
|
||
@Inject | ||
private LocaleService localeServiceImpl; | ||
|
||
@Inject | ||
private Messages msgs; | ||
|
||
@Inject | ||
private ApplicationConfiguration applicationConfiguration; | ||
|
||
@Inject | ||
private LocaleMemberDAO localeMemberDAO; | ||
|
||
@Getter | ||
@Setter | ||
private String message; | ||
|
||
@Getter | ||
@Setter | ||
private String subject; | ||
|
||
@Getter | ||
@Setter | ||
private String localeId; | ||
|
||
private HLocale locale; | ||
|
||
private List<HLocaleMember> getMembers() { | ||
return localeMemberDAO.findActiveMembers(new LocaleId(localeId)); | ||
} | ||
|
||
|
||
@CheckLoggedIn | ||
public void send() { | ||
List<HLocaleMember> members = getMembers(); | ||
if(!members.isEmpty()) { | ||
String fromName = authenticatedAccount.getPerson().getName(); | ||
String fromLoginName = authenticatedAccount.getUsername(); | ||
String replyEmail = authenticatedAccount.getPerson().getEmail(); | ||
String contactCoordinatorLink = | ||
applicationConfiguration.getServerPath() + | ||
"/language/view/" + localeId; | ||
|
||
String localeNativeName = getLocale().retrieveNativeName(); | ||
|
||
EmailStrategy strategy = | ||
new ContactLanguageTeamMembersEmailStrategy( | ||
fromLoginName, fromName, replyEmail, | ||
getSubject(), | ||
getLocale().getLocaleId().getId(), | ||
localeNativeName, message, contactCoordinatorLink); | ||
try { | ||
String msg = emailServiceImpl.sendToLanguageTeamMembers( | ||
getLocale().getLocaleId(), strategy, members); | ||
facesMessages.addGlobal(msg); | ||
} catch (Exception e) { | ||
String subject = strategy.getSubject(msgs); | ||
|
||
StringBuilder sb = | ||
new StringBuilder() | ||
.append("Failed to send email with subject '") | ||
.append(strategy.getSubject(msgs)) | ||
.append("' , message '").append(message) | ||
.append("'"); | ||
log.error( | ||
"Failed to send email: fromName '{}', fromLoginName '{}', replyEmail '{}', subject '{}', message '{}'. {}", | ||
fromName, fromLoginName, replyEmail, subject, message, e); | ||
facesMessages.addGlobal(sb.toString()); | ||
} | ||
} | ||
} | ||
|
||
public HLocale getLocale() { | ||
if (locale == null) { | ||
locale = localeServiceImpl.getByLocaleId(new LocaleId(localeId)); | ||
} | ||
return locale; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
zanata-war/src/main/java/org/zanata/email/ContactLanguageTeamMembersEmailStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.email; | ||
|
||
import com.google.common.base.Optional; | ||
import com.googlecode.totallylazy.collections.PersistentMap; | ||
import lombok.RequiredArgsConstructor; | ||
import org.zanata.i18n.Messages; | ||
import org.zanata.util.HtmlUtil; | ||
|
||
import javax.mail.internet.InternetAddress; | ||
|
||
import static org.zanata.email.Addresses.getReplyTo; | ||
|
||
/** | ||
* @author Alex Eng <a href="aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
@RequiredArgsConstructor | ||
public class ContactLanguageTeamMembersEmailStrategy | ||
extends EmailStrategy { | ||
private final String fromLoginName; | ||
private final String fromName; | ||
private final String replyEmail; | ||
private final String userSubject; | ||
private final String localeId; | ||
private final String localeNativeName; | ||
private final String htmlMessage; | ||
private final String contactCoordinatorLink; | ||
|
||
@Override | ||
public String getBodyResourceName() { | ||
return "org/zanata/email/templates/email_language_team_members.vm"; | ||
} | ||
|
||
@Override | ||
public Optional<InternetAddress[]> getReplyToAddress() { | ||
return Optional.of(getReplyTo(replyEmail, fromName)); | ||
} | ||
|
||
@Override | ||
public String getSubject(Messages msgs) { | ||
return msgs.format("jsf.email.language.members.SubjectPrefix", | ||
localeId, fromLoginName) + " " + userSubject; | ||
} | ||
|
||
@Override | ||
public PersistentMap<String, Object> makeContext( | ||
PersistentMap<String, Object> genericContext, | ||
InternetAddress[] toAddresses) { | ||
PersistentMap<String, Object> context = super.makeContext(genericContext, | ||
toAddresses); | ||
String safeHTML = HtmlUtil.SANITIZER.sanitize(htmlMessage); | ||
return context | ||
.insert("fromLoginName", fromLoginName) | ||
.insert("fromName", fromName) | ||
.insert("replyEmail", replyEmail) | ||
.insert("localeId", localeId) | ||
.insert("contactCoordinatorLink", contactCoordinatorLink) | ||
.insert("localeNativeName", localeNativeName) | ||
.insert("htmlMessage", safeHTML); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
zanata-war/src/main/resources/org/zanata/email/templates/email_language_team_members.vm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p>$msgs.get("jsf.email.language.members.DearMember")</p> | ||
$htmlMessage | ||
<hr/> | ||
<p>$msgs.format("jsf.email.languageteam.permission.howToReply", $contactCoordinatorLink)</p> |
Oops, something went wrong.