Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use Nextcloud sets for rector #10129

Draft
wants to merge 4 commits into
base: refactor/oc-server-get
Choose a base branch
from
Draft
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
32 changes: 13 additions & 19 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 All @@ -54,7 +55,7 @@
public function __construct(string $appName,
IRequest $request,
AccountService $accountService,
$UserId,
$userId,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kesselb only the argument is renamed, not its usaged 🙊

LoggerInterface $logger,
IL10N $l10n,
AliasesService $aliasesService,
Expand All @@ -68,7 +69,7 @@
) {
parent::__construct($appName, $request);
$this->accountService = $accountService;
$this->currentUserId = $UserId;

Check failure on line 72 in lib/Controller/AccountsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedVariable

lib/Controller/AccountsController.php:72:26: UndefinedVariable: Cannot find referenced variable $UserId (see https://psalm.dev/024)
$this->logger = $logger;
$this->l10n = $l10n;
$this->aliasesService = $aliasesService;
Expand All @@ -82,11 +83,10 @@
}

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

Expand All @@ -100,20 +100,19 @@
}

/**
* @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 @@
* @throws ClientException
*/
#[TrapError]
#[NoAdminRequired]
public function update(int $id,
string $accountName,
string $emailAddress,
Expand Down Expand Up @@ -198,7 +198,6 @@
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $editorMode
Expand All @@ -212,10 +211,10 @@
* @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 @@
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $signature
Expand All @@ -293,28 +291,27 @@
* @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 @@
* @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 @@
}

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

/**
* @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 @@
}

/**
* @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 @@
}

/**
* @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
19 changes: 8 additions & 11 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 @@ -27,39 +28,35 @@
public function __construct(string $appName,
IRequest $request,
AliasesService $aliasesService,
string $UserId) {
string $userId) {
parent::__construct($appName, $request);
$this->aliasService = $aliasesService;
$this->currentUserId = $UserId;

Check failure on line 34 in lib/Controller/AliasesController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

UndefinedVariable

lib/Controller/AliasesController.php:34:26: UndefinedVariable: Cannot find referenced variable $UserId (see https://psalm.dev/024)
}

/**
* @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 @@
}

/**
* @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 @@
* @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 @@
}

/**
* @NoAdminRequired
*
* @param int $id
* @param string|null $signature
Expand All @@ -114,6 +110,7 @@
* @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
Loading
Loading