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

Remove oppressive words from code #1205

Merged
merged 1 commit into from
Aug 30, 2020

Conversation

davidromani
Copy link
Contributor

@davidromani davidromani commented Aug 8, 2020

Subject

We should avoid offending terms like blacklist, whitlist, master, slave... and use more tech-related words like blocklist, primary or secondary, for example.

I am targeting 4.x branch because everything is backwards compatible.

Closes #1191

Changelog

### Changed
- Replace `ip_white_list` by `trusted_ip_list` configuration key

To do

  • Update the tests;
  • Update the documentation;
  • Add an upgrade note.

@SonataCI
Copy link
Collaborator

SonataCI commented Aug 8, 2020

Could you please rebase your PR and fix merge conflicts?

@davidromani
Copy link
Contributor Author

Ok, let me a little bit more time, I prefer to make it BC too...

@davidromani
Copy link
Contributor Author

Hey @greg0ire I don't know how to change this PR against 4.x branch instead of master branch. Is this possible? Or I must open a new PR?

@franmomu
Copy link
Member

Hey @greg0ire I don't know how to change this PR against 4.x branch instead of master branch. Is this possible? Or I must open a new PR?

You can click on the Edit button on the top right (like changing the title) and then change the base branch.

@davidromani davidromani changed the base branch from master to 4.x August 10, 2020 10:21
@davidromani davidromani requested a review from greg0ire August 10, 2020 10:55
@@ -178,7 +178,7 @@ public function configureGoogleAuthenticator($config, ContainerBuilder $containe
}

$container->setParameter('sonata.user.google.authenticator.forced_for_role', $config['google_authenticator']['forced_for_role']);
$container->setParameter('sonata.user.google.authenticator.ip_white_list', $config['google_authenticator']['ip_white_list']);
$container->setParameter('sonata.user.google.authenticator.trusted_ip_list', $config['google_authenticator']['trusted_ip_list']);
Copy link
Member

@franmomu franmomu Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be BC-break, people can still use the ip_white_list option, so here we should also check if ip_white_list exists and use it. A test verifying that this behavior still works would be nice.

PS: Is it possible to deprecate a parameter? 🤔 EDIT: deprecate a parameter in the container.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franmomu I've marked ip_white_list as a deprecated parameter, is this enough?

Copy link
Contributor

@greg0ire greg0ire Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ip_white_list is a configuration node. A container parameter is something else entirely. AFAIK You cannot deprecate it, but maybe I'm wrong. IMO @franmomu is right, you should define that parameter from whatever configuration node is defined in the config (after validating that one and only one of them is defined as I described above).

Copy link
Member

@franmomu franmomu Aug 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant (about the parameter deprecation in the container) is removing sonata.user.google.authenticator.ip_white_list from the container is BC-break because someone can be using that parameter (it's unlikely, but you never know), if there is no way to deprecate a parameter in the container, an upgrade note I think it's enough and we will remove it on the next major version.

@@ -69,6 +69,9 @@ public function getConfigTreeBuilder()
->scalarNode('server')->cannotBeEmpty()->end()
->scalarNode('enabled')->defaultFalse()->end()
->arrayNode('ip_white_list')
->setDeprecated('The "%node%" option is deprecated. Use "trusted_ip_list" instead with the same values.')
->end()
->arrayNode('trusted_ip_list')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to throw an exception if both configuration nodes are defined. I'm not sure if it can be done here, if yes, that's great, if not you can do it in the extension.

@franmomu
Copy link
Member

franmomu commented Aug 10, 2020

So just to be clear because I didn't explain myself clearly, there are three issues right now:

  • A user can define ip_white_list and trusted_ip_list, in that case as @greg0ire said it would be great to throw an exception.
  • In case someone uses ip_white_list, they will get a deprecation message, but it won't work right now, we should do something like:
$trustedIpList = $config['google_authenticator']['ip_white_list'] ?? $config['google_authenticator']['trusted_ip_list'];
$container->setParameter('sonata.user.google.authenticator.trusted_ip_list', trustedIpList);
  • We shouldn't remove sonata.user.google.authenticator.ip_white_list parameter from the container because is BC-break, so we should add:
$container->setParameter('sonata.user.google.authenticator.ip_white_list', trustedIpList);

@davidromani davidromani requested a review from franmomu August 10, 2020 19:03
@davidromani
Copy link
Contributor Author

@franmomu @greg0ire only as a proof of concept, is the last commit in a good path to solve it?

Comment on lines 182 to 187
if (array_key_exists('ip_white_list', $config['google_authenticator']) && array_key_exists('trusted_ip_list', $config['google_authenticator'])) {
throw new \RuntimeException('Please use only ``trusted_ip_list`` parameter. ``ip_white_list`` is deprecated.');
}
if (array_key_exists('ip_white_list', $config['google_authenticator']) && !array_key_exists('trusted_ip_list', $config['google_authenticator'])) {
$container->setParameter('sonata.user.google.authenticator.trusted_ip_list', $config['google_authenticator']['ip_white_list']);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a comment
// NEXT_MAJOR: Remove this checks and only set the trusted_ip_list.

That's how we deal todos.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

$container->setParameter('sonata.user.google.authenticator.ip_white_list', $config['google_authenticator']['ip_white_list']);

if (array_key_exists('ip_white_list', $config['google_authenticator']) && array_key_exists('trusted_ip_list', $config['google_authenticator'])) {
throw new \RuntimeException('Please use only ``trusted_ip_list`` parameter. ``ip_white_list`` is deprecated.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed by changing code, so let's use \LogicException here

Suggested change
throw new \RuntimeException('Please use only ``trusted_ip_list`` parameter. ``ip_white_list`` is deprecated.');
throw new \LogicException('Please use only ``trusted_ip_list`` parameter. ``ip_white_list`` is deprecated.');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why the double backticks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seen in line 177 of the same class, I've tried to keep same notation (don't know if must be single or double backtick)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neither markdown nor rst, don't know why it was contributed like this. IMO we should use double quotes…

@greg0ire
Copy link
Contributor

@franmomu @greg0ire only as a proof of concept, is the last commit in a good path to solve it?

It's looking good yeah :)

Copy link
Contributor Author

@davidromani davidromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that now it's all fine tuned, but still getting an error during testing process. Can you help me to solve tests? I don't know very well how to do it.

Thx.

@davidromani davidromani requested a review from franmomu August 11, 2020 08:12
@davidromani davidromani requested a review from franmomu August 12, 2020 08:03
@@ -42,7 +42,7 @@ public function testDefault(): void
],
'google_authenticator' => [
'enabled' => false,
'ip_white_list' => ['127.0.0.1'],
'trusted_ip_list' => ['127.0.0.1'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'trusted_ip_list' => ['127.0.0.1'],
'ip_white_list' => [],
'trusted_ip_list' => ['127.0.0.1'],

Since ip_white_list is still accepted, it will be in the default values, with this the test should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@davidromani davidromani requested a review from greg0ire August 20, 2020 13:31
greg0ire
greg0ire previously approved these changes Aug 20, 2020
jordisala1991
jordisala1991 previously approved these changes Aug 20, 2020
Copy link
Member

@jordisala1991 jordisala1991 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please squash to a single commit ? If you dont know how to do it, we need to make sure we do a squash merge

@davidromani
Copy link
Contributor Author

Can you please squash to a single commit ? If you dont know how to do it, we need to make sure we do a squash merge

Never done before, but I think that I can do it... let me try it

@greg0ire
Copy link
Contributor

Here is a guide:

  1. git rebase -i origin/4.x, assuming origin is a git remote that points to this repository, and not your fork. If you're not sure what your remotes are, run git remote -vvv, there should be your fork and the holy/reference/base/origin/whatever-you-call-it repository.
  2. A window will show up with many lines, replace pick with fixup on every line but the first one
  3. Close your editor, git should do its magic, and you should end up with one commit
  4. Use git push --force to overwrite what you already push. Don't forget the --force option otherwise git will try to merge both things together.

@davidromani davidromani dismissed stale reviews from jordisala1991 and greg0ire via 90f76c7 August 20, 2020 17:37
@davidromani davidromani force-pushed the fix_issue_1191 branch 3 times, most recently from ccf5d62 to 634faa2 Compare August 20, 2020 17:43
@greg0ire
Copy link
Contributor

greg0ire commented Aug 20, 2020

Looks like you did it! One last thing: please format your commit message according to our rules :

  • The commit message subject must be less than 50 characters and tell us what you did.
  • The commit message body should tell us why you did it. It is optional but highly recommended.

Bad example :

Fixed bug #989 by removing call to defraculate()

Good example:

Remove call to defraculate()

Calling this function caused a bug because it interferes 
with calls to getSchmeckles().
Fixes #989

git commit --amend && git push --force-with-lease to do so.

More details in CONTRIBUTING.md

"ip_white_list" from "google_authenticator" configuration key has been replaced by "trusted_ip_list" key.
For now, both configuration keys are valid, but only one can be used at same time.
"ip_white_list" has been marked as deprecated and will be removed in next major release to keep BC in 4.x branch.
Fixes sonata-project#1191
@davidromani
Copy link
Contributor Author

Looks like you did it! One last thing: please format your commit message according to our rules :

All done, thanks for your patience and for teaching me how to improve my Git skills.

@davidromani davidromani requested a review from greg0ire August 21, 2020 08:34
@franmomu franmomu closed this Aug 30, 2020
@franmomu franmomu reopened this Aug 30, 2020
@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2020

Codecov Report

❗ No coverage uploaded for pull request base (4.x@782cdcd). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##             4.x    #1205   +/-   ##
======================================
  Coverage       ?   69.61%           
  Complexity     ?      458           
======================================
  Files          ?       46           
  Lines          ?     1415           
  Branches       ?        0           
======================================
  Hits           ?      985           
  Misses         ?      430           
  Partials       ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 782cdcd...4e9613e. Read the comment docs.

@franmomu franmomu merged commit b8eca6d into sonata-project:4.x Aug 30, 2020
@franmomu
Copy link
Member

Thanks @davidromani!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove oppressive words from code
7 participants