Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
['name' => 'Endpoint#deleteAllNotifications', 'url' => '/api/{apiVersion}/notifications', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => 'v(1|2)']],
['name' => 'Push#registerDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v2']],
['name' => 'Push#removeDevice', 'url' => '/api/{apiVersion}/push', 'verb' => 'DELETE', 'requirements' => ['apiVersion' => 'v2']],
['name' => 'API#generateNotification', 'url' => '/api/{apiVersion}/notifications/{userId}', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v(1|2)'], 'root' => '/apps/admin_notifications'],

['name' => 'API#generateNotification', 'url' => '/api/{apiVersion}/admin_notifications/{userId}', 'verb' => 'POST', 'requirements' => ['apiVersion' => 'v(1|2)']],
],
];
6 changes: 5 additions & 1 deletion docs/admin-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ Options:

## HTTP request

> ⚠️ The URL had to be changed when switching from Nextcloud 20 to 21:
> * 20 and earlier: ocs/v2.php/apps/admin_notifications/api/v1/notifications/{user}
> * 21 and later: ocs/v2.php/apps/notifications/api/v2/admin_notifications/{user}

```
curl -H "OCS-APIREQUEST: true" -X POST \
https://admin:admin@localhost/ocs/v2.php/apps/admin_notifications/api/v1/notifications/admin \
https://admin:admin@localhost/ocs/v2.php/apps/notifications/api/v1/admin_notifications/admin \
-d "shortMessage=Short message up to 255 characters" \
-d "longMessage=Optional: longer message with more details, up to 4000 characters"
```
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2017 Joas Schilling <[email protected]>
*
Expand Down Expand Up @@ -43,14 +46,11 @@ class APIController extends OCSController {
/** @var IManager */
protected $notificationManager;

/**
* @param string $appName
* @param IRequest $request
* @param ITimeFactory $timeFactory
* @param IUserManager $userManager
* @param IManager $notificationManager
*/
public function __construct($appName, IRequest $request, ITimeFactory $timeFactory, IUserManager $userManager, IManager $notificationManager) {
public function __construct(string $appName,
IRequest $request,
ITimeFactory $timeFactory,
IUserManager $userManager,
IManager $notificationManager) {
parent::__construct($appName, $request);

$this->timeFactory = $timeFactory;
Expand Down
27 changes: 27 additions & 0 deletions tests/Integration/features/admin-notification-v2.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: admin-notification
Background:
Given user "test1" exists
Given as user "test1"

Scenario: Create notification
Given user "admin" sends admin notification to "test1" with
| shortMessage | without long message |
Then user "test1" has 1 notifications on v2
And last notification on v2 matches
| app | admin_notifications |
| subject | without long message |
| link | |
| message | |
| object_type | admin_notifications |

Scenario: Create different notification
Given user "admin" sends admin notification to "test1" with
| shortMessage | with long message |
| longMessage | this is long message |
Then user "test1" has 1 notifications on v2
And last notification on v2 matches
| app | admin_notifications |
| subject | with long message |
| link | |
| message | this is long message |
| object_type | admin_notifications |
15 changes: 15 additions & 0 deletions tests/Integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ public function receiveNotification(string $user, TableNode $formData) {
}
}

/**
* @Given /^user "([^"]*)" sends admin notification to "([^"]*)" with$/
*
* @param string $sender
* @param string $recipient
* @param TableNode|null $formData
*/
public function sendAdminNotification(string $sender, string $recipient, TableNode $formData) {
$currentUser = $this->currentUser;
$this->setCurrentUser($sender);
$this->sendingToWith('POST', '/apps/notifications/api/v2/admin_notifications/' . $recipient . '?format=json', $formData);
$this->assertStatusCode($this->response, 200);
$this->setCurrentUser($currentUser);
}

/**
* @When /^getting notifications on (v\d+)(| with different etag| with matching etag)$/
* @param string $api
Expand Down