New stuff for encrypted amounts.

This commit is contained in:
James Cole 2015-05-23 07:47:36 +02:00
parent 54c6ca9f45
commit 1c2cbd5b40
7 changed files with 256 additions and 131 deletions

View File

@ -74,9 +74,7 @@ class ReportQuery implements ReportQueryInterface
if ($journal->amount != 0) {
return $journal;
}
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
} // @codeCoverageIgnore
);
return $data;
@ -193,9 +191,7 @@ class ReportQuery implements ReportQueryInterface
if ($journal->amount != 0) {
return $journal;
}
// @codeCoverageIgnoreStart
}
// @codeCoverageIgnoreEnd
} // @codeCoverageIgnore
);
return $data;

View File

@ -149,15 +149,12 @@ class Cleanup
unset($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) {

View File

@ -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\HasMany

View File

@ -14,6 +14,38 @@ class Bill extends Model
protected $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
*/

View File

@ -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');
}
);
}
}

View File

@ -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 Seeder
return null;
}
/**
* @param $name
*
* @return PiggyBank|null
*/
protected function findPiggyBank($name)
{
// account
$user = User::whereEmail('thegrumpydictator@gmail.com')->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('thegrumpydictator@gmail.com')->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;
}
}

View File

@ -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();
}
}