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

View File

@ -23,6 +23,7 @@ return [
"unique_for_user" => "There already is an entry with this :attribute.",
"before" => "The :attribute must be a date before :date.",
'unique_object_for_user' => 'This name is already in use',
'unique_account_for_user' => 'This account name is already in use',
"between" => [
"numeric" => "The :attribute must be between :min and :max.",
"file" => "The :attribute must be between :min and :max kilobytes.",

View File

@ -23,6 +23,7 @@ return [
"unique_for_user" => "There already is an entry with this :attribute.",
"before" => "The :attribute must be a date before :date.",
'unique_object_for_user' => 'Deze naam is al in gebruik',
'unique_account_for_user' => 'This rekeningnaam is already in use',
"between" => [
"numeric" => "The :attribute must be between :min and :max.",
"file" => "The :attribute must be between :min and :max kilobytes.",