Merge pull request #8461 from nextcloud/fix/8402/feedback-for-sieve-script-error

fix(sieve): show feedback on syntax error
This commit is contained in:
Johannes 2023-05-12 10:55:46 +02:00 коммит произвёл GitHub
Родитель fc2b86a542 3443da78be
Коммит 78d1453c15
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 17 добавлений и 3 удалений

Просмотреть файл

@ -39,6 +39,7 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\Security\ICrypto;
use OCP\Security\IRemoteHostValidator;
use Psr\Log\LoggerInterface;
class SieveController extends Controller {
private AccountService $accountService;
@ -47,6 +48,7 @@ class SieveController extends Controller {
private string $currentUserId;
private ICrypto $crypto;
private IRemoteHostValidator $hostValidator;
private LoggerInterface $logger;
public function __construct(IRequest $request,
string $UserId,
@ -54,7 +56,8 @@ class SieveController extends Controller {
MailAccountMapper $mailAccountMapper,
SieveClientFactory $sieveClientFactory,
ICrypto $crypto,
IRemoteHostValidator $hostValidator
IRemoteHostValidator $hostValidator,
LoggerInterface $logger
) {
parent::__construct(Application::APP_ID, $request);
$this->currentUserId = $UserId;
@ -63,6 +66,7 @@ class SieveController extends Controller {
$this->sieveClientFactory = $sieveClientFactory;
$this->crypto = $crypto;
$this->hostValidator = $hostValidator;
$this->logger = $logger;
}
/**
@ -109,7 +113,13 @@ class SieveController extends Controller {
$sieve = $this->getClient($id);
$scriptName = $sieve->getActive() ?? 'nextcloud';
$sieve->installScript($scriptName, $script, true);
try {
$sieve->installScript($scriptName, $script, true);
} catch (ManagesieveException $e) {
$this->logger->error('Installing sieve script failed: ' . $e->getMessage(), ['app' => 'mail', 'exception' => $e]);
return new JSONResponse(data: ['message' => $e->getMessage()], statusCode: Http::STATUS_UNPROCESSABLE_ENTITY);
}
return new JSONResponse();
}

Просмотреть файл

@ -79,7 +79,11 @@ export default {
},
})
} catch (error) {
this.errorMessage = error.message
if (error.response.status === 422) {
this.errorMessage = t('mail', 'The syntax seems to be incorrect:') + ' ' + error.response.data.message
} else {
this.errorMessage = error.message
}
}
this.loading = false