2020-11-19 12:47:50 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-06-24 14:22:50 +03:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-11-19 12:47:50 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Mail\Controller;
|
|
|
|
|
|
|
|
use OCA\Mail\AppInfo\Application;
|
|
|
|
use OCA\Mail\Contracts\ITrustedSenderService;
|
|
|
|
use OCA\Mail\Http\JsonResponse;
|
2023-01-25 17:40:41 +03:00
|
|
|
use OCA\Mail\Http\TrapError;
|
2020-11-19 12:47:50 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http;
|
2024-07-30 13:09:10 +03:00
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
2020-11-19 12:47:50 +03:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
2024-07-30 13:09:10 +03:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2020-11-19 12:47:50 +03:00
|
|
|
class TrustedSendersController extends Controller {
|
2022-10-01 23:01:07 +03:00
|
|
|
private ?string $uid;
|
|
|
|
private ITrustedSenderService $trustedSenderService;
|
2020-11-19 12:47:50 +03:00
|
|
|
|
|
|
|
public function __construct(IRequest $request,
|
2023-06-28 15:44:08 +03:00
|
|
|
?string $UserId,
|
|
|
|
ITrustedSenderService $trustedSenderService) {
|
2020-11-19 12:47:50 +03:00
|
|
|
parent::__construct(Application::APP_ID, $request);
|
|
|
|
|
|
|
|
$this->uid = $UserId;
|
|
|
|
$this->trustedSenderService = $trustedSenderService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $email
|
2021-02-11 20:32:08 +03:00
|
|
|
* @param string $type
|
2020-11-19 12:47:50 +03:00
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2021-02-11 20:32:08 +03:00
|
|
|
public function setTrusted(string $email, string $type): JsonResponse {
|
2020-11-19 12:47:50 +03:00
|
|
|
$this->trustedSenderService->trust(
|
|
|
|
$this->uid,
|
2021-02-11 20:32:08 +03:00
|
|
|
$email,
|
|
|
|
$type
|
2020-11-19 12:47:50 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return JsonResponse::success(null, Http::STATUS_CREATED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @param string $email
|
2021-02-11 20:32:08 +03:00
|
|
|
* @param string $type
|
2020-11-19 12:47:50 +03:00
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2021-02-11 20:32:08 +03:00
|
|
|
public function removeTrust(string $email, string $type): JsonResponse {
|
2020-11-19 12:47:50 +03:00
|
|
|
$this->trustedSenderService->trust(
|
|
|
|
$this->uid,
|
|
|
|
$email,
|
2021-02-11 20:32:08 +03:00
|
|
|
$type,
|
2020-11-19 12:47:50 +03:00
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
return JsonResponse::success(null);
|
|
|
|
}
|
2020-12-16 18:23:16 +03:00
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2023-01-25 17:40:41 +03:00
|
|
|
#[TrapError]
|
2020-12-16 18:23:16 +03:00
|
|
|
public function list(): JsonResponse {
|
|
|
|
$list = $this->trustedSenderService->getTrusted(
|
|
|
|
$this->uid
|
|
|
|
);
|
|
|
|
|
|
|
|
return JsonResponse::success($list);
|
|
|
|
}
|
2020-11-19 12:47:50 +03:00
|
|
|
}
|