Skip to content

Commit 7f1f4da

Browse files
committed
Deprecated value instead of removing it
1 parent f36fef9 commit 7f1f4da

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- User cache not flushed on model save ([#1050])
2424
- Fix "the passwords don't match" error when editing a user password ([#1034], [#1038])
2525

26+
### Deprecated
27+
`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).
28+
2629
## [v4.3.1]
2730

2831
### Changed

app/sprinkles/admin/src/Controller/UserController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,13 +1323,19 @@ public function updateField(Request $request, Response $response, array $args)
13231323
// Get PUT parameters: value
13241324
$put = $request->getParsedBody();
13251325

1326-
if (!isset($put[$fieldName])) {
1326+
// Make sure data is part of $_PUT data
1327+
if (isset($put[$fieldName])) {
1328+
$fieldData = $put[$fieldName];
1329+
} elseif (isset($put['value'])) {
1330+
/** @deprecated - Fieldname should be used instead of `value` */
1331+
$fieldData = $put['value'];
1332+
} else {
13271333
throw new BadRequestException();
13281334
}
13291335

13301336
// Create and validate key -> value pair
13311337
$params = [
1332-
$fieldName => $put[$fieldName],
1338+
$fieldName => $fieldData,
13331339
];
13341340

13351341
// Load the request schema

app/sprinkles/admin/tests/Integration/Controller/UserControllerTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,41 @@ public function testUpdateField(UserController $controller)
819819
$this->assertSame('success', end($messages)['type']);
820820
}
821821

822+
/**
823+
* @depends testControllerConstructorWithUser
824+
* @depends testUpdateField
825+
* @param UserController $controller
826+
*/
827+
public function testUpdateFieldWithDeprecatedSupport(UserController $controller)
828+
{
829+
// Create a user
830+
$user = $this->createTestUser();
831+
832+
// Set post data
833+
$data = [
834+
'value' => 'deprecated', //<-- Use old `value`
835+
];
836+
$request = $this->getRequest()->withParsedBody($data);
837+
838+
// Get controller stuff
839+
$result = $controller->updateField($request, $this->getResponse(), ['user_name' => $user->user_name, 'field' => 'first_name']);
840+
$this->assertSame($result->getStatusCode(), 200);
841+
$this->assertJson((string) $result->getBody());
842+
$this->assertSame('[]', (string) $result->getBody());
843+
844+
// Make sure user was update
845+
$editedUser = User::where('user_name', $user->user_name)->first();
846+
$this->assertSame('deprecated', $editedUser->first_name);
847+
$this->assertNotSame($user->first_name, $editedUser->first_name);
848+
$this->assertSame($user->last_name, $editedUser->last_name);
849+
850+
// Test message
851+
/** @var \UserFrosting\Sprinkle\Core\Alert\AlertStream $ms */
852+
$ms = $this->ci->alerts;
853+
$messages = $ms->getAndClearMessages();
854+
$this->assertSame('success', end($messages)['type']);
855+
}
856+
822857
/**
823858
* @depends testControllerConstructorWithUser
824859
* @depends testUpdateField

0 commit comments

Comments
 (0)