Skip to content

Commit

Permalink
Merge pull request 'Notify email' from feature/mentions-notify-email …
Browse files Browse the repository at this point in the history
  • Loading branch information
LinneyS committed Jan 13, 2025
2 parents c1210a6 + 9af8d09 commit 1f7fcb0
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Added
- setting for setup unknown author display name
- setting for sending notifications by email

## Changed
- fix address when opening editor
Expand Down
10 changes: 9 additions & 1 deletion l10n/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ OC.L10N.register(
"The data source must not be the current document": "Источником данных не должен быть текущий документ",
"Enable background connection check to the editors": "Включить фоновую проверку подключения к редакторам",
"The domain in the file url does not match the domain of the Document server": "Домен в адресе файла не соответствует домену сервера документов",
"Unknown author display name" : "Отображаемое имя неизвестного автора"
"Unknown author display name" : "Отображаемое имя неизвестного автора",
"Enable e-mail notifications" : "Включить уведомления по электронной почте",
"You were mentioned in the document" : "Вы были упомянуты в документе",
"%1\$s mentioned you in the document comment" : "%1\$s упомянул вас в комментарии к документу",
"This is a mail message to notify that you have been mentioned by <a href=\"%1\$s\">%2\$s</a> in the comment to the <a href=\"%3\$s\">%4\$s</a>:<br>\"%5\$s\"" : "Это почтовое сообщение, уведомляющее о том, что вас упомянул <a href=\"%1\$s\">%2\$s</a> в комментарии к <a href=\"%3\$s\">%4\$s</a>:<br>\"%5\$s\"",
"Open file" : "Открыть документ",
"ONLYOFFICE Document Server is unavailable" : "Сервер документов ONLYOFFICE недоступен",
"This is a mail message to notify that the connection with the ONLYOFFICE Document Server has been lost. Please check the connection settings:" : "Это почтовое сообщение, уведомляющее о том, что соединение с сервером документов ONLYOFFICE потеряно. Пожалуйста, проверьте настройки подключения:",
"Go to Settings" : "Перейти в настройки"
},
"nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);");
10 changes: 9 additions & 1 deletion l10n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@
"The data source must not be the current document": "Источником данных не должен быть текущий документ",
"Enable background connection check to the editors": "Включить фоновую проверку подключения к редакторам",
"The domain in the file url does not match the domain of the Document server": "Домен в адресе файла не соответствует домену сервера документов",
"Unknown author display name" : "Отображаемое имя неизвестного автора"
"Unknown author display name" : "Отображаемое имя неизвестного автора",
"Enable e-mail notifications" : "Включить уведомления по электронной почте",
"You were mentioned in the document" : "Вы были упомянуты в документе",
"%1$s mentioned you in the document comment" : "%1$s упомянул вас в комментарии к документу",
"This is a mail message to notify that you have been mentioned by <a href=\"%1$s\">%2$s</a> in the comment to the <a href=\"%3$s\">%4$s</a>:<br>\"%5$s\"" : "Это почтовое сообщение, уведомляющее о том, что вас упомянул <a href=\"%1$s\">%2$s</a> в комментарии к <a href=\"%3$s\">%4$s</a>:<br>\"%5$s\"",
"Open file" : "Открыть документ",
"ONLYOFFICE Document Server is unavailable" : "Сервер документов ONLYOFFICE недоступен",
"This is a mail message to notify that the connection with the ONLYOFFICE Document Server has been lost. Please check the connection settings:" : "Это почтовое сообщение, уведомляющее о том, что соединение с сервером документов ONLYOFFICE потеряно. Пожалуйста, проверьте настройки подключения:",
"Go to Settings" : "Перейти в настройки"
},"pluralForm" :"nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);"
}
27 changes: 27 additions & 0 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class AppConfig {
*/
private $_cronChecker = "cronChecker";

/**
* The config key for the e-mail notifications
*
* @var string
*/
private $_emailNotifications = "emailNotifications";

/**
* The config key for the keep versions history
*
Expand Down Expand Up @@ -767,6 +774,26 @@ public function setCronChecker($value) {
$this->config->setAppValue($this->appName, $this->_cronChecker, json_encode($value));
}

/**
* Get e-mail notifications setting
*
* @return bool
*/
public function getEmailNotifications() {
return $this->config->getAppValue($this->appName, $this->_emailNotifications, "true") !== "false";
}

/**
* Save e-mail notifications setting
*
* @param bool $value - emailNotifications
*/
public function setEmailNotifications($value) {
$this->logger->info("Set e-mail notifications: " . json_encode($value), ["app" => $this->appName]);

$this->config->setAppValue($this->appName, $this->_emailNotifications, json_encode($value));
}

/**
* Get generate preview setting
*
Expand Down
4 changes: 3 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCP\IPreview;
use OCP\ITagManager;
use OCP\Preview\IMimeIconProvider;
use OCP\Mail\IMailer;
use OCP\Notification\IManager;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Viewer\Event\LoadViewer;
Expand Down Expand Up @@ -188,7 +189,8 @@ public function register(IRegistrationContext $context): void {
$this->crypt,
$c->get("IManager"),
$c->get("Session"),
$c->get("GroupManager")
$c->get("GroupManager"),
$c->get(IMailer::class)
);
});

Expand Down
24 changes: 23 additions & 1 deletion lib/Controller/EditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\DocumentService;
use OCA\Onlyoffice\EmailManager;
use OCA\Onlyoffice\FileUtility;
use OCA\Onlyoffice\FileVersions;
use OCA\Onlyoffice\KeyManager;
Expand All @@ -52,6 +53,7 @@
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\Mail\IMailer;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -159,6 +161,20 @@ class EditorController extends Controller {
* @var IAvatarManager
*/
private $avatarManager;

/**
* Mailer
*
* @var IMailer
*/
private $mailer;

/**
* Email manager
*
* @var EmailManager
*/
private $emailManager;

/**
* @param string $AppName - application name
Expand All @@ -174,6 +190,7 @@ class EditorController extends Controller {
* @param IManager $shareManager - Share manager
* @param ISession $session - Session
* @param IGroupManager $groupManager - group Manager
* @param IMailer $mailer - mailer
*/
public function __construct(
$AppName,
Expand All @@ -188,7 +205,8 @@ public function __construct(
Crypt $crypt,
IManager $shareManager,
ISession $session,
IGroupManager $groupManager
IGroupManager $groupManager,
IMailer $mailer
) {
parent::__construct($AppName, $request);

Expand All @@ -213,6 +231,7 @@ public function __construct(

$this->fileUtility = new FileUtility($AppName, $trans, $logger, $config, $shareManager, $session);
$this->avatarManager = \OC::$server->getAvatarManager();
$this->emailManager = new EmailManager($AppName, $trans, $logger, $mailer, $userManager, $urlGenerator);
}

/**
Expand Down Expand Up @@ -609,6 +628,9 @@ public function mention($fileId, $anchor, $comment, $emails) {
$notification->setUser($recipientId);

$notificationManager->notify($notification);
if ($this->config->getEmailNotifications()) {
$this->emailManager->notifyMentionEmail($userId, $recipientId, $file->getId(), $file->getName(), $anchor, $notification->getObjectId());
}
}

return ["message" => $this->trans->t("Notification sent successfully")];
Expand Down
4 changes: 4 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function index() {
"preview" => $this->config->getPreview(),
"advanced" => $this->config->getAdvanced(),
"cronChecker" => $this->config->getCronChecker(),
"emailNotifications" => $this->config->getEmailNotifications(),
"versionHistory" => $this->config->getVersionHistory(),
"protection" => $this->config->getProtection(),
"limitGroups" => $this->config->getLimitGroups(),
Expand Down Expand Up @@ -227,6 +228,7 @@ public function saveAddress(
* @param bool $preview - generate preview files
* @param bool $advanced - use advanced tab
* @param bool $cronChecker - disable cron checker
* @param bool $emailNotifications - notifications via e-mail
* @param bool $versionHistory - keep version history
* @param array $limitGroups - list of groups
* @param bool $chat - display chat
Expand All @@ -247,6 +249,7 @@ public function saveCommon(
$preview,
$advanced,
$cronChecker,
$emailNotifications,
$versionHistory,
$limitGroups,
$chat,
Expand All @@ -266,6 +269,7 @@ public function saveCommon(
$this->config->setPreview($preview);
$this->config->setAdvanced($advanced);
$this->config->setCronChecker($cronChecker);
$this->config->setEmailNotifications($emailNotifications);
$this->config->setVersionHistory($versionHistory);
$this->config->setLimitGroups($limitGroups);
$this->config->setCustomizationChat($chat);
Expand Down
16 changes: 16 additions & 0 deletions lib/Cron/EditorsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
use OCA\Onlyoffice\AppConfig;
use OCA\Onlyoffice\Crypt;
use OCA\Onlyoffice\DocumentService;
use OCA\Onlyoffice\EmailManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\TimedJob;
use OCP\Mail\IMailer;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -96,6 +99,13 @@ class EditorsCheck extends TimedJob {
*/
private $groupManager;

/**
* Email manager
*
* @var EmailManager
*/
private $emailManager;

/**
* @param string $AppName - application name
* @param IURLGenerator $urlGenerator - url generator service
Expand Down Expand Up @@ -124,6 +134,9 @@ public function __construct(
$this->groupManager = $groupManager;
$this->setInterval($this->config->getEditorsCheckInterval());
$this->setTimeSensitivity(IJob::TIME_SENSITIVE);
$mailer = \OC::$server->get(IMailer::class);
$userManager = \OC::$server->get(IUserManager::class);
$this->emailManager = new EmailManager($AppName, $trans, $logger, $mailer, $userManager, $urlGenerator);
}

/**
Expand Down Expand Up @@ -200,6 +213,9 @@ private function notifyAdmins() {
foreach ($this->getUsersToNotify() as $uid) {
$notification->setUser($uid);
$notificationManager->notify($notification);
if ($this->config->getEmailNotifications()) {
$this->emailManager->notifyEditorsCheckEmail($uid);
}
}
}
}
Loading

0 comments on commit 1f7fcb0

Please sign in to comment.