Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2022-02-13 02:31:53 +0300
committerdartcafe <github@dartcafe.de>2022-02-21 17:49:50 +0300
commit9ed90c847b85fda5515006312697716cd32ef4e2 (patch)
tree811f0fab8095fe57802f7947795bfb059f37539c /lib
parenta9380cb640c3a5e3781565cd9bdcf3f3331d413b (diff)
add SettingsSection and legal terms links
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Model/Mail/MailBase.php39
-rw-r--r--lib/Model/Settings/AppSettings.php55
-rw-r--r--lib/Service/SettingsService.php4
3 files changed, 96 insertions, 2 deletions
diff --git a/lib/Model/Mail/MailBase.php b/lib/Model/Mail/MailBase.php
index fe8376d5..0335c7d1 100644
--- a/lib/Model/Mail/MailBase.php
+++ b/lib/Model/Mail/MailBase.php
@@ -26,6 +26,7 @@ namespace OCA\Polls\Model\Mail;
use OCA\Polls\Model\UserGroup\UserBase;
use OCA\Polls\Model\UserGroup\User;
+use OCA\Polls\Model\Settings\AppSettings;
use OCA\Polls\Db\Poll;
use OCA\Polls\Helper\Container;
use OCP\IL10N;
@@ -74,6 +75,9 @@ abstract class MailBase {
/** @var IEmailTemplate */
protected $emailTemplate;
+ /** @var AppSettings */
+ protected $appSettings;
+
/** @var User */
protected $owner;
@@ -86,6 +90,7 @@ abstract class MailBase {
$this->logger = Container::queryClass(LoggerInterface::class);
$this->mailer = Container::queryClass(IMailer::class);
$this->transFactory = Container::queryClass(IFactory::class);
+ $this->appSettings = Container::queryClass(AppSettings::class);
$this->poll = $this->getPoll($pollId);
$this->recipient = $this->getUser($recipientId);
@@ -142,11 +147,21 @@ abstract class MailBase {
$this->buildBody();
// add footer
- $this->emailTemplate->addFooter($this->getFooter());
+ $footerText = $this->getFooter();
+ if ($this->appSettings->getLegalTermsInEmail()) {
+ $footerText = $footerText . '<br>' . $this->getLegalLinks();
+ }
+
+ if ($this->appSettings->getDisclaimer()) {
+ $footerText = $footerText . '<br>' . $this->getParsedMarkDown($this->appSettings->getDisclaimer());
+ }
+ $this->emailTemplate->addFooter($footerText);
return $this->emailTemplate;
}
+
+
protected function getSubject(): string {
return $this->l10n->t('Notification for poll "%s"', $this->poll->getTitle());
}
@@ -167,6 +182,22 @@ abstract class MailBase {
$this->emailTemplate->addBodyText('Sorry. This eMail has no text and this should not happen.');
}
+ protected function getLegalLinks() {
+ $legal = '';
+
+ if ($this->appSettings->getUseImprintUrl()) {
+ $legal = '<a href="' . $this->appSettings->getUseImprintUrl() . '">' . $this->l10n->t('Legal Notice') . '</a>';
+ }
+ if ($this->appSettings->getUsePrivacyUrl()) {
+ if ($this->appSettings->getUseImprintUrl()) {
+ $legal = $legal . ' | ';
+ }
+
+ $legal = $legal . '<a href="' . $this->appSettings->getUsePrivacyUrl() . '">' . $this->l10n->t('Privacy Policy') . '</a>';
+ }
+ return $legal;
+ }
+
protected function getUser(string $userId) : UserBase {
if ($this->userManager->get($userId) instanceof IUser) {
// return User object
@@ -177,6 +208,10 @@ abstract class MailBase {
}
protected function getRichDescription() : string {
+ return $this->getParsedMarkDown($this->poll->getDescription());
+ }
+
+ protected function getParsedMarkDown($source) : string {
$config = [
'html_input' => 'strip',
'allow_unsafe_links' => false,
@@ -186,7 +221,7 @@ abstract class MailBase {
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new TableExtension());
$converter = new MarkdownConverter($environment);
- return $converter->convertToHtml($this->poll->getDescription())->getContent();
+ return $converter->convertToHtml($source)->getContent();
}
private function getShareURL() : string {
diff --git a/lib/Model/Settings/AppSettings.php b/lib/Model/Settings/AppSettings.php
index 0010b672..d6fcf1c9 100644
--- a/lib/Model/Settings/AppSettings.php
+++ b/lib/Model/Settings/AppSettings.php
@@ -151,6 +151,37 @@ class AppSettings implements JsonSerializable {
return false;
}
+ public function getLegalTermsInEmail(): bool {
+ return $this->stringToBool($this->config->getAppValue(self::APP_NAME, 'legalTermsInEmail'), true);
+ }
+
+ public function getPrivacyUrl(): string {
+ return $this->config->getAppValue(self::APP_NAME, 'privacyUrl');
+ }
+
+ public function getUsePrivacyUrl(): string {
+ if ($this->config->getAppValue(self::APP_NAME, 'privacyUrl')) {
+ return $this->config->getAppValue(self::APP_NAME, 'privacyUrl');
+ }
+ return $this->config->getAppValue('theming', 'privacyUrl');
+ }
+
+ public function getImprintUrl(): string {
+ return $this->config->getAppValue(self::APP_NAME, 'imprintUrl');
+ }
+
+
+ public function getUseImprintUrl(): string {
+ if ($this->config->getAppValue(self::APP_NAME, 'imprintUrl')) {
+ return $this->config->getAppValue(self::APP_NAME, 'imprintUrl');
+ }
+ return $this->config->getAppValue('theming', 'imprintUrl');
+ }
+
+ public function getDisclaimer(): string {
+ return $this->config->getAppValue(self::APP_NAME, 'disclaimer');
+ }
+
// Setters
public function setAllowPublicShares(bool $value): void {
$this->config->setAppValue(self::APP_NAME, 'allowPublicShares', $this->boolToString($value));
@@ -212,6 +243,22 @@ class AppSettings implements JsonSerializable {
$this->config->setAppValue(self::APP_NAME, 'useActivity', $this->boolToString($value));
}
+ public function setLegalTermsInEmail(bool $value): void {
+ $this->config->setAppValue(self::APP_NAME, 'legalTermsInEmail', $this->boolToString($value));
+ }
+
+ public function setPrivacyUrl(string $value): void {
+ $this->config->setAppValue(self::APP_NAME, 'privacyUrl', $value);
+ }
+
+ public function setImprintUrl(string $value): void {
+ $this->config->setAppValue(self::APP_NAME, 'imprintUrl', $value);
+ }
+
+ public function setDisclaimer(string $value): void {
+ $this->config->setAppValue(self::APP_NAME, 'disclaimer', $value);
+ }
+
public function jsonSerialize() {
// convert group ids to group objects
$publicSharesGroups = [];
@@ -256,6 +303,14 @@ class AppSettings implements JsonSerializable {
'autoArchiveOffset' => $this->getAutoArchiveOffset(),
'updateType' => $this->getUpdateType(),
'useActivity' => $this->getUseActivity(),
+ 'privacyUrl' => $this->getPrivacyUrl(),
+ 'legalTermsInEmail' => $this->getLegalTermsInEmail(),
+ 'imprintUrl' => $this->getImprintUrl(),
+ 'usePrivacyUrl' => $this->getUsePrivacyUrl(),
+ 'useImprintUrl' => $this->getUseImprintUrl(),
+ 'defaultPrivacyUrl' => $this->config->getAppValue('theming', 'privacyUrl'),
+ 'defaultImprintUrl' => $this->config->getAppValue('theming', 'imprintUrl'),
+ 'disclaimer' => $this->getDisclaimer(),
];
}
diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php
index b5f2cb54..51926b9f 100644
--- a/lib/Service/SettingsService.php
+++ b/lib/Service/SettingsService.php
@@ -73,5 +73,9 @@ class SettingsService {
$this->appSettings->setPollDownloadGroups(array_column($settingsArray['pollDownloadGroups'], 'id'));
$this->appSettings->setUpdateType($settingsArray['updateType']);
$this->appSettings->setUseActivity($settingsArray['useActivity']);
+ $this->appSettings->setPrivacyUrl($settingsArray['privacyUrl']);
+ $this->appSettings->setImprintUrl($settingsArray['imprintUrl']);
+ $this->appSettings->setLegalTermsInEmail($settingsArray['legalTermsInEmail']);
+ $this->appSettings->setDisclaimer($settingsArray['disclaimer']);
}
}