Closed (fixed)
Project:
Password Policy
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Oct 2021 at 12:48 UTC
Updated:
9 Sep 2022 at 12:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
srishtiiee commentedComment #3
srishtiiee commentedComment #4
wim leersThis is looking great! 👍
Marking for the first two points of feedback in particular; everything else is pure nitpickery 🤓
This should use a migration lookup; different Drupal 7 sites could have different role IDs.
Example:
in
\Drupal\field\Plugin\migrate\process\d7\FieldInstanceSettings::transform().Woah, this is an interesting piece of code! 😄
These are 4 step-by-step transformations. In this case, what would be really helpful is if there was a comment at the top showing the input at the beginning and the output at the end; that allows somebody reading this code to make sense of these 4 transformation steps 😊 … without being overwhelmed 🙈😅
staticbecause uses no data in the object; that way it's clearly enforced that this method cannot modify the object.protected? Never makepublicwhat you don't have to, because that de facto becomes an API you have to support! (I learned this the hard way 😬)This … sort of feels like the kind of code that Drupal core should already have something for. So I grepped for "months". Didn't find anything useful 😬
Then I realized there should be something for this even in PHP, right?
So I searched
php date months weeks hours: https://duckduckgo.com/?q=php+date+months+weeks+hours&ia=web and found https://www.php.net/manual/en/function.date-diff.php as the 4th search result.The first example at https://www.php.net/manual/en/datetime.diff.php is:
And if I then enter
nowandnow + 2 weeksin there, I get:+14 days.See https://3v4l.org/M5bZi
But … that's not fundamentally better either.
So +1 to keeping what you have here: it's the least amount of magic for sure!
This is formatted a bit weirdly to my Drupal-y eyes 🤓
I'd have expected either:
(when using multi-line formatting)
or
(single-line formatting is possible because it's still less than 80 characters on this line).
Can be simplified to:
Comment #5
srishtiiee commentedMade all the required changes.
Comment #6
wim leersI have one last round of feedback 🤓
Nit: s/MenuLinkParent/PolicyConfiguration/
👏
Interesting! Why is this necessary? 🤔
🤔 What is special about role
0?Doesn't that correspond to the
anonymousrole for which we have a more explicit check 2 lines later?🤓 Nitpick: the
isat the end of this lines makes this line exceed the "80 characters per line" rule.Can you re-flow the comment so that it never exceeds 80 characters?
… that being said, this does explain what's happening very clearly! 👏
Comment #7
srishtiiee commentedIn #6:
4. I'm checking if the value of role is not set to 0, which means that the policy applies to that particular user role. And in the later check I've excluded the 'anonymous' role as the policies can only apply to 'authenticated' or 'administrator' user roles in 8.x-3.x
Comment #8
srishtiiee commentedFixed minor coding standard issues.
Comment #9
wim leersLooking great! 👏😊
Comment #10
paulocsI tried to reproduce the migration process between a drupal 7 and a drupal 9 fresh installation with one password policy created and I was not able to migrate it via the interface.
How can I manually test it?
My steps were:
1) Create e fresh Drupal 7 project and install password_policy module
2) Create a password_policy to set a minimum of uppercase characters to the password
3) Create e fresh Drupal 9 project and install password_policy module
4) Install password_policy_characters
5) Create the same password policy
6) Go to
/upgradeAfter adding the information of the Drupal 7 database, in /upgrade/review says that the password_policy module won't be migrated.
See image attached.
Comment #11
wim leers@paulocs: that's just because there's no
password_policy.migrate_drupal.ymlfile defined added in the patch. If you usedrush migrate:import password_policy_settingsit will work just fine.(Not a whole lot of people use
migrate_drupal_uiAFAIK.)We can easily add that though. Create
password_policy.migrate_drupal.ymlwith these contents, and you'll be able to use that UI:Comment #12
paulocsThank you @Wim Leers.
I'll try it later. I'm not very familiar with migration so I'm still learning about it.
Comment #13
paulocsPassword policy in drupal 7 has no config column. When I run the migration I got the error:
Migration failed with source plugin exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_policy.config' in 'field list': SELECT "password_policy"."name" AS "name", "password_policy"."config" AS "config", "map"."sourceid1" AS "migrate_map_sourceid1", "map"."source_row_status" AS "migrate_map_source_row_status"I suppose its because in
password_policy_settings.ymlhas a reference to this field in:In
Drupal\password_policy\Plugin\migrate\source\PasswordPolicyas well.The tests should be updated too so moving to NW.
Comment #14
wim leersSorry, only seeing this now, @paulocs!
This migration was developed agains the
7.x-2.xversion of thepassword_policymodule, which does have that column: https://git.drupalcode.org/project/password_policy/-/blob/7.x-2.x/passwo... — but indeed the7.x-1.xversion does not: https://git.drupalcode.org/project/password_policy/-/blob/7.x-1.x/passwo....Per https://www.drupal.org/project/usage/password_policy, ~2500 D7 sites use the
7.x-2.xbranch, while ~22000 D7 sites use the7.x-1.xbranch.We should update this patch to support both branches.
Comment #15
wim leersUntil we do #14, here's an updated patch that uses #3151732: DrupalSqlBase::checkRequirements should test version with $minimum_version to ensure this migration only runs on sites that were using
7.x-2.x.Comment #16
wim leersActually, safer to require
7208, which corresponds to the latest update hook there.Comment #17
huzookaSome thoughts on how to proceed here in regard of the data source:
The source plugin could be made compatible with 7.x-1.x if we don't explicitly specify the columns in the query:
And if we implement the MigrateSourceInterface::prepareRow() method, then we might be able to standardize the two different source data structure, either based on the columns we have, or based on the actual password_policy schema version:
(Note that the available password_policy columns in 7.x-1.x are pid, name, description, enabled, constraints (as a serialized array), created, expiration, warning (a positive number!); while in 7.x-2.x: name, config (serialized array of every single config).
A very rough review:
In addition to the above, we will need to refactor the migration and process plugin as well, because the only process plugin we have now tries to convert all of the destination policy's props, which will be the bottleneck of making the migration path compatible with both
7.x-1.xand7.x-2.x.We also should consider migrating other data (or at least triage how important they are), e.g. the previous password (hashes) also could be important imho.
But since this module had also a Drupal 4 version, declaring the minimum_schema_version is a requirement here! And I'd also change the ID of migration by adding a
d7_suffix.Comment #18
yash.rode commentedfollow up for #17.
Comment #19
wim leers🤓 All logic in this if-branch should move into a
private function transformV2()helper function.🤓 All logic in this else-branch should move into a
private function transformV1()helper function.👍 This means that it will now work for both 7.x-1.x and 7.x-2.x.
This looks simple enough 👍 And the passing test proves that it works … but only kinda. I'd like to see:
👎 This is testing with a disabled password policy. I think we should test with an enabled one.
This means the same password policy applies to all 3 roles. It'd be better if we had at least one other policy applied to one of the roles.
Comment #20
yash.rode commentedfollow up for #19.
Comment #21
yash.rode commentedComment #22
yash.rode commentedAdded parameter doc comments.
Comment #23
wim leersCould use a cleanup in formatting 🙏
🤔 Do we really want strict equality checking here?
I know it's a common abbreviation in everyday English, but it's a bit confusing in a code comment I think 🤓
s/no/number/
s/no./number/
for eg -→
For example:Comment #24
yash.rode commentedfollow up for #23.
Comment #25
yash.rode commentedComment #26
wim leersLooking good!
P.S.: could you maybe post the before → after screenshots for both branches here too that you showed me? 🤞
Comment #27
yash.rode commented7.x-1.x:
migrates to
7.x-2.x:
Comment #28
yash.rode commentedAbove screenshots shows, migration for booth 7.x-1.x and 7.x-2.x branches.
Comment #29
wim leersYay, thanks!
Comment #30
paulocsJust tested it and it looks good for both versions. Thank you all!
Comment #32
wim leersWonderful! Any chance there will be a new release soon that includes this? 🤓
Comment #33
paulocsYes, I'll create it next week.
#3305839: Create Password Policy 8.x-3.2 release
Comment #34
wim leers🥳