Merge branch 'develop' into v480

* develop: (21 commits)
  Update lock file
  Update change logs and config files.
  Enable norsk, update version of DB
  Various language string updates.
  Norwegian strings.
  Improve installer middleware for Sandstorm.
  Fix some issues with importer #2166
  Other delete thing.
  More debug things.
  Extra debug info for #2159 and some kernel changes.
  Extra debug info for #2159
  Fix #2173
  Rename class and add copyright statement @wrouesnel #2167
  Fix LDAP auth configuration paths.
  Fix some cache issues and a version bump.
  Updated file list.
  Updated list.
  New file list.
  Update composer file.
  Small fix in changelog.
  ...
This commit is contained in:
James Cole
2019-03-17 12:34:36 +01:00
67 changed files with 4405 additions and 908 deletions

View File

@@ -147,8 +147,9 @@ class RecurrenceController extends Controller
*/
public function suggest(Request $request): JsonResponse
{
$string = $request->get('date') ?? date('Y-m-d');
$today = new Carbon;
$date = Carbon::createFromFormat('Y-m-d', $request->get('date'));
$date = Carbon::createFromFormat('Y-m-d', $string);
$preSelected = (string)$request->get('pre_select');
$result = [];
if ($date > $today || 'true' === (string)$request->get('past')) {

View File

@@ -25,10 +25,13 @@ namespace FireflyIII\Http\Controllers\System;
use Artisan;
use Cache;
use Exception;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
use Laravel\Passport\Passport;
use Log;
use phpseclib\Crypt\RSA;
@@ -75,11 +78,17 @@ class InstallController extends Controller
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
Cache::clear();
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
@@ -91,6 +100,9 @@ class InstallController extends Controller
*/
public function index()
{
// index will set FF3 version.
app('fireflyconfig')->set('ff3_version', (string)config('firefly.version'));
return view('install.index');
}
@@ -118,8 +130,12 @@ class InstallController extends Controller
return response()->json(['error' => false, 'message' => 'OK']);
}
file_put_contents($publicKey, array_get($keys, 'publickey'));
file_put_contents($privateKey, array_get($keys, 'privatekey'));
file_put_contents($publicKey, Arr::get($keys, 'publickey'));
file_put_contents($privateKey, Arr::get($keys, 'privatekey'));
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
@@ -148,6 +164,9 @@ class InstallController extends Controller
return response()->json(['error' => true, 'message' => self::OTHER_ERROR]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
@@ -176,6 +195,10 @@ class InstallController extends Controller
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
@@ -204,6 +227,11 @@ class InstallController extends Controller
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}

View File

@@ -221,6 +221,7 @@ class SingleController extends Controller
*/
public function delete(TransactionJournal $journal)
{
Log::debug(sprintf('Start of delete view for journal #%d', $journal->id));
// Covered by another controller's tests
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) {
@@ -232,6 +233,7 @@ class SingleController extends Controller
$subTitle = (string)trans('firefly.delete_' . $what, ['description' => $journal->description]);
// put previous url in session
Log::debug('Will try to remember previous URI');
$this->rememberPreviousUri('transactions.delete.uri');
return view('transactions.single.delete', compact('journal', 'subTitle', 'what'));

View File

@@ -184,7 +184,21 @@ class Kernel extends HttpKernel
'bindings',
],
];
/**
* The priority-sorted list of middleware.
*
* This forces non-global middleware to always be in the given order.
*
* @var array
*/
protected $middlewarePriority
= [
StartFireflySession::class,
ShareErrorsFromSession::class,
Authenticate::class,
Binder::class,
Authorize::class,
];
/**
* The application's route middleware.
*

View File

@@ -54,9 +54,11 @@ class Installer
*/
public function handle($request, Closure $next)
{
// ignore installer in test environment.
if ('testing' === config('app.env')) {
return $next($request);
}
// don't run installer when already in installer.
$url = $request->url();
$strpos = stripos($url, '/install');
if (!(false === $strpos)) {
@@ -64,37 +66,16 @@ class Installer
return $next($request);
}
// no tables present?
try {
DB::table('users')->count();
} catch (QueryException $e) {
$message = $e->getMessage();
Log::error('Access denied: ' . $message);
if ($this->isAccessDenied($message)) {
throw new FireflyException('It seems your database configuration is not correct. Please verify the username and password in your .env file.');
}
if ($this->noTablesExist($message)) {
// redirect to UpdateController
Log::warning('There are no Firefly III tables present. Redirect to migrate routine.');
return response()->redirectTo(route('installer.index'));
}
throw new FireflyException(sprintf('Could not access the database: %s', $message));
}
// older version in config than database?
$configVersion = (int)config('firefly.db_version');
$dbVersion = (int)app('fireflyconfig')->getFresh('db_version', 1)->data;
if ($configVersion > $dbVersion) {
Log::warning(
sprintf(
'The current installed version (%d) is older than the required version (%d). Redirect to migrate routine.', $dbVersion, $configVersion
)
);
// redirect to migrate routine:
// run installer when no tables are present,
// or when old scheme version
// or when old firefly version
if ($this->hasNoTables() || $this->oldDBVersion() || $this->oldVersion()) {
return response()->redirectTo(route('installer.index'));
}
// update scheme version
// update firefly version
return $next($request);
}
@@ -122,4 +103,85 @@ class Installer
{
return !(false === stripos($message, 'Base table or view not found'));
}
/**
* Check if the tables are created and accounted for.
*
* @return bool
* @throws FireflyException
*/
private function hasNoTables(): bool
{
Log::debug('Now in routine hasNoTables()');
try {
DB::table('users')->count();
} catch (QueryException $e) {
$message = $e->getMessage();
Log::error(sprintf('Error message trying to access users-table: %s', $message));
if ($this->isAccessDenied($message)) {
throw new FireflyException('It seems your database configuration is not correct. Please verify the username and password in your .env file.');
}
if ($this->noTablesExist($message)) {
// redirect to UpdateController
Log::warning('There are no Firefly III tables present. Redirect to migrate routine.');
return true;
}
throw new FireflyException(sprintf('Could not access the database: %s', $message));
}
Log::debug('Everything seems OK with the tables.');
return false;
}
/**
* Check if the "db_version" variable is correct.
*
* @return bool
*/
private function oldDBVersion(): bool
{
// older version in config than database?
$configVersion = (int)config('firefly.db_version');
$dbVersion = (int)app('fireflyconfig')->getFresh('db_version', 1)->data;
if ($configVersion > $dbVersion) {
Log::warning(
sprintf(
'The current configured version (%d) is older than the required version (%d). Redirect to migrate routine.', $dbVersion, $configVersion
)
);
return true;
}
Log::info(sprintf('Configured DB version (%d) equals expected DB version (%d)', $dbVersion, $configVersion));
return false;
}
/**
* Check if the "firefly_version" variable is correct.
*
* @return bool
*/
private function oldVersion(): bool
{
// version compare thing.
$configVersion = (string)config('firefly.version');
$dbVersion = (string)app('fireflyconfig')->getFresh('ff3_version', '1.0')->data;
if (1 === version_compare($configVersion, $dbVersion)) {
Log::warning(
sprintf(
'The current configured Firefly III version (%s) is older than the required version (%s). Redirect to migrate routine.', $dbVersion, $configVersion
)
);
return true;
}
Log::info(sprintf('Installed Firefly III version (%s) equals expected Firefly III version (%s)', $dbVersion, $configVersion));
return false;
}
}

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Http\Middleware;
use Illuminate\Http\Request;
use Illuminate\Session\Middleware\StartSession;
use Log;
/**
* Class StartFireflySession.
@@ -40,10 +41,18 @@ class StartFireflySession extends StartSession
*/
protected function storeCurrentUrl(Request $request, $session): void
{
$uri = $request->fullUrl();
$strpos = strpos($uri, 'jscript');
if (false === $strpos && 'GET' === $request->method() && !$request->ajax()) {
$uri = $request->fullUrl();
$isScriptPage = strpos($uri, 'jscript');
$isDeletePage = strpos($uri, 'delete');
// also stop remembering "delete" URL's.
if (false === $isScriptPage && false === $isDeletePage && 'GET' === $request->method() && !$request->ajax()) {
$session->setPreviousUrl($uri);
Log::debug(sprintf('Will set previous URL to %s', $uri));
return;
}
Log::debug(sprintf('Will NOT set previous URL to %s', $uri));
}
}

View File

@@ -575,21 +575,24 @@ class ImportArrayStorage
++$hits;
Log::debug(sprintf('Source IDs are the same! (%d)', $hits));
}
Log::debug('Source IDs are not the same.');
unset($transferSourceIDs);
// compare source and destination names
$transferSource = [(string)$transfer->account_name, (int)$transfer->opposing_account_name];
$transferSource = [(string)$transfer->account_name, (string)$transfer->opposing_account_name];
sort($transferSource);
/** @noinspection DisconnectedForeachInstructionInspection */
Log::debug('Comparing current transaction source+dest names', $currentSourceNames);
Log::debug('.. with current transfer source+dest names', $transferSource);
if ($currentSourceNames === $transferSource) {
// @codeCoverageIgnoreStart
Log::debug(sprintf('Source names are the same! (%d)', $hits));
++$hits;
Log::debug(sprintf('Source names are the same! (%d)', $hits));
// @codeCoverageIgnoreEnd
}
Log::debug('Source names are not the same.');
$totalHits += $hits;
Log::debug(sprintf('Total hits is now %d, hits is %d', $totalHits, $hits));
if ($totalHits >= $requiredHits) {
return true;
}

View File

@@ -242,6 +242,7 @@ class Amount
$currencyPreference = Prefs::getForUser($user, 'currencyPreference', config('firefly.default_currency', 'EUR'));
// at this point the currency preference could be encrypted, if coming from an old version.
Log::debug('Going to try to decrypt users currency preference.');
$currencyCode = $this->tryDecrypt((string)$currencyPreference->data);
// could still be json encoded:
@@ -288,7 +289,7 @@ class Amount
try {
$value = Crypt::decrypt($value);
} catch (DecryptException $e) {
Log::debug(sprintf('Could not decrypt. %s', $e->getMessage()));
Log::debug(sprintf('Could not decrypt "%s". %s', $value, $e->getMessage()));
}
return $value;

View File

@@ -50,6 +50,7 @@ trait UserNavigation
*/
protected function getPreviousUri(string $identifier): string
{
Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
// "forbidden" words for specific identifiers:
// if these are in the previous URI, don't refer back there.
$array = [
@@ -66,18 +67,25 @@ trait UserNavigation
'transactions.mass-delete.uri' => '/transactions/show/',
];
$forbidden = $array[$identifier] ?? '/show/';
Log::debug(sprintf('The forbidden word for %s is "%s"', $identifier, $forbidden));
$uri = (string)session($identifier);
Log::debug(sprintf('The URI is %s', $uri));
if (
!(false === strpos($identifier, 'delete'))
&& !(false === strpos($uri, $forbidden))) {
$uri = $this->redirectUri;
Log::debug(sprintf('URI is now %s (identifier contains "delete")', $uri));
}
if (!(false === strpos($uri, 'jscript'))) {
$uri = $this->redirectUri; // @codeCoverageIgnore
Log::debug(sprintf('URI is now %s (uri contains jscript)', $uri));
}
// more debug notes:
Log::debug(sprintf('strpos($identifier, "delete"): %s', var_export(strpos($identifier, 'delete'), true)));
Log::debug(sprintf('strpos($uri, $forbidden): %s', var_export(strpos($uri, $forbidden), true)));
return $uri;
}
@@ -147,6 +155,9 @@ trait UserNavigation
$url = app('url')->previous();
session()->put($identifier, $url);
Log::debug(sprintf('Will put previous URI in cache under key %s: %s', $identifier, $url));
return;
}
Log::debug(sprintf('The users session contains errors somehow so we will not remember the URI!: %s', var_export($errors, true)));
}
}