Skip to content

Commit

Permalink
Merge pull request #1707 from nextcloud/techdebt/noid/openapi-scopes
Browse files Browse the repository at this point in the history
Demo for OpenAPI scopes
  • Loading branch information
nickvergessen authored Jan 24, 2024
2 parents 4627e91 + 9a345d8 commit cb3f703
Show file tree
Hide file tree
Showing 8 changed files with 2,440 additions and 684 deletions.
2 changes: 2 additions & 0 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\Notifications\Controller;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Utility\ITimeFactory;
Expand Down Expand Up @@ -71,6 +72,7 @@ public function __construct(
* 400: Generating notification is not possible
* 404: User not found
*/
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
public function generateNotification(string $userId, string $shortMessage, string $longMessage = ''): DataResponse {
$user = $this->userManager->get($userId);

Expand Down
2 changes: 2 additions & 0 deletions lib/Controller/PushController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OC\Security\IdentityProof\Manager;
use OCA\Notifications\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\Authentication\Exceptions\InvalidTokenException;
Expand All @@ -44,6 +45,7 @@
/**
* @psalm-import-type NotificationsPushDevice from ResponseDefinitions
*/
#[OpenAPI(scope: 'push')]
class PushController extends OCSController {
/** @var IDBConnection */
private $db;
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Notifications\AppInfo\Application;
use OCA\Notifications\Model\SettingsMapper;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function __construct(string $appName,
*
* 200: Personal settings updated
*/
#[OpenAPI]
public function personal(int $batchSetting, string $soundNotification, string $soundTalk): DataResponse {
$this->settingsMapper->setBatchSettingForUser($this->userId, $batchSetting);

Expand All @@ -83,6 +85,7 @@ public function personal(int $batchSetting, string $soundNotification, string $s
*
* 200: Admin settings updated
*/
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
public function admin(int $batchSetting, string $soundNotification, string $soundTalk): DataResponse {
$this->config->setAppValue(Application::APP_ID, 'setting_batchtime', (string) $batchSetting);
$this->config->setAppValue(Application::APP_ID, 'sound_notification', $soundNotification !== 'no' ? 'yes' : 'no');
Expand Down
Loading

0 comments on commit cb3f703

Please sign in to comment.