Skip to content
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

Closed
wants to merge 557 commits into from
Closed

Conversation

davidnsai
Copy link
Contributor

@davidnsai davidnsai commented Feb 1, 2023

Closes #509

A completed feature for banning and unbanning users.

@kenjis kenjis added GPG-Signing needed Pull requests that need GPG-Signing new feature PRs for new features tests needed Pull requests that need tests labels Feb 1, 2023
@kenjis
Copy link
Member

kenjis commented Feb 1, 2023

Thank you for sending this PR.

Please sign your commits:
https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#signing

And fix the failed tests and add tests for your work:
https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#unit-testing

@davidnsai
Copy link
Contributor Author

@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?

@lonnieezell
Copy link
Member

@davidnsai Nope - that's not on your end. I've approved it. We'll see if @kenjis has any other comments before we merge.

@kenjis
Copy link
Member

kenjis commented Feb 14, 2023

@kenjis
Copy link
Member

kenjis commented Feb 14, 2023

@kenjis
Copy link
Member

kenjis commented Feb 14, 2023

@@ -65,6 +65,15 @@ public function attempt(array $credentials): Result

$user = $result->extraInfo();

if ($user->banned) {
Copy link
Member

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

@kenjis
Copy link
Member

kenjis commented Feb 14, 2023

When I run phpunit locally, some tests fails.
Why do all test pass on GitHub Actions?

$ 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.

@davidnsai
Copy link
Contributor Author

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

@datamweb
Copy link
Collaborator

@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.

@kenjis
Copy link
Member

kenjis commented Feb 15, 2023

@davidnsai
Copy link
Contributor Author

@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

@kenjis kenjis mentioned this pull request Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GPG-Signing needed Pull requests that need GPG-Signing new feature PRs for new features tests needed Pull requests that need tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev: banning users