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

Enhance calendar invitation emails #6402

Merged
merged 6 commits into from
Nov 6, 2017
Merged

Conversation

leonklingele-work
Copy link

This PR adds support to customize DAV-related emails on a per-attendee basis.

@codecov
Copy link

codecov bot commented Sep 8, 2017

Codecov Report

Merging #6402 into master will increase coverage by 0.02%.
The diff coverage is 72.41%.

@@             Coverage Diff              @@
##             master    #6402      +/-   ##
============================================
+ Coverage     50.61%   50.64%   +0.02%     
- Complexity    24297    24329      +32     
============================================
  Files          1577     1577              
  Lines         92922    93047     +125     
  Branches       1359     1359              
============================================
+ Hits          47036    47121      +85     
- Misses        45886    45926      +40
Impacted Files Coverage Δ Complexity Δ
apps/dav/appinfo/v1/caldav.php 0% <0%> (ø) 0 <0> (ø) ⬇️
lib/private/L10N/L10N.php 87.93% <100%> (+0.43%) 5 <0> (ø) ⬇️
apps/dav/lib/Server.php 46.62% <100%> (+0.36%) 17 <0> (ø) ⬇️
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 71.72% <72.14%> (-3.64%) 54 <46> (+32)
lib/private/Mail/Message.php 77.55% <0%> (-6.13%) 20% <0%> (ø)
lib/private/Security/CertificateManager.php 91.08% <0%> (-1%) 39% <0%> (ø)
lib/private/Server.php 83.41% <0%> (+0.12%) 125% <0%> (ø) ⬇️

@@ -84,7 +84,15 @@
$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger(), new \OC\AppFramework\Utility\TimeFactory()));
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin(
'dav', // TODO(leon): Retrieve dynamically, but where to find it? :(
Copy link
Author

Choose a reason for hiding this comment

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

@nickvergessen any idea on how to retrieve the current app's name from here?

Copy link
Member

Choose a reason for hiding this comment

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

"current" app name is dav, because this code is part of the dav app and the dav api is used by the calendar app

Copy link
Author

Choose a reason for hiding this comment

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

I know, I'm the one who added 'dav'.. But how to retrieve this value dynamically? I don't want to hardcode it.

Copy link
Member

Choose a reason for hiding this comment

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

In this scope here you cannot retrieve this dynamically with public API and need to hard-code it. In a controller it will get injected…


private function renderMailTemplates($name, $params) {
$tmplBase = 'mail/' . $name;
$plainTemplate = new TemplateResponse($this->appName, $tmplBase . '-plain', $params, 'blank');
Copy link
Member

Choose a reason for hiding this comment

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

Please use the new $mailer->createMail()->createEMailTemplate() for this...

Copy link
Author

Choose a reason for hiding this comment

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

Yay, new stuff is cool.

Copy link
Author

Choose a reason for hiding this comment

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

Hmpf, do you really prefer the new style? I don't.

Copy link
Author

Choose a reason for hiding this comment

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

Proper link: a4deea5

return null;
}

private function stringOrDefault($str, $def) {
Copy link
Member

@nickvergessen nickvergessen Sep 8, 2017

Choose a reason for hiding this comment

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

use $str ?: $def instead

Copy link
Author

@leonklingele-work leonklingele-work Sep 8, 2017

Choose a reason for hiding this comment

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

Is this already in all PHP versions currently supported by NC?

EDIT:
Fix typo, sorry ;)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah its available since 5.3, we require 5.6

Copy link
Member

Choose a reason for hiding this comment

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

you misunderstood. Drop this complete method and use ?: directly.
No need to have a custom method which just wraps an operator?!

Copy link
Author

Choose a reason for hiding this comment

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

Makes sense, updated.

@MorrisJobke MorrisJobke changed the title WIP:DAV: Initial email customization support DAV: Initial email customization support Sep 8, 2017
@MorrisJobke MorrisJobke added the 2. developing Work in progress label Sep 8, 2017
$this->server->addPlugin(new IMipPlugin($mailer, $logger, $timezone));
$this->server->addPlugin(new IMipPlugin(
'dav', // TODO(leon): Retrieve dynamically, but where to find it? :(
\OC::$server->getUserSession()->getUser()->getUID(),
Copy link
Author

Choose a reason for hiding this comment

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

This fails on anonymous users. How to properly retrieve the user id?

Copy link
Member

Choose a reason for hiding this comment

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

You want the owner of the event? Or which user should be returned?

Otherwise try:

$user = \OC::$server->getUserSession()->getUser();
$userId = $user instanceof IUser ? $user->getUID() : '';

$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger(), new \OC\AppFramework\Utility\TimeFactory()));
$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin(
'dav', // TODO(leon): Retrieve dynamically, but where to find it? :(
\OC::$server->getUserSession()->getUser()->getUID(),
Copy link
Author

Choose a reason for hiding this comment

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

@fancycode
Copy link
Member

It would probably be a lot less intrusive to just dispatch an event before sending the mail in

$failed = $this->mailer->send($message);
and pass the $iTipMessage and $message as parameters. That way any app could listen for the event and update the mail contents as needed (for the changes here, that would be the calendar app with the Spreed integration).

@georgehrke
Copy link
Member

Any reason why u use Swift directly? I would really like to see this use the Nextcloud 12 Email Template class.

@leonklingele-work
Copy link
Author

@fancycode

It would probably be a lot less intrusive to just dispatch an event

How would this be less intrusive? This PR is not spreed-specific, though I agree I should probably use a different wording here, event instead of meeting.

@georgehrke

Nextcloud 12 Email Template class

i.e.? Isn't this what Joas suggested here: #6402 (comment)
How to not use swiftmail for attachments?

@leonklingele-work
Copy link
Author

@fancycode wouldn't this require some kind of way to load the Calendar app on requests to remote.php?
I'd prefer to trigger an event to allow other apps to extend the mail template from this PR with their own section.

@georgehrke
Copy link
Member

How to not use swiftmail for attachments?

I think we should extend EMailTemplate to be able to add extensions in that case.

@fancycode
Copy link
Member

@fancycode wouldn't this require some kind of way to load the Calendar app on requests to remote.php?

Sure, but wouldn't that also be the case for apps that listen for events to extend the mail template?

I'd prefer to trigger an event to allow other apps to extend the mail template from this PR with their own section.

@nickvergessen nickvergessen force-pushed the dav-email-customization branch from 49614be to 71bd8bf Compare October 31, 2017 15:24
@nickvergessen nickvergessen changed the title DAV: Initial email customization support Enhance calendar invitation emails Oct 31, 2017
@georgehrke
Copy link
Member

georgehrke commented Oct 31, 2017

  • please revert 3rdparty changes

@nickvergessen nickvergessen force-pushed the dav-email-customization branch from 71bd8bf to e16f670 Compare October 31, 2017 19:59
@nickvergessen nickvergessen added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 1, 2017
@georgehrke georgehrke force-pushed the dav-email-customization branch from 0c62d18 to e16f670 Compare November 1, 2017 22:05
@georgehrke georgehrke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Nov 2, 2017
@georgehrke georgehrke self-assigned this Nov 2, 2017
@georgehrke
Copy link
Member

hijacking this PR to fix various issues in the email

Leon Klingele and others added 2 commits November 3, 2017 11:19
Signed-Off-By: Leon Klingele <[email protected]>
Signed-off-by: Georg Ehrke <[email protected]>
Signed-off-by: Joas Schilling <[email protected]>
nickvergessen and others added 4 commits November 3, 2017 11:20
@georgehrke georgehrke force-pushed the dav-email-customization branch from 4214fbc to e111da7 Compare November 3, 2017 10:20
@georgehrke georgehrke added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 3, 2017
@georgehrke
Copy link
Member

please review @LukasReschke @MorrisJobke

@georgehrke
Copy link
Member

Let's get this in and do further tiny enhancements after feature freeze.

@MorrisJobke MorrisJobke merged commit 6c29ce4 into master Nov 6, 2017
@MorrisJobke MorrisJobke deleted the dav-email-customization branch November 6, 2017 14:14
@MorrisJobke MorrisJobke added this to the Nextcloud 13 milestone Nov 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants