mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
First code for Spectre import.
This commit is contained in:
@@ -116,7 +116,7 @@ class CreateImport extends Command
|
|||||||
// make prerequisites thing.
|
// make prerequisites thing.
|
||||||
$class = (string)config(sprintf('import.prerequisites.%s', $provider));
|
$class = (string)config(sprintf('import.prerequisites.%s', $provider));
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new FireflyException(sprintf('No class to handle configuration for "%s".', $provider)); // @codeCoverageIgnore
|
throw new FireflyException(sprintf('No class to handle prerequisites for "%s".', $provider)); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
/** @var PrerequisitesInterface $object */
|
/** @var PrerequisitesInterface $object */
|
||||||
$object = app($class);
|
$object = app($class);
|
||||||
|
@@ -85,14 +85,13 @@ class IndexController extends Controller
|
|||||||
Log::debug(sprintf('Created job #%d for provider %s', $importJob->id, $importProvider));
|
Log::debug(sprintf('Created job #%d for provider %s', $importJob->id, $importProvider));
|
||||||
|
|
||||||
$hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider));
|
$hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider));
|
||||||
$hasConfig = (bool)config(sprintf('import.has_config.%s', $importProvider));
|
$hasConfig = (bool)config(sprintf('import.has_job_config.%s', $importProvider));
|
||||||
// if job provider has no prerequisites:
|
// if job provider has no prerequisites:
|
||||||
if ($hasPreReq === false) {
|
if ($hasPreReq === false) {
|
||||||
Log::debug('Provider has no prerequisites. Continue.');
|
Log::debug('Provider has no prerequisites. Continue.');
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
// if job provider also has no configuration:
|
// if job provider also has no configuration:
|
||||||
if ($hasConfig === false) {
|
if ($hasConfig === false) {
|
||||||
Log::debug('Provider has no configuration. Job is ready to start.');
|
Log::debug('Provider needs no configuration for job. Job is ready to start.');
|
||||||
$this->repository->updateStatus($importJob, 'ready_to_run');
|
$this->repository->updateStatus($importJob, 'ready_to_run');
|
||||||
Log::debug('Redirect to status-page.');
|
Log::debug('Redirect to status-page.');
|
||||||
|
|
||||||
@@ -106,13 +105,12 @@ class IndexController extends Controller
|
|||||||
Log::debug('Redirect to configuration.');
|
Log::debug('Redirect to configuration.');
|
||||||
|
|
||||||
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
return redirect(route('import.job.configuration.index', [$importJob->key]));
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
}
|
||||||
Log::debug('Job provider has prerequisites.');
|
Log::debug('Job provider has prerequisites.');
|
||||||
// if need to set prerequisites, do that first.
|
// if need to set prerequisites, do that first.
|
||||||
$class = (string)config(sprintf('import.prerequisites.%s', $importProvider));
|
$class = (string)config(sprintf('import.prerequisites.%s', $importProvider));
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new FireflyException(sprintf('No class to handle configuration for "%s".', $importProvider)); // @codeCoverageIgnore
|
throw new FireflyException(sprintf('No class to handle prerequisites for "%s".', $importProvider)); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
/** @var PrerequisitesInterface $providerPre */
|
/** @var PrerequisitesInterface $providerPre */
|
||||||
$providerPre = app($class);
|
$providerPre = app($class);
|
||||||
@@ -189,7 +187,6 @@ class IndexController extends Controller
|
|||||||
|
|
||||||
$providers[$providerName] = [
|
$providers[$providerName] = [
|
||||||
'has_prereq' => (bool)config('import.has_prereq.' . $providerName),
|
'has_prereq' => (bool)config('import.has_prereq.' . $providerName),
|
||||||
'has_config' => (bool)config('import.has_config.' . $providerName),
|
|
||||||
];
|
];
|
||||||
$class = (string)config(sprintf('import.prerequisites.%s', $providerName));
|
$class = (string)config(sprintf('import.prerequisites.%s', $providerName));
|
||||||
$result = false;
|
$result = false;
|
||||||
|
@@ -83,7 +83,7 @@ class JobConfigurationController extends Controller
|
|||||||
|
|
||||||
// if provider has no config, just push it through:
|
// if provider has no config, just push it through:
|
||||||
$importProvider = $importJob->provider;
|
$importProvider = $importJob->provider;
|
||||||
if (!(bool)config(sprintf('import.has_config.%s', $importProvider))) {
|
if (!(bool)config(sprintf('import.has_job_config.%s', $importProvider))) {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
Log::debug('Job needs no config, is ready to run!');
|
Log::debug('Job needs no config, is ready to run!');
|
||||||
$this->repository->updateStatus($importJob, 'ready_to_run');
|
$this->repository->updateStatus($importJob, 'ready_to_run');
|
||||||
|
@@ -83,7 +83,7 @@ class PrerequisitesController extends Controller
|
|||||||
app('view')->share('subTitle', trans('import.prerequisites_breadcrumb_' . $importProvider));
|
app('view')->share('subTitle', trans('import.prerequisites_breadcrumb_' . $importProvider));
|
||||||
$class = (string)config(sprintf('import.prerequisites.%s', $importProvider));
|
$class = (string)config(sprintf('import.prerequisites.%s', $importProvider));
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
throw new FireflyException(sprintf('No class to handle configuration for "%s".', $importProvider)); // @codeCoverageIgnore
|
throw new FireflyException(sprintf('No class to handle prerequisites for "%s".', $importProvider)); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
/** @var PrerequisitesInterface $object */
|
/** @var PrerequisitesInterface $object */
|
||||||
$object = app($class);
|
$object = app($class);
|
||||||
|
@@ -24,18 +24,15 @@ namespace FireflyIII\Import\Prerequisites;
|
|||||||
|
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Log;
|
|
||||||
use Preferences;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains all the routines necessary to connect to Spectre.
|
* This class contains all the routines necessary to connect to Spectre.
|
||||||
*/
|
*/
|
||||||
class SpectrePrerequisites implements PrerequisitesInterface
|
class SpectrePrerequisites implements PrerequisitesInterface
|
||||||
{
|
{
|
||||||
// /** @var User */
|
/** @var User */
|
||||||
// private $user;
|
private $user;
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
// * Returns view name that allows user to fill in prerequisites. Currently asks for the API key.
|
||||||
@@ -204,7 +201,20 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
|||||||
*/
|
*/
|
||||||
public function getViewParameters(): array
|
public function getViewParameters(): array
|
||||||
{
|
{
|
||||||
return [];
|
/** @var Preference $appIdPreference */
|
||||||
|
$appIdPreference = app('preferences')->getForUser($this->user, 'spectre_app_id', null);
|
||||||
|
$appId = null === $appIdPreference ? '' : $appIdPreference->data;
|
||||||
|
|
||||||
|
/** @var Preference $secretPreference */
|
||||||
|
$secretPreference = app('preferences')->getForUser($this->user, 'spectre_secret', null);
|
||||||
|
$secret = null === $secretPreference ? '' : $secretPreference->data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'app_id' => $appId,
|
||||||
|
'secret' => $secret,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,6 +234,7 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
|||||||
*/
|
*/
|
||||||
public function setUser(User $user): void
|
public function setUser(User $user): void
|
||||||
{
|
{
|
||||||
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,4 +250,20 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
|||||||
{
|
{
|
||||||
return new MessageBag;
|
return new MessageBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function hasAppId(): bool
|
||||||
|
{
|
||||||
|
$appId = app('preferences')->getForUser($this->user, 'spectre_app_id', null);
|
||||||
|
if (null === $appId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ('' === (string)$appId->data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ return [
|
|||||||
'fake' => true,
|
'fake' => true,
|
||||||
'file' => true,
|
'file' => true,
|
||||||
'bunq' => false,
|
'bunq' => false,
|
||||||
'spectre' => false,
|
'spectre' => true,
|
||||||
'plaid' => false,
|
'plaid' => false,
|
||||||
'quovo' => false,
|
'quovo' => false,
|
||||||
'yodlee' => false,
|
'yodlee' => false,
|
||||||
@@ -75,21 +75,21 @@ return [
|
|||||||
'prerequisites' => [
|
'prerequisites' => [
|
||||||
'fake' => FakePrerequisites::class,
|
'fake' => FakePrerequisites::class,
|
||||||
'file' => false,
|
'file' => false,
|
||||||
'bunq' => SpectrePrerequisites::class,
|
'bunq' => false,
|
||||||
'spectre' => false,
|
'spectre' => SpectrePrerequisites::class,
|
||||||
'plaid' => false,
|
'plaid' => false,
|
||||||
'quovo' => false,
|
'quovo' => false,
|
||||||
'yodlee' => false,
|
'yodlee' => false,
|
||||||
],
|
],
|
||||||
// some providers may have extra configuration per job.
|
// some providers may need extra configuration per job
|
||||||
'has_config' => [
|
'has_job_config' => [
|
||||||
'fake' => true,
|
'fake' => true,
|
||||||
'file' => true,
|
'file' => true,
|
||||||
'bunq' => true,
|
'bunq' => false,
|
||||||
'spectre' => true,
|
'spectre' => false,
|
||||||
'plaid' => true,
|
'plaid' => false,
|
||||||
'quovo' => true,
|
'quovo' => false,
|
||||||
'yodlee' => true,
|
'yodlee' => false,
|
||||||
],
|
],
|
||||||
// if so, this is the class that handles it.
|
// if so, this is the class that handles it.
|
||||||
'configuration' => [
|
'configuration' => [
|
||||||
|
@@ -68,6 +68,9 @@ return [
|
|||||||
// prerequisites:
|
// prerequisites:
|
||||||
'prereq_fake_title' => 'Prerequisites for an import from the fake import provider',
|
'prereq_fake_title' => 'Prerequisites for an import from the fake import provider',
|
||||||
'prereq_fake_text' => 'This fake provider requires a fake API key. It must be 32 characters long. You can use this one: 123456789012345678901234567890AA',
|
'prereq_fake_text' => 'This fake provider requires a fake API key. It must be 32 characters long. You can use this one: 123456789012345678901234567890AA',
|
||||||
|
'prereq_spectre_title' => 'Prerequisites for an import using the Spectre API',
|
||||||
|
'prereq_spectre_text' => 'In order to import data using the Spectre API (v4), you must provide Firefly III with two secret values. They can be found on the <a href="https://www.saltedge.com/clients/profile/secrets">secrets page</a>.',
|
||||||
|
'prereq_spectre_pub' => 'Likewise, the Spectre API needs to know the public key you see below. Without it, it will not recognize you. Please enter this public key on your <a href="https://www.saltedge.com/clients/profile/secrets">secrets page</a>.',
|
||||||
// prerequisites success messages:
|
// prerequisites success messages:
|
||||||
'prerequisites_saved_for_fake' => 'Fake API key stored successfully!',
|
'prerequisites_saved_for_fake' => 'Fake API key stored successfully!',
|
||||||
|
|
||||||
|
@@ -10,13 +10,13 @@
|
|||||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ trans('import.spectre_prerequisites_title') }}</h3>
|
<h3 class="box-title">{{ trans('import.prereq_spectre_title') }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
<p>
|
<p>
|
||||||
{{ trans('import.spectre_prerequisites_text')|raw }}
|
{{ trans('import.prereq_spectre_text')|raw }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8">
|
<div class="col-lg-8">
|
||||||
<p>{{ trans('import.spectre_enter_pub_key')|raw }}</p>
|
<p>{{ trans('import.prereq_spectre_pub')|raw }}</p>
|
||||||
<div class="form-group" id="pub_key_holder">
|
<div class="form-group" id="pub_key_holder">
|
||||||
<label for="ffInput_pub_key_holder" class="col-sm-4 control-label">{{ trans('form.public_key') }}</label>
|
<label for="ffInput_pub_key_holder" class="col-sm-4 control-label">{{ trans('form.public_key') }}</label>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user