Skip to content

Commit

Permalink
Deprecated value instead of removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Nov 20, 2019
1 parent f36fef9 commit 7f1f4da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- User cache not flushed on model save ([#1050])
- Fix "the passwords don't match" error when editing a user password ([#1034], [#1038])

### Deprecated
`UserController:updateField` now expect the new value as `$_PUT[$fieldName]` (where `$fieldName` is the name of the field you want to update, eg. `$_PUT['password']` for editing `password`) instead of `$_PUT['value']`. This will only affect your code if you're **not** using the [user widjet](https://github.com/userfrosting/UserFrosting/blob/master/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js).

## [v4.3.1]

### Changed
Expand Down
10 changes: 8 additions & 2 deletions app/sprinkles/admin/src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,13 +1323,19 @@ public function updateField(Request $request, Response $response, array $args)
// Get PUT parameters: value
$put = $request->getParsedBody();

if (!isset($put[$fieldName])) {
// Make sure data is part of $_PUT data
if (isset($put[$fieldName])) {
$fieldData = $put[$fieldName];
} elseif (isset($put['value'])) {
/** @deprecated - Fieldname should be used instead of `value` */
$fieldData = $put['value'];
} else {
throw new BadRequestException();
}

// Create and validate key -> value pair
$params = [
$fieldName => $put[$fieldName],
$fieldName => $fieldData,
];

// Load the request schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,41 @@ public function testUpdateField(UserController $controller)
$this->assertSame('success', end($messages)['type']);
}

/**
* @depends testControllerConstructorWithUser
* @depends testUpdateField
* @param UserController $controller
*/
public function testUpdateFieldWithDeprecatedSupport(UserController $controller)
{
// Create a user
$user = $this->createTestUser();

// Set post data
$data = [
'value' => 'deprecated', //<-- Use old `value`
];
$request = $this->getRequest()->withParsedBody($data);

// Get controller stuff
$result = $controller->updateField($request, $this->getResponse(), ['user_name' => $user->user_name, 'field' => 'first_name']);
$this->assertSame($result->getStatusCode(), 200);
$this->assertJson((string) $result->getBody());
$this->assertSame('[]', (string) $result->getBody());

// Make sure user was update
$editedUser = User::where('user_name', $user->user_name)->first();
$this->assertSame('deprecated', $editedUser->first_name);
$this->assertNotSame($user->first_name, $editedUser->first_name);
$this->assertSame($user->last_name, $editedUser->last_name);

// Test message
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
$ms = $this->ci->alerts;
$messages = $ms->getAndClearMessages();
$this->assertSame('success', end($messages)['type']);
}

/**
* @depends testControllerConstructorWithUser
* @depends testUpdateField
Expand Down

0 comments on commit 7f1f4da

Please sign in to comment.