-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Banning Users #617
Conversation
Thank you for sending this PR. Please sign your commits: And fix the failed tests and add tests for your work: |
@lonnieezell thanks, for the review. I am now encountering the unused package error, I should believe that is not an issue on my end right? |
@davidnsai Nope - that's not on your end. I've approved it. We'll see if @kenjis has any other comments before we merge. |
@davidnsai Please sign your commits: |
@davidnsai There is no test code. Please add test code. |
@davidnsai This PR branch is out of dated. Please rebase: |
@@ -65,6 +65,15 @@ public function attempt(array $credentials): Result | |||
|
|||
$user = $result->extraInfo(); | |||
|
|||
if ($user->banned) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the property directly makes it impossible to define interface in the future.
I think it is better to have User::isBanned()
like isActivated()
:
https://github.com/codeigniter4/shield/blob/develop/src/Traits/Activatable.php#L13
When I run phpunit locally, some tests fails. $ composer test
> phpunit
PHPUnit 9.6.3 by Sebastian Bergmann and contributors.
Runtime: PHP 8.1.13 with Xdebug 3.1.5
Configuration: /Users/kenji/work/codeigniter/official/codeigniter-shield/phpunit.xml
Random Seed: 1676334955
....F....F....F......F............F.....F.....F...F.......F.... 63 / 284 ( 22%)
............................................................... 126 / 284 ( 44%)
............................................................... 189 / 284 ( 66%)
............................................................... 252 / 284 ( 88%)
................................ 284 / 284 (100%)
Nexus\PHPUnit\Extension\Tachycardia identified these 30 slow tests:
+------------------------------------------------------------------------------------------------------+---------------+-------------+
| Test Case | Time Consumed | Time Limit |
+------------------------------------------------------------------------------------------------------+---------------+-------------+
| Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined | 00:00:04.19 | 00:00:00.50 |
| Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin | 00:00:04.07 | 00:00:00.50 |
| Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin | 00:00:04.05 | 00:00:00.50 |
| Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain | 00:00:03.71 | 00:00:00.50 |
| Tests\\Controllers\\RegisterTest::testRegisterActionSuccess | 00:00:03.65 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\AccessTokenAuthenticatorTest::testLoginByIdWithMultipleTokens | 00:00:03.03 | 00:00:00.50 |
| Tests\\Unit\\UserModelTest::testUpdateUserArrayWithUserDataToUpdate | 00:00:02.94 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\SessionAuthenticatorTest::testLoginNoRemember | 00:00:02.53 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testLoginActionEmailSuccess | 00:00:02.45 | 00:00:00.50 |
| Tests\\Unit\\DictionaryValidatorTest::testCheckTrueOnNotFound | 00:00:02.28 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testLogoutAction | 00:00:02.04 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testLoginRedirectsToActionIfDefined | 00:00:01.98 | 00:00:00.50 |
| Tests\\Authentication\\Filters\\PermissionFilterTest::testFilterSuccess | 00:00:01.91 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testLoginBadEmail | 00:00:01.88 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testLoginActionUsernameSuccess | 00:00:01.85 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\AccessTokenAuthenticatorTest::testLoginByIdWithToken | 00:00:01.84 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\SessionAuthenticatorTest::testCheckSuccess | 00:00:01.77 | 00:00:00.50 |
| Tests\\Controllers\\LoginTest::testAfterLoggedInNotDisplayLoginPage | 00:00:01.75 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\AccessTokenAuthenticatorTest::testLoginByIdNoToken | 00:00:01.73 | 00:00:00.50 |
| Tests\\Authentication\\MagicLinkTest::testMagicLinkVerifySuccess | 00:00:01.72 | 00:00:00.50 |
| Tests\\Unit\\UserTest::testModelFindAllWithIdentities | 00:00:01.69 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\SessionAuthenticatorTest::testLoggedInWithRememberCookie | 00:00:01.59 | 00:00:00.50 |
| Tests\\Authentication\\MagicLinkTest::testMagicLinkSubmitSuccess | 00:00:01.58 | 00:00:00.50 |
| Tests\\Authentication\\Filters\\GroupFilterTest::testFilterIncorrectGroupNoPrevious | 00:00:01.56 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\SessionAuthenticatorTest::testLoginById | 00:00:01.54 | 00:00:00.50 |
| Tests\\Unit\\UserModelTest::testSaveUpdateUserObjectWithoutUserDataToUpdate | 00:00:01.54 | 00:00:00.50 |
| Tests\\Unit\\UserTest::testModelFindByIdWithIdentities | 00:00:01.54 | 00:00:00.50 |
| Tests\\Unit\\UserTest::testGetIdentitiesSome | 00:00:01.54 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\AccessTokenAuthenticatorTest::testAttemptSuccess | 00:00:01.53 | 00:00:00.50 |
| Tests\\Authentication\\Authenticators\\SessionAuthenticatorTest::testLoginByIdRemember | 00:00:01.53 | 00:00:00.50 |
+------------------------------------------------------------------------------------------------------+---------------+-------------+
...and 143 more tests hidden from view.
Time: 04:01.470, Memory: 64.00 MB
There were 9 failures:
1) Tests\Language\GermanTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "de" ('de')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "de" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
2) Tests\Language\SlovakTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "sk" ('sk')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "sk" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
3) Tests\Language\ItalianTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "it" ('it')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "it" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
4) Tests\Language\FrenchTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "fr" ('fr')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "fr" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
5) Tests\Language\FarsiTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "fa" ('fa')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "fa" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
6) Tests\Language\JapaneseTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "ja" ('ja')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "ja" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
7) Tests\Language\SpanishTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "es" ('es')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "es" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
8) Tests\Language\IndonesianTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "id" ('id')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "id" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
9) Tests\Language\TurkishTranslationTest::testAllConfiguredLanguageKeysAreIncluded with data set "tr" ('tr')
Failed asserting that the language keys "Auth.bannedUser", "Auth.logOutBannedUser" in the main repository are included for translation in "tr" locale.
Failed asserting that an array is empty.
/Users/kenji/work/codeigniter/official/codeigniter-shield/tests/Language/AbstractTranslationTestCase.php:174
FAILURES!
Tests: 284, Assertions: 638, Failures: 9. |
These tests are failing locally as well because I only added a translation for English. I will add translations for the other languages as well. I just hope that the translation service I use will get the statements right |
@davidnsai No need to translate, for other languages add as below. 'bannedUser' => '(To be translated) Can not log you in as you are currently banned.',
'logOutBannedUser' => '(To be translated) You have been logged out because you have been banned.', Address the other topics that kenjis said. |
Please sign all commits: |
To fix phpcpd error.
Co-authored-by: kenjis <kenji.uui@gmail.com>
Co-authored-by: Pooya Parsa Dadashi <pooya_parsa_dadashi@yahoo.com>
@kenjis I think I ran into some issues while signing my old commits. So I just reopen a new pull request. I won't be rewriting a lot of stuff |
Closes #509
A completed feature for banning and unbanning users.