diff --git a/.drone.star b/.drone.star index 2e092231620..400423748aa 100644 --- a/.drone.star +++ b/.drone.star @@ -286,11 +286,21 @@ config = { "skip": False, "withRemotePhp": [True], "antivirusNeeded": True, + "emailNeeded": True, + "extraEnvironment": { + "EMAIL_HOST": EMAIL_SMTP_HOST, + "EMAIL_PORT": EMAIL_PORT, + }, "extraServerEnvironment": { + "NOTIFICATIONS_SMTP_HOST": EMAIL_SMTP_HOST, + "NOTIFICATIONS_SMTP_PORT": EMAIL_SMTP_PORT, + "NOTIFICATIONS_SMTP_INSECURE": "true", + "NOTIFICATIONS_SMTP_SENDER": EMAIL_SMTP_SENDER, + "NOTIFICATIONS_DEBUG_ADDR": "0.0.0.0:9174", "ANTIVIRUS_SCANNER_TYPE": "clamav", "ANTIVIRUS_CLAMAV_SOCKET": "tcp://clamav:3310", "OCIS_ASYNC_UPLOADS": True, - "OCIS_ADD_RUN_SERVICES": "antivirus", + "OCIS_ADD_RUN_SERVICES": "antivirus,notifications", }, }, }, diff --git a/tests/acceptance/bootstrap/CliContext.php b/tests/acceptance/bootstrap/CliContext.php index d6e4446c785..d75861841cd 100644 --- a/tests/acceptance/bootstrap/CliContext.php +++ b/tests/acceptance/bootstrap/CliContext.php @@ -23,6 +23,7 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Behat\Context\Context; use Behat\Gherkin\Node\TableNode; +use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Assert; use TestHelpers\CliHelper; use TestHelpers\OcisConfigHelper; @@ -468,4 +469,21 @@ class CliContext implements Context { $response = CliHelper::runCommand($body); Assert::assertEquals("200", $response->getStatusCode(), "Failed to clean upload sessions"); } + + /** + * @When /^the administrator triggers "([^"]*)" email notifications using the CLI$/ + * + * @param string $interval + * + * @return void + * @throws GuzzleException + */ + public function theAdministratorTriggersEmailNotificationsUsingTheCLI(string $interval): void { + $command = "notifications send-email --$interval"; + $body = [ + "command" => $command + ]; + + $this->featureContext->setResponse(CliHelper::runCommand($body)); + } } diff --git a/tests/acceptance/bootstrap/EmailContext.php b/tests/acceptance/bootstrap/EmailContext.php index 52d9b297a41..3aa1e7da278 100644 --- a/tests/acceptance/bootstrap/EmailContext.php +++ b/tests/acceptance/bootstrap/EmailContext.php @@ -247,4 +247,24 @@ class EmailContext implements Context { } throw new Exception("Could not find the email to the address: " . $emailAddress); } + + /** + * @Then user :user should have received the following grouped email + * + * @param string $user + * @param PyStringNode $content + * + * @return void + * @throws Exception|GuzzleException + */ + public function userShouldHaveReceivedTheFollowingGroupedEmail( + string $user, + PyStringNode $content + ): void { + $rawExpectedEmailBodyContent = \str_replace("\r\n", "\n", $content->getRaw()); + $expectedEmailBodyContent = $this->featureContext->substituteInLineCodes( + $rawExpectedEmailBodyContent + ); + $this->assertEmailContains($user, $expectedEmailBodyContent); + } } diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index 9315bca436d..57968283bf7 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -78,6 +78,7 @@ class FeatureContext extends BehatVariablesContext { private string $adminUsername; private string $adminPassword; private string $originalAdminPassword; + private DateTime $expiryDateTime; /** * An array of values of replacement values of user attributes. @@ -454,6 +455,7 @@ class FeatureContext extends BehatVariablesContext { $this->regularUserPassword = $regularUserPassword; $this->currentServer = 'LOCAL'; $this->cookieJar = new CookieJar(); + $this->expiryDateTime = new DateTime('yesterday'); // These passwords are referenced in tests and can be overridden by // setting environment variables. @@ -903,6 +905,22 @@ class FeatureContext extends BehatVariablesContext { ); } + /** + * @return DateTime + */ + public function getExpiryDateTime(): DateTime { + return $this->expiryDateTime; + } + + /** + * @param string $format + * + * @return string + */ + public function formatExpiryDateTime(string $format = 'Y-m-d H:i:sP'): string { + return $this->getExpiryDateTime()->format($format); + } + /** * @Given using SharingNG * @@ -2476,6 +2494,13 @@ class FeatureContext extends BehatVariablesContext { "getXRequestIdRegex" ], "parameter" => [] + ], + [ + "code" => "%expiry_date_in_mail%", + "function" => [ + $this, "formatExpiryDateTime" + ], + "parameter" => ['Y-m-d H:i:s'] ] ]; if ($user !== null) { diff --git a/tests/acceptance/bootstrap/SettingsContext.php b/tests/acceptance/bootstrap/SettingsContext.php index 9ab764a2b4c..2618975826a 100644 --- a/tests/acceptance/bootstrap/SettingsContext.php +++ b/tests/acceptance/bootstrap/SettingsContext.php @@ -666,4 +666,29 @@ class SettingsContext implements Context { ); $this->featureContext->setResponse($response); } + + /** + * @Given /^user "([^"]*)" has set the email sending interval to "([^"]*)" using the settings API$/ + * + * @param string $user + * @param string $interval + * + * @return void + * @throws Exception|GuzzleException + */ + public function userHasSetTheEmailSendingIntervalToUsingTheSettingsAPI( + string $user, + string $interval, + ): void { + $body = $this->getBodyForNotificationSetting($user, "Email sending interval"); + $body["value"]["stringValue"] = $interval; + $response = SettingsHelper::updateSettings( + $this->featureContext->getBaseUrl(), + $this->featureContext->getActualUsername($user), + $this->featureContext->getPasswordForUser($user), + json_encode($body), + $this->featureContext->getStepLineRef(), + ); + $this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response); + } } diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index 1ed893029ee..0b6a83adc80 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -2717,7 +2717,6 @@ class SpacesContext implements Context { $this->featureContext->shareNgAddToCreatedUserGroupShares($response); } $this->featureContext->setResponse($response); - } else { $rows['permissions'] = (string)$this->featureContext->getLastCreatedUserGroupShare()->permissions; $this->featureContext->setResponse($this->updateSharedResource($user, $rows)); @@ -4810,4 +4809,24 @@ class SpacesContext implements Context { ) ); } + + /** + * @Given /^user "([^"]*)" has expired the membership of user "([^"]*)" from space "([^"]*)"$/ + * + * @param string $user + * @param string $memberUser + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function userHasExpiredTheMembershipOfUserFromSpace( + string $user, + string $memberUser, + string $spaceName + ): void { + $rows['expireDate'] = $this->featureContext->formatExpiryDateTime('Y-m-d\\TH:i:sP'); + $rows['shareWith'] = $memberUser; + $this->featureContext->setResponse($this->shareSpace($user, $spaceName, $rows)); + } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 6a963fadad1..a40298a695d 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -464,6 +464,9 @@ default: - TrashbinContext: - SpacesTUSContext: - AuthAppContext: + - SettingsContext: + - NotificationContext: + - EmailContext: coreApiMain: paths: diff --git a/tests/acceptance/features/cliCommands/backupConsistency.feature b/tests/acceptance/features/cliCommands/backupConsistency.feature index e061b4fb8be..a83a5d147d4 100644 --- a/tests/acceptance/features/cliCommands/backupConsistency.feature +++ b/tests/acceptance/features/cliCommands/backupConsistency.feature @@ -53,4 +53,4 @@ Feature: backup consistency And the administrator has started the server When user "Alice" gets the number of versions of file "/textfile0.txt" Then the HTTP status code should be "207" - And the number of versions should be "2" \ No newline at end of file + And the number of versions should be "2" diff --git a/tests/acceptance/features/cliCommands/emailNotification.feature b/tests/acceptance/features/cliCommands/emailNotification.feature new file mode 100644 index 00000000000..54fe3bafd5f --- /dev/null +++ b/tests/acceptance/features/cliCommands/emailNotification.feature @@ -0,0 +1,125 @@ +@env-config @email +Feature: get grouped email notification + As a user + I want to get email notification of grouped events related to me either daily or weekly + So that I can stay updated about the events either once a day or once a week + + + Background: + Given using spaces DAV path + And using SharingNG + And these users have been created with default attributes: + | username | + | Alice | + | Brian | + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "New-Space" with the default quota using the Graph API + And user "Alice" has uploaded file with content "some data" to "lorem.txt" + + + Scenario: get daily grouped email notification + Given user "Brian" has set the email sending interval to "daily" using the settings API + And user "Alice" has sent the following resource share invitation: + | resource | lorem.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + And user "Alice" has removed the access of user "Brian" from resource "lorem.txt" of space "Personal" + And user "Alice" has sent the following space share invitation: + | space | New-Space | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Viewer | + And user "Alice" has removed the access of user "Brian" from space "New-Space" + And user "Alice" has sent the following space share invitation: + | space | New-Space | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Viewer | + | expirationDateTime | 2042-03-25T23:59:59.000Z | + And user "Alice" has expired the membership of user "Brian" from space "New-Space" + When the administrator triggers "daily" email notifications using the CLI + Then the command should be successful + And the command output should contain "successfully sent SendEmailsEvent" + And user "Brian" should have received the following grouped email + """ + Hi Brian Murphy, + + Alice Hansen has shared "lorem.txt" with you. + + + Alice Hansen has unshared 'lorem.txt' with you. + + Even though this share has been revoked you still might have access through other shares and/or space memberships. + + + Alice Hansen has invited you to join "New-Space". + + + Alice Hansen has removed you from "New-Space". + + You might still have access through your other groups or direct membership. + + + Alice Hansen has invited you to join "New-Space". + + + Your membership of space New-Space has expired at %expiry_date_in_mail% + + Even though this membership has expired you still might have access through other shares and/or space memberships + """ + + + Scenario: get weekly grouped email notification + Given user "Brian" has set the email sending interval to "weekly" using the settings API + And user "Alice" has sent the following resource share invitation: + | resource | lorem.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + And user "Alice" has removed the access of user "Brian" from resource "lorem.txt" of space "Personal" + And user "Alice" has sent the following space share invitation: + | space | New-Space | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Viewer | + And user "Alice" has removed the access of user "Brian" from space "New-Space" + And user "Alice" has sent the following space share invitation: + | space | New-Space | + | sharee | Brian | + | shareType | user | + | permissionsRole | Space Viewer | + | expirationDateTime | 2042-03-25T23:59:59.000Z | + And user "Alice" has expired the membership of user "Brian" from space "New-Space" + When the administrator triggers "weekly" email notifications using the CLI + Then the command should be successful + And the command output should contain "successfully sent SendEmailsEvent" + And user "Brian" should have received the following grouped email + """ + Hi Brian Murphy, + + Alice Hansen has shared "lorem.txt" with you. + + + Alice Hansen has unshared 'lorem.txt' with you. + + Even though this share has been revoked you still might have access through other shares and/or space memberships. + + + Alice Hansen has invited you to join "New-Space". + + + Alice Hansen has removed you from "New-Space". + + You might still have access through your other groups or direct membership. + + + Alice Hansen has invited you to join "New-Space". + + + Your membership of space New-Space has expired at %expiry_date_in_mail% + + Even though this membership has expired you still might have access through other shares and/or space memberships + """