Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mail provider settings #48134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

SebastianKrupinski
Copy link
Contributor

@SebastianKrupinski SebastianKrupinski marked this pull request as draft September 17, 2024 11:48
@SebastianKrupinski SebastianKrupinski self-assigned this Sep 17, 2024
@SebastianKrupinski SebastianKrupinski added the 3. to review Waiting for reviews label Sep 17, 2024
@SebastianKrupinski SebastianKrupinski marked this pull request as ready for review September 17, 2024 13:28
@SebastianKrupinski
Copy link
Contributor Author

image

New setting in administration section

@SebastianKrupinski
Copy link
Contributor Author

@marcoambrosini

Copy link
Contributor

@kesselb kesselb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.sample.php needs an update

'section_id' => 'server',
'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL,
'title' => $this->l->t('System Mails'),
'description' => $this->l->t('System e-mails are messages generated automatically by Nextcloud. They are sent for example when a share is created or when inviting attendees to a calendar event..'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are sent for example when a share is created

I find it weird to use "share is created" as an example because we don't use the mail provider there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what design wanted...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm quite sure that design wanted a description of what the feature actually does. I can't imagine that design asked you to mention in the description that this feature toggle affects the behavior of the sharebyemail provider, whereas it doesn't affect it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if we don't use the mail provider there than the example is wrong and we should change it to something that is actually affected by the setting


switch ($event->getFieldId()) {
case 'mail_providers_disabled':
$this->config->setSystemValue('mail_providers_disabled', $event->getValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how you planned the feature with @ChristophWurst, but changing values in config.php via web admin is tricky.

Examples:

  1. config_is_read_only = true
  2. multiple config files (the additional configuration files overwrite the values in config.php, setSystemValue modifies only config.php not the additional configuration files)
  3. The unfinished and undocumented "overwrite configuration variables via env" feature may overload the variable as well.

That's all unrelated to this pull request, but the incomplete handling in our configuration classes is the reason that we usually don't change config.php via web admin.

I recommend against adding a ui with system config as backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature functions identical to the new Windows support feature that was put in last month

if ($user !== null) {
// retrieve appropriate service with the same address as sender
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {

Must be documented in https://github.com/nextcloud/server/blob/master/config/config.sample.php.

https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html is also generated from the config.sample.php.

if ($user !== null) {
// retrieve appropriate service with the same address as sender
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {
if ($this->config->getSystemValueBool('mail_providers_disabled', false)) {

if ($user !== null) {
// retrieve appropriate service with the same address as sender
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
if ($this->config->getSystemValueInt('mail_providers_disabled', 0) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to use/read: mail_providers_enabled with default true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what design wanted...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return;
}

if ($event instanceof DeclarativeSettingsSetValueEvent) {

Check notice

Code scanning / Psalm

RedundantConditionGivenDocblockType Note

Docblock-defined type OCP\Settings\Events\DeclarativeSettingsSetValueEvent for $event is always OCP\Settings\Events\DeclarativeSettingsSetValueEvent
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
@SebastianKrupinski
Copy link
Contributor Author

image

Latest version

Copy link
Member

@marcoambrosini marcoambrosini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ from design

if ($user !== null) {
// retrieve appropriate service with the same address as sender
$mailService = $this->mailManager->findServiceByAddress($user->getUID(), $sender);
if ($this->config->getValueInt('core', 'mail_providers_disabled', 0) === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a boolean?

I would also recommend using mail_providers_enabled true/false rather than mail_providers_disabled true/false because it's easier to read.

Example:

if (!$this->config->getValueBool('core', 'mail_providers_disabled', false))

vs.

if ($this->config->getValueBool('core', 'mail_providers_enabled', true))

'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN,
'section_id' => 'server',
'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL,
'title' => $this->l->t('System Mails'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to use Mail Providers instead of System Mails. System Mails can mean anything.

'section_id' => 'server',
'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_EXTERNAL,
'title' => $this->l->t('System Mails'),
'description' => $this->l->t('System emails are automatically generated by Nextcloud when people perform actions like inviting others to calendar events.'),
Copy link
Contributor

@kesselb kesselb Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about:

Nextcloud 30 introduced a feature called mail provider to send emails through the user's personal email account when possible. Currently, it only works with calendar invitations. You need Nextcloud 30, Nextcloud Mail 4.1 and there must be an email account in Nextcloud Mail matching the email address of the user in Nextcloud.

I think we should try to explain what's necessary to make the feature work. The requirements Mail 4.0 + a matching email account should be explained somewhere, how should a user otherwise know how it works?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors


declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors


private function handleGetValue(DeclarativeSettingsGetValueEvent $event): void {

$event->setValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated? ;)

We only have one field right now.

		if ($event->getFieldId() === 'mail_providers_disabled') {
			$event->setValue($this->config->getValueInt('core', 'mail_providers_disabled', 0));
			return;
		}


private function handleSetValue(DeclarativeSettingsSetValueEvent $event): void {

switch ($event->getFieldId()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here ;)

		if ($event->getFieldId() === 'mail_providers_disabled') {
			$this->config->setValueInt('core', 'mail_providers_disabled', (int)$event->getValue());
			$event->stopPropagation();
			return;
		}

@kesselb
Copy link
Contributor

kesselb commented Sep 24, 2024

The Linter is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
Status: 🏗️ In progress
Development

Successfully merging this pull request may close these issues.

5 participants