Skip to content

Commit

Permalink
fixup! refactor: Use Nextcloud sets for rector
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Sep 11, 2024
1 parent da5d783 commit d65b14a
Show file tree
Hide file tree
Showing 27 changed files with 177 additions and 188 deletions.
30 changes: 12 additions & 18 deletions lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\Mail\Service\Sync\SyncService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
Expand Down Expand Up @@ -82,11 +83,10 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
*
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
public function index(): JSONResponse {
$mailAccounts = $this->accountService->findByUserId($this->currentUserId);

Expand All @@ -100,20 +100,19 @@ public function index(): JSONResponse {
}

/**
* @NoAdminRequired
*
* @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function show(int $id): JSONResponse {
return new JSONResponse($this->accountService->find($this->currentUserId, $id));
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string $accountName
Expand All @@ -134,6 +133,7 @@ public function show(int $id): JSONResponse {
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function update(int $id,
string $accountName,
string $emailAddress,
Expand Down Expand Up @@ -198,7 +198,6 @@ public function update(int $id,
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $editorMode
Expand All @@ -212,10 +211,10 @@ public function update(int $id,
* @param bool|null $signatureAboveQuote
*
* @return JSONResponse
*
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function patchAccount(int $id,
?string $editorMode = null,
?int $order = null,
Expand Down Expand Up @@ -282,7 +281,6 @@ public function patchAccount(int $id,
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $signature
Expand All @@ -293,28 +291,27 @@ public function patchAccount(int $id,
* @throws ServiceException
*/
#[TrapError]
#[NoAdminRequired]
public function updateSignature(int $id, ?string $signature = null): JSONResponse {
$this->accountService->updateSignature($id, $this->currentUserId, $signature);
return new JSONResponse();
}

/**
* @NoAdminRequired
*
* @param int $id
*
* @return JSONResponse
*
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function destroy(int $id): JSONResponse {
$this->accountService->delete($this->currentUserId, $id);
return new JSONResponse();
}

/**
* @NoAdminRequired
*
* @param string $accountName
* @param string $emailAddress
Expand All @@ -329,10 +326,10 @@ public function destroy(int $id): JSONResponse {
* @param string|null $smtpUser
* @param string|null $smtpPassword
* @param string $authMethod
*
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
public function create(string $accountName,
string $emailAddress,
?string $imapHost = null,
Expand Down Expand Up @@ -403,13 +400,12 @@ public function create(string $accountName,
}

/**
* @NoAdminRequired
*
* @return JSONResponse
*
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function draft(int $id,
string $subject,
string $body,
Expand Down Expand Up @@ -456,13 +452,13 @@ public function draft(int $id,
}

/**
* @NoAdminRequired
*
* @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
#[NoAdminRequired]
public function getQuota(int $id): JSONResponse {
$account = $this->accountService->find($this->currentUserId, $id);

Expand All @@ -474,14 +470,13 @@ public function getQuota(int $id): JSONResponse {
}

/**
* @NoAdminRequired
*
* @param int $id Account id
* @param ?int $smimeCertificateId
* @return JSONResponse
*
* @throws ClientException
*/
#[NoAdminRequired]
public function updateSmimeCertificate(int $id, ?int $smimeCertificateId = null) {
$account = $this->accountService->find($this->currentUserId, $id)->getMailAccount();
$account->setSmimeCertificateId($smimeCertificateId);
Expand All @@ -490,13 +485,12 @@ public function updateSmimeCertificate(int $id, ?int $smimeCertificateId = null)
}

/**
* @NoAdminRequired
*
* @param int $id Account id
* @return JSONResponse
*
* @throws ClientException
*/
#[NoAdminRequired]
public function testAccountConnection(int $id) {
return new JSONResponse([
'data' => $this->accountService->testAccountConnection($this->currentUserId, $id),
Expand Down
17 changes: 7 additions & 10 deletions lib/Controller/AliasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
Expand All @@ -34,32 +35,28 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
*
* @param int $accountId
*
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
public function index(int $accountId): JSONResponse {
return new JSONResponse($this->aliasService->findAll($accountId, $this->currentUserId));
}

/**
* @NoAdminRequired
*
*
* @return never
*/
#[TrapError]
#[NoAdminRequired]
public function show() {
throw new NotImplemented();
}

/**
* @NoAdminRequired
*/
#[TrapError]
#[NoAdminRequired]
public function update(int $id,
string $alias,
string $aliasName,
Expand All @@ -76,18 +73,17 @@ public function update(int $id,
}

/**
* @NoAdminRequired
*
* @param int $id
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
public function destroy(int $id): JSONResponse {
return new JSONResponse($this->aliasService->delete($this->currentUserId, $id));
}

/**
* @NoAdminRequired
*
* @param int $accountId
* @param string $alias
Expand All @@ -97,6 +93,7 @@ public function destroy(int $id): JSONResponse {
* @throws DoesNotExistException
*/
#[TrapError]
#[NoAdminRequired]
public function create(int $accountId, string $alias, string $aliasName): JSONResponse {
return new JSONResponse(
$this->aliasService->create($this->currentUserId, $accountId, $alias, $aliasName),
Expand All @@ -105,7 +102,6 @@ public function create(int $accountId, string $alias, string $aliasName): JSONRe
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $signature
Expand All @@ -114,6 +110,7 @@ public function create(int $accountId, string $alias, string $aliasName): JSONRe
* @throws DoesNotExistException
*/
#[TrapError]
#[NoAdminRequired]
public function updateSignature(int $id, ?string $signature = null): JSONResponse {
return new JSONResponse($this->aliasService->updateSignature($this->currentUserId, $id, $signature));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/AutoCompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Mail\Http\TrapError;
use OCA\Mail\Service\AutoCompletion\AutoCompleteService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
Expand All @@ -33,13 +34,12 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
*
* @param string $term
*
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
public function index(string $term): JSONResponse {
if ($this->userId === null) {
return new JSONResponse([]);
Expand Down
10 changes: 4 additions & 6 deletions lib/Controller/AutoConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\Mail\Service\AutoConfig\MxRecord;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\IRequest;
Expand Down Expand Up @@ -46,13 +47,12 @@ public function __construct(IRequest $request,
/**
* @param string $email
*
* @NoAdminRequired
* @UserRateThrottle(limit=5, period=60)
*
* @return JsonResponse
*/
#[TrapError]
#[UserRateLimit(limit: 5, period: 60)]
#[NoAdminRequired]
public function queryIspdb(string $host, string $email): JsonResponse {
$rfc822Address = new Horde_Mail_Rfc822_Address($email);
if (!$rfc822Address->valid || !$this->hostValidator->isValid($host)) {
Expand All @@ -66,13 +66,12 @@ public function queryIspdb(string $host, string $email): JsonResponse {
/**
* @param string $email
*
* @NoAdminRequired
* @UserRateThrottle(limit=5, period=60)
*
* @return JsonResponse
*/
#[TrapError]
#[UserRateLimit(limit: 5, period: 60)]
#[NoAdminRequired]
public function queryMx(string $email): JsonResponse {
$rfc822Address = new Horde_Mail_Rfc822_Address($email);
if (!$rfc822Address->valid || !$this->hostValidator->isValid($rfc822Address->host)) {
Expand All @@ -88,13 +87,12 @@ public function queryMx(string $email): JsonResponse {
* @param string $host
* @param int $port
*
* @NoAdminRequired
* @UserRateThrottle(limit=30, period=60)
*
* @return JsonResponse
*/
#[TrapError]
#[UserRateLimit(limit: 30, period: 60)]
#[NoAdminRequired]
public function testConnectivity(string $host, int $port): JsonResponse {
if (!in_array($port, [143, 993, 465, 587])) {
return JsonResponse::fail('Port not allowed');
Expand Down
12 changes: 6 additions & 6 deletions lib/Controller/AvatarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use OCA\Mail\Http\TrapError;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
Expand All @@ -35,13 +37,12 @@ public function __construct(string $appName,
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $email
* @return JSONResponse
*/
#[TrapError]
#[NoAdminRequired]
#[NoCSRFRequired]
public function url(string $email): JSONResponse {
if (empty($email)) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
Expand Down Expand Up @@ -72,13 +73,12 @@ public function url(string $email): JSONResponse {
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $email
* @return Response
*/
#[TrapError]
#[NoAdminRequired]
#[NoCSRFRequired]
public function image(string $email): Response {
if (empty($email)) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
Expand Down
Loading

0 comments on commit d65b14a

Please sign in to comment.