Fix rules surrounding creation of jobs [skip ci]

This commit is contained in:
James Cole 2018-05-13 09:34:27 +02:00
parent 1aae84a4d0
commit 0c99248deb
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 8 additions and 8 deletions

View File

@ -72,13 +72,11 @@ class IndexController extends Controller
public function create(string $importProvider)
{
// can only create "fake" for demo user.
$providers = array_keys($this->getProviders());
if (!in_array($importProvider, $providers, true)) {
session()->flash('warning', trans('import.cannot_create_for_provider', ['provider' => $importProvider]));
if (
!(bool)config('app.debug')
&& !(bool)config(sprintf('import.enabled.%s', $importProvider)) === true
&& !\in_array(config('app.env'), ['demo', 'testing'])
) {
throw new FireflyException(sprintf('Import using provider "%s" is currently not available.', $importProvider)); // @codeCoverageIgnore
return redirect(route('import.index'));
}
$importJob = $this->repository->create($importProvider);
@ -148,6 +146,7 @@ class IndexController extends Controller
$providerNames = array_keys(config('import.enabled'));
$providers = [];
$isDemoUser = $this->userRepository->hasRole(auth()->user(), 'demo');
$isDebug = (bool)config('app.debug');
foreach ($providerNames as $providerName) {
Log::debug(sprintf('Now with provider %s', $providerName));
// only consider enabled providers
@ -163,7 +162,7 @@ class IndexController extends Controller
Log::debug('User is demo and this provider is not allowed for demo user. NEXT!');
continue;
}
if ($isDemoUser === false && $allowedForUser === false) {
if ($isDemoUser === false && $allowedForUser === false && $isDebug === false) {
Log::debug('User is not demo and this provider is not allowed for such users. NEXT!');
continue;
}

View File

@ -28,6 +28,7 @@ return [
'prerequisites_breadcrumb_fake' => 'Prerequisites for the fake import provider',
'job_configuration_breadcrumb' => 'Configuration for ":key"',
'job_status_breadcrumb' => 'Import status for ":key"',
'cannot_create_for_provider' => 'Firefly III cannot create a job for the ":provider"-provider.',
// index page:
'general_index_title' => 'Import a file',
@ -132,7 +133,7 @@ return [
'job_config_field_value' => 'Field value',
'job_config_field_mapped' => 'Mapped to',
'map_do_not_map' => '(do not map)',
'job_config_map_submit' => 'Start the import',
'job_config_map_submit' => 'Start the import',
// import status page: