Skip to content

Commit

Permalink
Move dav.invitation_link_recipients from getSystemValue to getAppValue
Browse files Browse the repository at this point in the history
Per @georgehrke change request for PR #12392, instead of setting
dav.invitation_link_recipients in the system config.php file, we
set it in the database table oc_appconfig.

Furthermore, the value of the config variable is always a string:
'yes' to include links in imip mail, 'no' to exclude them, or a
comma-separated list of email addresses and/or domains for which
they should be included.  If not specified in oc_appconfig, the
default is 'yes'.

Signed-off-by: brad2014 <brad2014@users.noreply.github.com>
  • Loading branch information
brad2014 committed Jul 31, 2019
1 parent 1a29239 commit 8d8bcea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 55 deletions.
24 changes: 11 additions & 13 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,28 +249,26 @@ public function schedule(Message $iTipMessage) {
** nextcloud server, to recipients who can access the nextcloud server via
** their internet/intranet. Issue #12156
**
** The app setting is stored in the appconfig database table.
**
** For nextcloud servers accessible to the public internet, the default
** "dav.invitation_link_recipients" value "true" (all recipients) is appropriate.
** "invitation_link_recipients" value "yes" (all recipients) is appropriate.
**
** When the nextcloud server is restricted behind a firewall, accessible
** only via an internal network or via vpn, you can set "dav.invitation_link_recipients"
** to the email address or email domain, or array of addresses or domains,
** to the email address or email domain, or comma separated list of addresses or domains,
** of recipients who can access the server.
**
** To deliver URL's always, set invitation_link_recipients to boolean "true".
** To suppress URL's entirely, set invitation_link_recipients to boolean "false".
** To always deliver URLs, set invitation_link_recipients to "yes".
** To suppress URLs entirely, set invitation_link_recipients to boolean "no".
*/

$recipientDomain = substr(strrchr($recipient, "@"), 1);
$invitationLinkRecipients = $this->config->getSystemValue('dav.invitation_link_recipients', true);
if (is_array($invitationLinkRecipients)) {
$invitationLinkRecipients = array_map('strtolower', $invitationLinkRecipients); // for case insensitive in_array
}
if ($invitationLinkRecipients === true
|| (is_string($invitationLinkRecipients) && strcasecmp($recipient, $invitationLinkRecipients) === 0)
|| (is_string($invitationLinkRecipients) && strcasecmp($recipientDomain, $invitationLinkRecipients) === 0)
|| (is_array($invitationLinkRecipients) && in_array(strtolower($recipient), $invitationLinkRecipients))
|| (is_array($invitationLinkRecipients) && in_array(strtolower($recipientDomain), $invitationLinkRecipients))) {
$invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->config->getAppValue('dav', 'invitation_link_recipients', 'yes'))));

if (strcmp('yes', $invitationLinkRecipients[0]) === 0
|| in_array(strtolower($recipient), $invitationLinkRecipients)
|| in_array(strtolower($recipientDomain), $invitationLinkRecipients)) {
$this->addResponseButtons($template, $l10n, $iTipMessage, $lastOccurrence);
}
}
Expand Down
30 changes: 15 additions & 15 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public function setUp() {

public function testDelivery() {
$this->config
->method('getSystemValue')
->with('dav.invitation_link_recipients', true)
->willReturn(true);
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');

$message = $this->_testMessage();
$this->_expectSend();
Expand All @@ -108,9 +108,9 @@ public function testDelivery() {

public function testFailedDelivery() {
$this->config
->method('getSystemValue')
->with('dav.invitation_link_recipients', true)
->willReturn(true);
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');

$message = $this->_testMessage();
$this->mailer
Expand All @@ -127,9 +127,9 @@ public function testFailedDelivery() {
public function testNoMessageSendForPastEvents($veventParams, $expectsMail) {

$this->config
->method('getSystemValue')
->with('dav.invitation_link_recipients', true)
->willReturn(true);
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn('yes');

$message = $this->_testMessage( $veventParams );

Expand Down Expand Up @@ -167,8 +167,8 @@ public function testIncludeResponseButtons( $config_setting, $recipient, $has_bu

$this->_expectSend($recipient, true, $has_buttons);
$this->config
->method('getSystemValue')
->with('dav.invitation_link_recipients', true)
->method('getAppValue')
->with('dav', 'invitation_link_recipients', 'yes')
->willReturn($config_setting);

$this->plugin->schedule($message);
Expand All @@ -178,13 +178,13 @@ public function testIncludeResponseButtons( $config_setting, $recipient, $has_bu
public function dataIncludeResponseButtons() {
return [
// dav.invitation_link_recipients, recipient, $has_buttons
[ true, 'joe@internal.com', true],
[ 'yes', 'joe@internal.com', true],
[ 'joe@internal.com', 'joe@internal.com', true],
[ 'internal.com', 'joe@internal.com', true],
[ ['pete@otherinternal.com', 'internal.com'], 'joe@internal.com', true],
[ false, 'joe@internal.com', false],
[ 'pete@otherinternal.com,internal.com', 'joe@internal.com', true],
[ 'no', 'joe@internal.com', false],
[ 'internal.com', 'joe@external.com', false],
[ ['jane@otherinternal.com', 'internal.com'], 'joe@otherinternal.com', false],
[ 'jane@otherinternal.com,internal.com', 'joe@otherinternal.com', false],
];
}

Expand Down
27 changes: 0 additions & 27 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1696,33 +1696,6 @@
'/^Microsoft-WebDAV-MiniRedir/', // Windows webdav drive
),

/**
* The caldav server sends invitation emails to invitees, attaching the ICS
* file for the invitation. It also may include, in the body of the e-mail,
* invitation accept/reject web links referencing URL's that point to the nextcloud server.
*
* Although any recipient can read and reply to the ICS file via the iMip protocol,
* we must only present the web links to recipients who can access the nextcloud
* web server via their internet/intranet.
*
* When your nextcloud server is restricted behind a firewall, accessible
* only via an internal network or via vpn, you can set "dav.invitation_link_recipients"
* to the email address or email domain, or array of addresses or domains,
* of recipients who can access the server. Only those recipients will get web links. External
* users can accept/reject invitations by emailing back ICS files containing appropriate
* messages, using the iMip protocol. Many mail clients support this functionality.
*
* To suppress iMip web links entirely, set dav.invitation_link_recipients to false.
* To deliver iMip web links always, set dav.invitation_link_recipients to true.
*
* Examples:
* 'dav.invitation_link_recipients' => 'internal.example.com',
* 'dav.invitation_link_recipients' => array( 'internal.example.com', 'pat@roadwarrior.example.com' ),
* 'dav.invitation_link_recipients' => false,
*
*/
'dav.invitation_link_recipients' => true, // always include accept/reject server links in iMip emails

/**
* By default there is on public pages a link shown that allows users to
* learn about the "simple sign up" - see https://nextcloud.com/signup/
Expand Down

0 comments on commit 8d8bcea

Please sign in to comment.