Skip to content

Commit

Permalink
Merge branch '5.2' into 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Nov 30, 2024
2 parents a6d722a + 56f92df commit 7456de9
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 307 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - Memory SQLite
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - MySQL
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - MariaDB
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - SQLite
Expand Down Expand Up @@ -251,7 +251,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - PostgreSQL
Expand Down Expand Up @@ -311,7 +311,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: windows-latest
name: PHPUnit - PHP ${{ matrix.php_versions }} - Windows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/PHPStan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_versions: ['8.1', '8.2', '8.3']
php_versions: ['8.1', '8.2', '8.3', '8.4']

runs-on: ubuntu-latest
name: PHPStan - ${{ matrix.php_versions }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [5.2.0](https://github.com/userfrosting/sprinkle-admin/compare/5.1.0...5.2.0)

## [5.1.3](https://github.com/userfrosting/sprinkle-admin/compare/5.1.2...5.1.3)
- [Fix] Locale is not displayed on the user page

## [5.1.2](https://github.com/userfrosting/sprinkle-admin/compare/5.1.1...5.1.2)
- Fix Unable to create a user without a group on MySQL (Fix [#1273](https://github.com/userfrosting/UserFrosting/issues/1273))

## [5.1.1](https://github.com/userfrosting/sprinkle-admin/compare/5.1.0...5.1.1)
- Fix issue when a Group Administrator without the `create_user_field` permission creates a new user, the new user SHOULD inherit the admin's group (Fix [#1256](https://github.com/userfrosting/UserFrosting/issues/1256))

Expand Down
2 changes: 2 additions & 0 deletions app/src/Controller/User/UserApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ protected function validateAccess(UserInterface $user): void
$locales = $this->siteLocale->getAvailableIdentifiers();
if (count($locales) <= 1) {
$fields['hidden'][] = 'locale';
} else {
$fields['locale_name'] = (new Locale($user->locale))->getRegionalName();
}
// Determine buttons to display
Expand Down
5 changes: 5 additions & 0 deletions app/src/Controller/User/UserCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ protected function handle(Request $request): void
$data['group_id'] = $currentUser->group_id;
}

// If group id is zero, then it's no group
if ($data['group_id'] === 0) {
$data['group_id'] = null;
}

// Now that we check the form, we can try to register the actual user
$user = new $this->userModel($data);

Expand Down
25 changes: 25 additions & 0 deletions app/tests/Controller/User/UserApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,29 @@ public function testPage(): void
'group',
], $response);
}

public function testPageWithMultipleLocales(): void
{
/** @var User */
$user = User::factory()->create();
$this->actAsUser($user, permissions: ['uri_user']);

/** @var Config */
$config = $this->ci->get(Config::class);

// Force locale config.
$config->set('site.registration.user_defaults.locale', 'en_US');
$config->set('site.locales.available', [
'en_US' => true,
'fr_FR' => true,
]);

// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/users/u/' . $user->user_name);
$response = $this->handleRequest($request);

// Assert response status & body
$this->assertResponseStatus(200, $response);
$this->assertNotEmpty((string) $response->getBody());
}
}
51 changes: 51 additions & 0 deletions app/tests/Controller/User/UserCreateActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,57 @@ public function testPostForGroupIsSetAs(): void
$this->assertSame('success', array_reverse($messages)[0]['type']);
}

public function testPostForNoGroup(): void
{
/** @var User */
$user = User::factory()->create();
$this->actAsUser($user, isMaster: true);

/** @var Config */
$config = $this->ci->get(Config::class);

// Force locale config.
$config->set('site.registration.user_defaults.locale', 'en_US');
$config->set('site.locales.available', ['en_US' => true]);

/** @var Mailer */
$mailer = Mockery::mock(Mailer::class)
->makePartial()
->shouldReceive('send')->once()
->getMock();
$this->ci->set(Mailer::class, $mailer);

// Set post payload
$data = [
'user_name' => 'foo',
'first_name' => 'Foo',
'last_name' => 'Bar',
'email' => '[email protected]',
'locale' => 'en_US',
'group_id' => 0,
];

// Create request with method and url and fetch response
$request = $this->createJsonRequest('POST', '/api/users', $data);
$response = $this->handleRequest($request);

// Assert response status & body
$this->assertJsonResponse([], $response);
$this->assertResponseStatus(200, $response);

// Make sure the user is added to the db by querying it
/** @var User */
$user = User::where('email', '[email protected]')->first();
$this->assertSame('foo', $user['user_name']);
$this->assertSame('en_US', $user['locale']);

// Test message
/** @var AlertStream */
$ms = $this->ci->get(AlertStream::class);
$messages = $ms->getAndClearMessages();
$this->assertSame('success', array_reverse($messages)[0]['type']);
}

/**
* @depends testPost
*/
Expand Down
Loading

0 comments on commit 7456de9

Please sign in to comment.