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'])) { if (isset($this->data['account_type_id'])) {
return $this->validateByAccountTypeId($value, $parameters); return $this->validateByAccountTypeId($value, $parameters);
} }
if(isset($this->data['id'])) {
return $this->validateByAccountId($value, $parameters);
}
return false; 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 $attribute
* @param $value * @param $value

View File

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

View File

@@ -13,68 +13,69 @@ return [
| |
*/ */
"accepted" => "The :attribute must be accepted.", "accepted" => "The :attribute must be accepted.",
"active_url" => "The :attribute is not a valid URL.", "active_url" => "The :attribute is not a valid URL.",
"after" => "The :attribute must be a date after :date.", "after" => "The :attribute must be a date after :date.",
"alpha" => "The :attribute may only contain letters.", "alpha" => "The :attribute may only contain letters.",
"alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.", "alpha_dash" => "The :attribute may only contain letters, numbers, and dashes.",
"alpha_num" => "The :attribute may only contain letters and numbers.", "alpha_num" => "The :attribute may only contain letters and numbers.",
"array" => "The :attribute must be an array.", "array" => "The :attribute must be an array.",
"unique_for_user" => "There already is an entry with this :attribute.", "unique_for_user" => "There already is an entry with this :attribute.",
"before" => "The :attribute must be a date before :date.", "before" => "The :attribute must be a date before :date.",
'unique_object_for_user' => 'Deze naam is al in gebruik', 'unique_object_for_user' => 'Deze naam is al in gebruik',
"between" => [ 'unique_account_for_user' => 'This rekeningnaam is already in use',
"between" => [
"numeric" => "The :attribute must be between :min and :max.", "numeric" => "The :attribute must be between :min and :max.",
"file" => "The :attribute must be between :min and :max kilobytes.", "file" => "The :attribute must be between :min and :max kilobytes.",
"string" => "The :attribute must be between :min and :max characters.", "string" => "The :attribute must be between :min and :max characters.",
"array" => "The :attribute must have between :min and :max items.", "array" => "The :attribute must have between :min and :max items.",
], ],
"boolean" => "The :attribute field must be true or false.", "boolean" => "The :attribute field must be true or false.",
"confirmed" => "The :attribute confirmation does not match.", "confirmed" => "The :attribute confirmation does not match.",
"date" => "The :attribute is not a valid date.", "date" => "The :attribute is not a valid date.",
"date_format" => "The :attribute does not match the format :format.", "date_format" => "The :attribute does not match the format :format.",
"different" => "The :attribute and :other must be different.", "different" => "The :attribute and :other must be different.",
"digits" => "The :attribute must be :digits digits.", "digits" => "The :attribute must be :digits digits.",
"digits_between" => "The :attribute must be between :min and :max digits.", "digits_between" => "The :attribute must be between :min and :max digits.",
"email" => "The :attribute must be a valid email address.", "email" => "The :attribute must be a valid email address.",
"filled" => "The :attribute field is required.", "filled" => "The :attribute field is required.",
"exists" => "The selected :attribute is invalid.", "exists" => "The selected :attribute is invalid.",
"image" => "The :attribute must be an image.", "image" => "The :attribute must be an image.",
"in" => "The selected :attribute is invalid.", "in" => "The selected :attribute is invalid.",
"integer" => "The :attribute must be an integer.", "integer" => "The :attribute must be an integer.",
"ip" => "The :attribute must be a valid IP address.", "ip" => "The :attribute must be a valid IP address.",
"max" => [ "max" => [
"numeric" => "The :attribute may not be greater than :max.", "numeric" => "The :attribute may not be greater than :max.",
"file" => "The :attribute may not be greater than :max kilobytes.", "file" => "The :attribute may not be greater than :max kilobytes.",
"string" => "The :attribute may not be greater than :max characters.", "string" => "The :attribute may not be greater than :max characters.",
"array" => "The :attribute may not have more than :max items.", "array" => "The :attribute may not have more than :max items.",
], ],
"mimes" => "The :attribute must be a file of type: :values.", "mimes" => "The :attribute must be a file of type: :values.",
"min" => [ "min" => [
"numeric" => "The :attribute must be at least :min.", "numeric" => "The :attribute must be at least :min.",
"file" => "The :attribute must be at least :min kilobytes.", "file" => "The :attribute must be at least :min kilobytes.",
"string" => "The :attribute must be at least :min characters.", "string" => "The :attribute must be at least :min characters.",
"array" => "The :attribute must have at least :min items.", "array" => "The :attribute must have at least :min items.",
], ],
"not_in" => "The selected :attribute is invalid.", "not_in" => "The selected :attribute is invalid.",
"numeric" => "The :attribute must be a number.", "numeric" => "The :attribute must be a number.",
"regex" => "The :attribute format is invalid.", "regex" => "The :attribute format is invalid.",
"required" => "The :attribute field is required.", "required" => "The :attribute field is required.",
"required_if" => "The :attribute field is required when :other is :value.", "required_if" => "The :attribute field is required when :other is :value.",
"required_with" => "The :attribute field is required when :values is present.", "required_with" => "The :attribute field is required when :values is present.",
"required_with_all" => "The :attribute field is required when :values is present.", "required_with_all" => "The :attribute field is required when :values is present.",
"required_without" => "The :attribute field is required when :values is not present.", "required_without" => "The :attribute field is required when :values is not present.",
"required_without_all" => "The :attribute field is required when none of :values are present.", "required_without_all" => "The :attribute field is required when none of :values are present.",
"same" => "The :attribute and :other must match.", "same" => "The :attribute and :other must match.",
"size" => [ "size" => [
"numeric" => "The :attribute must be :size.", "numeric" => "The :attribute must be :size.",
"file" => "The :attribute must be :size kilobytes.", "file" => "The :attribute must be :size kilobytes.",
"string" => "The :attribute must be :size characters.", "string" => "The :attribute must be :size characters.",
"array" => "The :attribute must contain :size items.", "array" => "The :attribute must contain :size items.",
], ],
"unique" => "The :attribute has already been taken.", "unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.", "url" => "The :attribute format is invalid.",
"timezone" => "The :attribute must be a valid zone.", "timezone" => "The :attribute must be a valid zone.",
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@@ -87,7 +88,7 @@ return [
| |
*/ */
'custom' => [ 'custom' => [
'attribute-name' => [ 'attribute-name' => [
'rule-name' => 'custom-message', 'rule-name' => 'custom-message',
], ],
@@ -104,6 +105,6 @@ return [
| |
*/ */
'attributes' => [], 'attributes' => [],
]; ];