Skip to content

Commit

Permalink
Add MailService integration to notify users of malicious file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartdohmann committed Nov 21, 2024
1 parent f4c300d commit 1930a17
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/EventListener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Server;
use OCA\GDataVaas\Service\MailService;

/** @template-implements IEventListener<BeforeNodeCopiedEvent|BeforeNodeDeletedEvent|BeforeNodeRenamedEvent|BeforeNodeTouchedEvent|BeforeNodeWrittenEvent|NodeCopiedEvent|NodeCreatedEvent|NodeDeletedEvent|NodeRenamedEvent|NodeTouchedEvent|NodeWrittenEvent> */
class FileEventsListener implements IEventListener {
Expand All @@ -38,7 +39,8 @@ public function __construct(
private VerdictService $verdictService,
private FileService $fileService,
private TagService $tagService,
private IAppConfig $appConfig
private IAppConfig $appConfig,
private MailService $mailService
) {
}

Expand All @@ -63,6 +65,9 @@ public function handle(Event $event): void {
if ($verdict->Verdict->value == TagService::MALICIOUS) {
$this->sendErrorResponse(new VirusFoundException($verdict, $node->getName(), $node->getId()));
$this->fileService->deleteFile($node->getId());
if ($this->appConfig->getValueBool(Application::APP_ID, 'sendMailOnVirusUpload')) {
$this->mailService->notifyMaliciousUpload($verdict, $node->getPath(), $this->userSession->getUser()->getUID(), $node->getSize());
}
exit;
}
}
Expand Down

0 comments on commit 1930a17

Please sign in to comment.