From 43ef82bd50fc1c840a39ba78622a6403cf019dda Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 4 Oct 2024 20:02:29 -0400 Subject: [PATCH 1/4] Fix https://github.com/userfrosting/UserFrosting/issues/1273 --- CHANGELOG.md | 3 ++ app/src/Controller/User/UserCreateAction.php | 5 ++ .../Controller/User/UserCreateActionTest.php | 51 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 617c2cb..987413b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [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)) diff --git a/app/src/Controller/User/UserCreateAction.php b/app/src/Controller/User/UserCreateAction.php index 4cd7939..c77ac2b 100644 --- a/app/src/Controller/User/UserCreateAction.php +++ b/app/src/Controller/User/UserCreateAction.php @@ -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); diff --git a/app/tests/Controller/User/UserCreateActionTest.php b/app/tests/Controller/User/UserCreateActionTest.php index fbe8958..a5e8231 100644 --- a/app/tests/Controller/User/UserCreateActionTest.php +++ b/app/tests/Controller/User/UserCreateActionTest.php @@ -358,6 +358,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' => 'foo@bar.com', + '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', 'foo@bar.com')->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 */ From 7ece95e452989ffb129c651459752de47079a6e5 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 18 Oct 2024 22:48:17 -0400 Subject: [PATCH 2/4] Fix locale is not displayed --- CHANGELOG.md | 3 +++ app/src/Controller/User/UserPageAction.php | 3 +++ app/templates/pages/user.html.twig | 2 +- .../Controller/User/UserPageActionTest.php | 25 +++++++++++++++++++ package.json | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 987413b..56c76fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [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)) diff --git a/app/src/Controller/User/UserPageAction.php b/app/src/Controller/User/UserPageAction.php index 273356c..65ca023 100644 --- a/app/src/Controller/User/UserPageAction.php +++ b/app/src/Controller/User/UserPageAction.php @@ -15,6 +15,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; +use UserFrosting\I18n\Locale; use UserFrosting\Sprinkle\Account\Authenticate\Authenticator; use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; use UserFrosting\Sprinkle\Account\Exceptions\ForbiddenException; @@ -99,6 +100,8 @@ protected function handle(UserInterface $user): array $locales = $this->siteLocale->getAvailableIdentifiers(); if (count($locales) <= 1) { $fields['hidden'][] = 'locale'; + } else { + $fields['locale_name'] = (new Locale($user->locale))->getRegionalName(); } // Determine buttons to display diff --git a/app/templates/pages/user.html.twig b/app/templates/pages/user.html.twig index 67495b7..0ab921e 100644 --- a/app/templates/pages/user.html.twig +++ b/app/templates/pages/user.html.twig @@ -111,7 +111,7 @@
{{translate("LOCALE")}}

- {{locales[user.locale]}} + {{ fields.locale_name }}

{% endif %} diff --git a/app/tests/Controller/User/UserPageActionTest.php b/app/tests/Controller/User/UserPageActionTest.php index c0fab0d..59e8de4 100644 --- a/app/tests/Controller/User/UserPageActionTest.php +++ b/app/tests/Controller/User/UserPageActionTest.php @@ -84,4 +84,29 @@ public function testPage(): void $this->assertResponseStatus(200, $response); $this->assertNotEmpty((string) $response->getBody()); } + + 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()); + } } diff --git a/package.json b/package.json index 9fffe2c..34e3738 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@userfrosting/sprinkle-admin", - "version": "5.1.1", + "version": "5.1.3", "description": "Admin Sprinkle for UserFrosting 5", "funding": "https://opencollective.com/userfrosting", "license": "MIT", From a15039434f8495122fae44d948ea829cf95fd5bb Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 29 Nov 2024 19:44:07 -0500 Subject: [PATCH 3/4] Add PHP 8.4 to tests --- .github/workflows/Build.yml | 12 ++++++------ .github/workflows/PHPStan.yml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 9c3a3ed..8fbdae4 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/PHPStan.yml b/.github/workflows/PHPStan.yml index c959a2a..f533dbb 100644 --- a/.github/workflows/PHPStan.yml +++ b/.github/workflows/PHPStan.yml @@ -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 }} From 0e6777f2e45c27355b5a3183586e5eb91fe07ed4 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 29 Nov 2024 20:08:50 -0500 Subject: [PATCH 4/4] 5.1.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f960cb1..06613a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@userfrosting/sprinkle-admin", - "version": "5.1.1", + "version": "5.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@userfrosting/sprinkle-admin", - "version": "5.1.1", + "version": "5.1.4", "license": "MIT", "dependencies": { "@userfrosting/theme-adminlte": "~5.1.0" diff --git a/package.json b/package.json index 34e3738..77d03c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@userfrosting/sprinkle-admin", - "version": "5.1.3", + "version": "5.1.4", "description": "Admin Sprinkle for UserFrosting 5", "funding": "https://opencollective.com/userfrosting", "license": "MIT",