-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #288 [FEATURE] Send mails to moderators when a new report is s…
…ubmitted via the report form
- Loading branch information
1 parent
0752e01
commit 9efafd8
Showing
12 changed files
with
165 additions
and
15 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
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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/faforever/api/data/listeners/ModerationReportListener.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,53 @@ | ||
package com.faforever.api.data.listeners; | ||
|
||
import com.faforever.api.config.FafApiProperties; | ||
import com.faforever.api.data.domain.LegacyAccessLevel; | ||
import com.faforever.api.data.domain.LobbyGroup; | ||
import com.faforever.api.data.domain.Login; | ||
import com.faforever.api.data.domain.ModerationReport; | ||
import com.faforever.api.email.EmailService; | ||
import com.faforever.api.user.LobbyGroupRepository; | ||
import com.google.common.collect.Sets; | ||
import com.yahoo.elide.functions.LifeCycleHook; | ||
import com.yahoo.elide.security.RequestScope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.inject.Inject; | ||
import java.text.MessageFormat; | ||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Component | ||
public class ModerationReportListener implements LifeCycleHook<ModerationReport> { | ||
private FafApiProperties properties; | ||
private EmailService emailService; | ||
private LobbyGroupRepository lobbyGroupRepository; | ||
|
||
@Inject | ||
public ModerationReportListener(FafApiProperties properties, EmailService emailService, LobbyGroupRepository lobbyGroupRepository) { | ||
this.properties = properties; | ||
this.emailService = emailService; | ||
this.lobbyGroupRepository = lobbyGroupRepository; | ||
} | ||
|
||
@Override | ||
public void execute(ModerationReport moderationReport, RequestScope requestScope, Optional changes) { | ||
final HashSet<LegacyAccessLevel> moderatorLevels = Sets.newHashSet(LegacyAccessLevel.ROLE_MODERATOR, LegacyAccessLevel.ROLE_ADMINISTRATOR); | ||
final Set<String> moderatorEmailAddresses = lobbyGroupRepository.findAllByAccessLevelIn(moderatorLevels).stream() | ||
.map(LobbyGroup::getUser) | ||
.map(Login::getEmail) | ||
.collect(Collectors.toSet()); | ||
emailService.sendMail( | ||
moderatorEmailAddresses, | ||
properties.getModerationReport().getNotificationEmailSubject(), | ||
MessageFormat.format(properties.getModerationReport().getNotificationEmailBodyTemplate(), | ||
moderationReport.getReporter().getLogin(), | ||
moderationReport.getReportDescription(), | ||
moderationReport.getGameIncidentTimecode(), | ||
moderationReport.getReportedUsers().stream().map(Login::getLogin).collect(Collectors.toSet()) | ||
) | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
package com.faforever.api.email; | ||
|
||
import com.google.common.collect.Sets; | ||
|
||
import java.util.Set; | ||
|
||
public interface EmailSender { | ||
void sendMail(String fromEmail, String fromName, String toEmail, String subject, String content); | ||
default void sendMail(String fromEmail, String fromName, String toEmail, String subject, String content) { | ||
sendMail(fromEmail, fromName, Sets.newHashSet(toEmail), subject, content); | ||
} | ||
|
||
void sendMail(String fromEmail, String fromName, Set<String> toEmails, String subject, String content); | ||
} |
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
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/faforever/api/user/LobbyGroupRepository.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,14 @@ | ||
package com.faforever.api.user; | ||
|
||
import com.faforever.api.data.domain.LegacyAccessLevel; | ||
import com.faforever.api.data.domain.LobbyGroup; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
|
||
@Repository | ||
public interface LobbyGroupRepository extends JpaRepository<LobbyGroup, Integer> { | ||
Set<LobbyGroup> findAllByAccessLevelIn(Collection<LegacyAccessLevel> accessLevels); | ||
} |
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