Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New stuff for encrypted amounts.
James Cole1c2cbd5b40fe
diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.phpindex 0dcaddb3f7..990f6aef30 100644--- a/app/Helpers/Report/ReportQuery.php+++ b/app/Helpers/Report/ReportQuery.php@@ -74,9 +74,7 @@ class ReportQuery implements ReportQueryInterfaceif ($journal->amount != 0) {return $journal;}- // @codeCoverageIgnoreStart- }- // @codeCoverageIgnoreEnd+ } // @codeCoverageIgnore);return $data;@@ -193,9 +191,7 @@ class ReportQuery implements ReportQueryInterfaceif ($journal->amount != 0) {return $journal;}- // @codeCoverageIgnoreStart- }- // @codeCoverageIgnoreEnd+ } // @codeCoverageIgnore);return $data;diff --git a/app/Http/Middleware/Cleanup.php b/app/Http/Middleware/Cleanup.phpindex c7e0f01d52..d818e8eac8 100644--- a/app/Http/Middleware/Cleanup.php+++ b/app/Http/Middleware/Cleanup.php@@ -149,15 +149,12 @@ class Cleanupunset($set, $entry, $metadata);//encrypt budget limit amount-//encrypt limit repetition amount//encrypt piggy bank event amount//encrypt piggy bank repetition currentamount//encrypt piggy bank targetamount-//encrypt preference name (add field)//encrypt preference data (add field)-//encrypt transaction amount}if ($count == 0 && $run) {diff --git a/app/Models/Account.php b/app/Models/Account.phpindex d9733d77fd..0688607cd3 100644--- a/app/Models/Account.php+++ b/app/Models/Account.php@@ -150,6 +150,23 @@ class Account extends Model// @codeCoverageIgnoreEnd}++ /**+ * @param $value+ *+ * @return float|int+ */+ public function getVirtualBalanceAttribute($value)+ {+ if (is_null($this->virtual_balance_encrypted)) {+ return $value;+ }+ $value = intval(Crypt::decrypt($this->virtual_balance_encrypted));+ $value = $value / 100;++ return $value;+ }+/*** @codeCoverageIgnore* @return \Illuminate\Database\Eloquent\Relations\HasMany@@ -203,6 +220,17 @@ class Account extends Model$this->attributes['encrypted'] = true;}+ /**+ * @param $value+ */+ public function setVirtualBalanceAttribute($value)+ {+ // save in cents:+ $value = intval($value * 100);+ $this->attributes['virtual_balance_encrypted'] = Crypt::encrypt($value);+ $this->attributes['virtual_balance'] = 0;+ }+/*** @codeCoverageIgnore* @return \Illuminate\Database\Eloquent\Relations\HasManydiff --git a/app/Models/Bill.php b/app/Models/Bill.phpindex d181e616c3..8d7d65f274 100644--- a/app/Models/Bill.php+++ b/app/Models/Bill.php@@ -14,6 +14,38 @@ class Bill extends Modelprotected $fillable= ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',];+ /**+ * @param $value+ *+ * @return float|int+ */+ public function getAmountMaxAttribute($value)+ {+ if (is_null($this->amount_max_encrypted)) {+ return $value;+ }+ $value = intval(Crypt::decrypt($this->amount_max_encrypted));+ $value = $value / 100;++ return $value;+ }++ /**+ * @param $value+ *+ * @return float|int+ */+ public function getAmountMinAttribute($value)+ {+ if (is_null($this->amount_min_encrypted)) {+ return $value;+ }+ $value = intval(Crypt::decrypt($this->amount_min_encrypted));+ $value = $value / 100;++ return $value;+ }+/*** @return array*/@@ -56,6 +88,28 @@ class Bill extends Model// @codeCoverageIgnoreEnd}+ /**+ * @param $value+ */+ public function setAmountMaxAttribute($value)+ {+ // save in cents:+ $value = intval($value * 100);+ $this->attributes['amount_max_encrypted'] = Crypt::encrypt($value);+ $this->attributes['amount_max'] = 0;+ }++ /**+ * @param $value+ */+ public function setAmountMinAttribute($value)+ {+ // save in cents:+ $value = intval($value * 100);+ $this->attributes['amount_min_encrypted'] = Crypt::encrypt($value);+ $this->attributes['amount_min'] = 0;+ }+/*** @param $value*/diff --git a/database/migrations/2015_05_22_172026_changes_for_v3409.php b/database/migrations/2015_05_22_172026_changes_for_v3409.phpnew file mode 100644index 0000000000..462b6d5af0--- /dev/null+++ b/database/migrations/2015_05_22_172026_changes_for_v3409.php@@ -0,0 +1,148 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;++/**+ * @SuppressWarnings(PHPMD.ShortMethodName)+ *+ * Class ChangesForV3409+ */+class ChangesForV3409 extends Migration+{++ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ // remove decryption, but this will destroy amounts.++ Schema::table(+ 'accounts', function (Blueprint $table) {+ $table->dropColumn('virtual_balance_encrypted');+ }+ );++ Schema::table(+ 'bills', function (Blueprint $table) {+ $table->dropColumn('amount_min_encrypted');+ $table->dropColumn('amount_max_encrypted');+ }+ );++ Schema::table(+ 'budget_limits', function (Blueprint $table) {++ $table->dropColumn('amount_encrypted');+ }+ );+ Schema::table(+ 'limit_repetitions', function (Blueprint $table) {+ $table->dropColumn('amount_encrypted');+ }+ );+ Schema::table(+ 'piggy_bank_events', function (Blueprint $table) {+ $table->dropColumn('amount_encrypted');+ }+ );+ Schema::table(+ 'piggy_bank_repetitions', function (Blueprint $table) {+ $table->dropColumn('currentamount_encrypted');+ }+ );++ Schema::table(+ 'piggy_banks', function (Blueprint $table) {+ $table->dropColumn('targetamount_encrypted');+ }+ );+ Schema::table(+ 'preferences', function (Blueprint $table) {+ $table->dropColumn('name_encrypted');+ $table->dropColumn('data_encrypted');+ }+ );++ Schema::table(+ 'transactions', function (Blueprint $table) {+ $table->dropColumn('amount_encrypted');+ }+ );+ }++ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up()+ {+ // encrypt account virtual balance:+ Schema::table(+ 'accounts', function (Blueprint $table) {+ $table->string('virtual_balance_encrypted')->nullable()->after('virtual_balance');+ }+ );++ // encrypt bill amount_min and amount_max:+ Schema::table(+ 'bills', function (Blueprint $table) {+ $table->string('amount_min_encrypted')->nullable()->after('amount_min');+ $table->string('amount_max_encrypted')->nullable()->after('amount_max');+ }+ );++ // encrypt budget limit amount+ Schema::table(+ 'budget_limits', function (Blueprint $table) {+ $table->string('amount_encrypted')->nullable()->after('amount');+ }+ );+ // encrypt limit repetition amount+ Schema::table(+ 'limit_repetitions', function (Blueprint $table) {+ $table->string('amount_encrypted')->nullable()->after('amount');+ }+ );+ // encrypt piggy bank event amount+ Schema::table(+ 'piggy_bank_events', function (Blueprint $table) {+ $table->string('amount_encrypted')->nullable()->after('amount');+ }+ );+ // encrypt piggy bank repetition currentamount+ Schema::table(+ 'piggy_bank_repetitions', function (Blueprint $table) {+ $table->string('currentamount_encrypted')->nullable()->after('currentamount');+ }+ );++ // encrypt piggy bank targetamount+ Schema::table(+ 'piggy_banks', function (Blueprint $table) {+ $table->string('targetamount_encrypted')->nullable()->after('targetamount');+ }+ );+ // encrypt preference name (add field)+ // encrypt preference data (add field)+ Schema::table(+ 'preferences', function (Blueprint $table) {+ $table->smallInteger('name_encrypted', false, true)->default(0)->after('name');+ $table->smallInteger('data_encrypted', false, true)->default(0)->after('data');+ }+ );++ // encrypt transaction amount+ Schema::table(+ 'transactions', function (Blueprint $table) {+ $table->string('amount_encrypted')->nullable()->after('amount');+ }+ );++ }++}diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.phpindex beb5a03eef..c729c8c2da 100644--- a/database/seeds/TestDataSeeder.php+++ b/database/seeds/TestDataSeeder.php@@ -134,7 +134,9 @@ class TestDataSeeder extends Seeder$acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);$acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);- $acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1]);+ $acc_c = Account::create(+ ['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1, 'virtual_balance' => 123.45]+ );// create account meta:AccountMeta::create(['account_id' => $acc_a->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);@@ -514,27 +516,6 @@ class TestDataSeeder extends Seederreturn null;}- /**- * @param $name- *- * @return PiggyBank|null- */- protected function findPiggyBank($name)- {- // account- $user = User::whereEmail('[email protected]')->first();- /** @var Budget $budget */- foreach (PiggyBank::get() as $piggyBank) {- $account = $piggyBank->account()->first();- if ($piggyBank->name == $name && $user->id == $account->user_id) {- return $piggyBank;- break;- }- }-- return null;- }-/*** @param $name*@@ -680,5 +661,26 @@ class TestDataSeeder extends Seeder);}+ /**+ * @param $name+ *+ * @return PiggyBank|null+ */+ protected function findPiggyBank($name)+ {+ // account+ $user = User::whereEmail('[email protected]')->first();+ /** @var Budget $budget */+ foreach (PiggyBank::get() as $piggyBank) {+ $account = $piggyBank->account()->first();+ if ($piggyBank->name == $name && $user->id == $account->user_id) {+ return $piggyBank;+ break;+ }+ }++ return null;+ }+}diff --git a/tests/helpers/ReportQueryTest.php b/tests/helpers/ReportQueryTest.phpdeleted file mode 100644index d4a769b922..0000000000--- a/tests/helpers/ReportQueryTest.php+++ /dev/null@@ -1,100 +0,0 @@-<?php--use FireflyIII\Helpers\Report\ReportQuery;-use FireflyIII\Models\AccountMeta;-use FireflyIII\Models\PiggyBankRepetition;-use FireflyIII\Models\Transaction;-use League\FactoryMuffin\Facade as FactoryMuffin;--/**- * @SuppressWarnings(PHPMD.TooManyMethods)- * Class ReportQueryTest- */-class ReportQueryTest extends TestCase-{- /**- * @var ReportQuery- */- protected $object;-- /**- * Sets up the fixture, for example, opens a network connection.- * This method is called before a test is executed.- */- public function setUp()- {- parent::setUp();- FactoryMuffin::create('FireflyIII\User');- $this->object = new ReportQuery;- }-- /**- * Tears down the fixture, for example, closes a network connection.- * This method is called after a test is executed.- */- public function tearDown()- {- parent::tearDown();- }-- public function testBalancedTransactionsList()- {- $this->markTestIncomplete();- }-- public function testBalancedTransactionsSum()- {- $this->markTestIncomplete();- }-- public function testGetAllAccounts()- {- $this->markTestIncomplete();- }-- public function testGetBudgetSummary()- {- $this->markTestIncomplete();- }-- public function testGetTransactionsWithoutBudget()- {- $this->markTestIncomplete();- }-- public function testIncomeInPeriod()- {- $this->markTestIncomplete();- }-- public function testJournalsByBudget()- {- $this->markTestIncomplete();- }-- public function testJournalsByCategory()- {- $this->markTestIncomplete();- }-- public function testJournalsByExpenseAccount()- {- $this->markTestIncomplete();- }-- public function testJournalsByRevenueAccount()- {- $this->markTestIncomplete();- }-- public function testSharedExpenses()- {- $this->markTestIncomplete();- }-- public function testSharedExpensesByCategory()- {- $this->markTestIncomplete();- }--}