Fixed the bug that would unintentionally not let you edit accounts without changing their name. Closed #83

This commit is contained in:
James Cole
2015-06-28 21:13:08 +02:00
parent 0258982e60
commit e70444f19a
3 changed files with 77 additions and 44 deletions

View File

@@ -75,6 +75,10 @@ class FireflyValidator extends Validator
if (isset($this->data['account_type_id'])) {
return $this->validateByAccountTypeId($value, $parameters);
}
if(isset($this->data['id'])) {
return $this->validateByAccountId($value, $parameters);
}
return false;
}
@@ -167,6 +171,33 @@ class FireflyValidator extends Validator
}
/**
* @param $value
* @param $parameters
*
* @return bool
*/
protected function validateByAccountId($value, $parameters)
{
/** @var Account $existingAccount */
$existingAccount = Account::find($this->data['id']);
$type = $existingAccount->accountType;
$ignore = $existingAccount->id;
$value = $this->tryDecrypt($value);
$set = Auth::user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get();
/** @var Account $entry */
foreach ($set as $entry) {
if ($entry->name == $value) {
return false;
}
}
return true;
}
/**
* @param $attribute
* @param $value