Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/atricle_tags' into featu…
Browse files Browse the repository at this point in the history
…re/atricle_tags
  • Loading branch information
Redjik committed Aug 21, 2015
2 parents eaf1c93 + 760c0cc commit 623cf4e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 45 deletions.
22 changes: 2 additions & 20 deletions api/app/Http/Controllers/ChildEntityController.php
Expand Up @@ -130,7 +130,7 @@ public function putOne(Request $request, $id, $childId)
$this->checkEntityIdMatchesRoute($request, $childId, $this->getChildModel());
$childModel = $this->findOrNewChildEntity($childId, $parent);

$this->validateRequest($request->all(), $this->addIdOverrideValidationRule($this->getValidationRules(), $childId));
$this->validateRequest($request->all(), $this->getValidationRules());

$childModel->fill($request->all());
$this->getRelation($parent)->save($childModel);
Expand Down Expand Up @@ -181,8 +181,7 @@ public function patchOne(Request $request, $id, $childId)
$this->checkEntityIdMatchesRoute($request, $childId, $this->getChildModel(), false);
$childModel = $this->findOrFailChildEntity($childId, $parent);

$validationRules = $this->addIdOverrideValidationRule($this->getValidationRules(), $childId);
$this->validateRequest($request->all(), $validationRules, true);
$this->validateRequest($request->all(), $this->getValidationRules(), true);

$childModel->fill($request->all());
$this->getRelation($parent)->save($childModel);
Expand Down Expand Up @@ -372,21 +371,4 @@ protected function getValidationRules()
{
return $this->getChildModel()->getValidationRules();
}

/**
* @param $validationRules
* @param $id
* @return mixed
*/
protected function addIdOverrideValidationRule($validationRules, $id)
{
$rule = 'equals:'.$id;
$keyName = $this->getChildModel()->getKeyName();
if (isset($validationRules[$keyName])) {
$rule='|'.$rule;
}

$validationRules[$keyName].= $rule;
return $validationRules;
}
}
23 changes: 2 additions & 21 deletions api/app/Http/Controllers/EntityController.php
Expand Up @@ -113,8 +113,7 @@ public function putOne(Request $request, $id)

$model = $this->findOrNewEntity($id);

$validationRules = $this->addIdOverrideValidationRule($this->getValidationRules(), $id);
$this->validateRequest($request->all(), $validationRules);
$this->validateRequest($request->all(), $this->getValidationRules());

$model->fill($request->all())
->save();
Expand Down Expand Up @@ -161,8 +160,7 @@ public function patchOne(Request $request, $id)

$model = $this->findOrFailEntity($id);

$validationRules = $this->addIdOverrideValidationRule($this->getValidationRules(), $id);
$this->validateRequest($request->all(), $validationRules, true);
$this->validateRequest($request->all(), $this->getValidationRules(), true);

$model->fill($request->all());
$model->save();
Expand Down Expand Up @@ -316,21 +314,4 @@ protected function getValidationRules()
{
return $this->getModel()->getValidationRules();
}

/**
* @param $validationRules
* @param $id
* @return mixed
*/
protected function addIdOverrideValidationRule($validationRules, $id)
{
$rule = 'equals:'.$id;
$keyName = $this->getModel()->getKeyName();
if (isset($validationRules[$keyName])) {
$rule='|'.$rule;
}

$validationRules[$keyName].= $rule;
return $validationRules;
}
}
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/UserController.php
Expand Up @@ -158,8 +158,8 @@ public function patchOne(Request $request, $id)
$model->email = $email;
}
}
$validationRules = $this->addIdOverrideValidationRule($this->getValidationRules(), $id);
$this->validateRequest($request->except('email'), $validationRules, true);
$this->checkEntityIdMatchesRoute($request, $id, $this->getModel(), false);
$this->validateRequest($request->except('email'), $this->getValidationRules(), true);
$model->fill($request->except('email'));
$model->save();

Expand Down
1 change: 0 additions & 1 deletion api/resources/lang/en/validation.php
Expand Up @@ -75,7 +75,6 @@
"timezone" => "The :attribute must be a valid zone.",
'uuid' => "The :attribute must be an UUID string.",
'float' => "The :attribute must be a float.",
'equals' => "The :attribute can not be changed.",
'not_found' => "The selected :attribute is invalid.",
'country' => 'The :attribute must be a valid country code.',
'alpha_dash_space' => 'The :attribute may only contain letters, numbers, dashes and spaces.',
Expand Down
2 changes: 1 addition & 1 deletion api/tests/integration/UserTest.php
Expand Up @@ -381,7 +381,7 @@ public function testPatchOneBySelfUserUUID()
'HTTP_AUTHORIZATION' => 'Bearer '.$token
]);

$this->assertResponseStatus(422);
$this->assertResponseStatus(400);
}

public function testDeleteOneByAdminUser()
Expand Down

0 comments on commit 623cf4e

Please sign in to comment.