Add validation constraints to user.settings

Created on 26 March 2024, 9 months ago
Updated 12 July 2024, 5 months ago

Problem/Motivation

vendor/bin/drush config:inspect --filter-keys=user.settings --detail --list-constraints

➜  🤖 Analyzing…

 Legend for Data:
  ✅❓  → Correct primitive type, detailed validation impossible.
  ✅✅  → Correct primitive type, passed all validation constraints.
 ----------------------------------------------------- --------- ------------- ------ ---------------------------------------------------------------------------------------------
  Key                                                   Status    Validatable   Data   Validation constraints
 ----------------------------------------------------- --------- ------------- ------ ---------------------------------------------------------------------------------------------
  user.settings                                         Correct   84%           ✅❓   ValidKeys: '<infer>'
   user.settings:                                       Correct   Validatable   ✅✅   ValidKeys: '<infer>'
   user.settings:_core                                  Correct   Validatable   ✅✅   ValidKeys:
                                                                                         - default_config_hash
   user.settings:_core.default_config_hash              Correct   Validatable   ✅✅   NotNull: {  }
                                                                                       Regex: '/^[a-zA-Z0-9\-_]+$/'
                                                                                       Length: 43
                                                                                       ↣ PrimitiveType: {  }
   user.settings:anonymous                              Correct   Validatable   ✅✅   Regex:
                                                                                         pattern: '/([^\PC])/u'
                                                                                         match: false
                                                                                         message: 'Labels are not allowed to span multiple lines or contain control characters.'
                                                                                       NotBlank: {  }
                                                                                       ↣ PrimitiveType: {  }
   user.settings:cancel_method                          Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here
   user.settings:langcode                               Correct   Validatable   ✅✅   NotNull: {  }
                                                                                       Choice:
                                                                                         callback: 'Drupal\Core\TypedData\Plugin\DataType\LanguageReference::getAllValidLangcodes'
                                                                                       ↣ PrimitiveType: {  }
   user.settings:notify                                 Correct   Validatable   ✅✅   ValidKeys: '<infer>'
   user.settings:notify.cancel_confirm                  Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.password_reset                  Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.register_admin_created          Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.register_no_approval_required   Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.register_pending_approval       Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.status_activated                Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.status_blocked                  Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:notify.status_canceled                 Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:password_reset_timeout                 Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here
   user.settings:password_strength                      Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
   user.settings:register                               Correct   NOT           ✅❓   ⚠️  @todo Add validation constraints here
   user.settings:verify_mail                            Correct   Validatable   ✅✅   ↣ PrimitiveType: {  }
 ----------------------------------------------------- --------- ------------- ------ ---------------------------------------------------------------------------------------------

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

11.0 🔥

Component
User module 

Last updated about 2 hours ago

Created by

🇮🇳India omkar.podey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @omkar.podey
  • Merge request !7204Add validation constraints to user.settings → (Open) created by omkar.podey
  • Pipeline finished with Failed
    9 months ago
    Total: 861s
    #130240
  • 🇮🇳India omkar.podey
    1. register key could have 3 values according to \Drupal\user\UserInterface
    2. cancel_method can have any function assigned to it but i think it can't be empty.
    3. password_reset_timeout It is never being set just being read so I think it should just not be null.
  • Pipeline finished with Failed
    9 months ago
    Total: 847s
    #130423
  • Pipeline finished with Success
    9 months ago
    Total: 494s
    #130523
  • 🇮🇳India omkar.podey

    cancel_method has to be nullable according to testConfigForm

  • Status changed to Needs review 9 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 9 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • Pipeline finished with Failed
    9 months ago
    Total: 505s
    #134378
  • Pipeline finished with Failed
    9 months ago
    Total: 490s
    #136241
  • Pipeline finished with Failed
    9 months ago
    Total: 493s
    #136364
  • 🇮🇳India omkar.podey

    The migration tests and UserMailNotifyTest isn't happy with making all the keys required because of marking user.settings as fullyValidatable .I could add keys to UserMailNotifyTest and remove the requiredkey: false from most of them, doing that next.

  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    I could add keys to UserMailNotifyTest and remove the requiredkey: false from most of them

    I agree, this looks like the best way

  • 🇮🇳India omkar.podey

    omkar.podey changed the visibility of the branch 3436164-add-validation-constraints to hidden.

  • Merge request !7412Add validation constraints to user.settings → (Open) created by omkar.podey
  • Pipeline finished with Failed
    8 months ago
    Total: 588s
    #142773
  • 🇮🇳India omkar.podey

    Okay so I switched to 10.3.x. and right now the only test that's failing is Drupal\Tests\user\Kernel\UserAdminSettingsFormTest::testConfigForm

    To fix this there were two options, either add config target data to core/modules/user/src/AccountSettingsForm.php or mark the keys that are failing the test as requiredKey: false in user.schema.yml.

    So I thought that the requiredKey false would be the solution but then I ran into the langcode issue again where the langcode isn't defined in user.schema.yml so I can't mark it requiredKey: false.

    thoughts ?

  • Pipeline finished with Failed
    8 months ago
    Total: 499s
    #144875
  • Pipeline finished with Success
    8 months ago
    Total: 2273s
    #146928
  • Pipeline finished with Success
    8 months ago
    Total: 4886s
    #147006
  • Status changed to Needs review 8 months ago
  • Status changed to Needs work 8 months ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs review 8 months ago
  • Status changed to Needs work 8 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Pipeline finished with Success
    8 months ago
    Total: 996s
    #147741
  • Status changed to Needs review 8 months ago
  • Status changed to Needs work 8 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Pipeline finished with Failed
    8 months ago
    Total: 201s
    #149010
  • Pipeline finished with Success
    8 months ago
    Total: 1017s
    #149030
  • Status changed to Needs review 8 months ago
  • Pipeline finished with Success
    8 months ago
    Total: 1077s
    #149824
  • Status changed to Needs work 8 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Getting close!

  • Pipeline finished with Canceled
    8 months ago
    Total: 374s
    #149968
  • Pipeline finished with Success
    8 months ago
    Total: 958s
    #149975
  • Pipeline finished with Success
    8 months ago
    Total: 1110s
    #149988
  • Status changed to Needs review 8 months ago
  • Status changed to Needs work 8 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    99% ready!

  • Status changed to Needs review 8 months ago
  • Pipeline finished with Success
    8 months ago
    Total: 1035s
    #153062
  • Status changed to Needs work 8 months ago
  • 🇺🇸United States smustgrave

    This is looking really good! Can the MR be updated for 11.x though please.

  • Status changed to Needs review 8 months ago
  • 🇮🇳India omkar.podey

    I would like to get it reviewed first and then we can decide if we need the 11.x branch explicitly.

  • Status changed to Needs work 8 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I would like to get it reviewed first and then we can decide if we need the 11.x branch explicitly.

    All changes land in 11.x first. So we need an MR that targets 11.x anyway.

    Still, reviewed it for you … and what I wrote in #24 is still true.

    If this were already targeting 11.x, I would and could've RTBC'd 😅

  • Merge request !7827add validation constraints to user.settings → (Open) created by omkar.podey
  • Pipeline finished with Canceled
    8 months ago
    Total: 3096s
    #159645
  • 🇮🇳India pradhumanjainOSL

    pradhumanjain2311 made their first commit to this issue’s fork.

  • Pipeline finished with Failed
    8 months ago
    Total: 6206s
    #159665
  • Pipeline finished with Failed
    8 months ago
    Total: 760s
    #159741
  • Pipeline finished with Success
    8 months ago
    Total: 1197s
    #159740
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    The addition of the UserCancelMethod constraint seems fine, but the API addition in user_cancel_methods() is somewhat questionable. Then again, I don't see any better choice available to us … this is just super old code that has never been converted to more modern Drupal standards.

    #3135592: Cannot implement a custom user cancellation method and Provide a Entity Handler for user cancelation Needs work are the issues to modernize that part of Drupal core. So until either of those land, this is doing the best we can. We don't need to make this the most elegant thing possible, because it isn't already anyway, and user_cancel_methods() will disappear when those are finished.

    Ah, no, the 11.x branch has two remaining failures:

    Drupal\Tests\user\Kernel\UserEntityLabelTest::testLabelCallback
    Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for user.settings with the following errors: 0 [] &#039;verify_mail&#039; is a required key., 1 [] &#039;notify&#039; is a required key., 2 [] &#039;register&#039; is a required key., 3 [] &#039;cancel_method&#039; is a required key., 4 [] &#039;password_reset_timeout&#039; is a required key., 5 [] &#039;password_strength&#039; is a required key.
    

    and

    Drupal\Tests\user\Kernel\UserAdminSettingsFormTest::testConfigForm
    Input values: <em class="placeholder">Array
    (
        [anonymous] =&gt; 3rj{f&gt;&amp;3y@
        [user_mail_cancel_confirm_body] =&gt; {;D5&gt;&amp;vM
        [user_mail_cancel_confirm_subject] =&gt; @R)&quot;o=`EfB&gt;&amp;T)#!\)V&lt;
        [register_pending_approval_admin_body] =&gt; 6e*n&gt;&amp;Ob
        [register_pending_approval_admin_subject] =&gt; %`6JwPffFF&gt;&amp;9WqUZ&#039;_4
        [user_mail_password_reset_subject] =&gt; C&gt;)w&gt;&amp;q:
        [user_mail_register_admin_created_subject] =&gt; \o&#039;A&gt;&amp;nH
        [user_mail_register_no_approval_required_subject] =&gt; APXk&gt;&amp;O&#039;
        [user_mail_register_pending_approval_subject] =&gt; My1A&gt;&amp;8{
        [user_mail_status_activated_subject] =&gt; ixV4&gt;&amp;^{
        [user_mail_status_blocked_subject] =&gt; DmL!&gt;&amp;,z
        [user_mail_status_canceled_subject] =&gt; 9K1&#039;&gt;&amp;=V
    )
    </em><br/>Validation handler errors: <em class="placeholder">&#039;register_pending_approval&#039; is a required key. This value should not be null. This value should not be null.</em>
    Failed asserting that false is true.
    
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Wim Leers changed the visibility of the branch 3436164-add-validation-constraints-user-settings to hidden.

  • Pipeline finished with Success
    8 months ago
    Total: 619s
    #160423
  • Pipeline finished with Success
    8 months ago
    Total: 503s
    #160441
  • Status changed to Needs review 8 months ago
  • Status changed to RTBC 8 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • Status changed to Needs work 8 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍
  • Pipeline finished with Success
    8 months ago
    Total: 592s
    #163176
  • Status changed to Needs review 8 months ago
  • Status changed to RTBC 8 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I think this is what @alexpott was asking for — until #3135592: Cannot implement a custom user cancellation method and/or Provide a Entity Handler for user cancelation Needs work happen, a truly elegant approach won't be possible anyway 👍

  • Status changed to Needs work 8 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Added some comments to the MR. This needs to go in 11.x first.

  • Pipeline finished with Success
    8 months ago
    Total: 571s
    #165249
  • Status changed to Needs review 8 months ago
  • Status changed to RTBC 7 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • Status changed to Needs work 7 months ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Looking good folks, I think we need some new tests for the constraints here.
    It would also be good to have a couple of follow ups to make this not feel so dirty in places.

  • Pipeline finished with Failed
    7 months ago
    Total: 1061s
    #185961
  • Pipeline finished with Canceled
    7 months ago
    Total: 137s
    #186773
  • Pipeline finished with Success
    7 months ago
    Total: 604s
    #186775
  • Status changed to Needs review 7 months ago
  • Status changed to RTBC 6 months ago
  • 🇺🇸United States smustgrave

    Removing tests tag as they seem to be added here https://git.drupalcode.org/issue/drupal-3436164/-/jobs/1734989

    From what I can tell the feedback in threads/followups have been resolved.

    On a standard install of 11.x with config inspector installed I get all checks for user.settings.

  • Status changed to Needs work 6 months ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Several nits and one commit-blocking remark.

  • 🇮🇳India kunal.sachdev

    kunal.sachdev made their first commit to this issue’s fork.

  • Pipeline finished with Success
    6 months ago
    Total: 506s
    #206631
  • Pipeline finished with Failed
    6 months ago
    Total: 199s
    #206735
  • Pipeline finished with Success
    6 months ago
    Total: 597s
    #206742
  • Pipeline finished with Failed
    6 months ago
    Total: 541s
    #206757
  • Pipeline finished with Success
    6 months ago
    Total: 594s
    #206780
  • Pipeline finished with Success
    6 months ago
    Total: 577s
    #206789
  • Status changed to Needs review 6 months ago
  • Status changed to RTBC 6 months ago
  • 🇺🇸United States smustgrave

    Appears additional feedback has been addressed

    Retested using configuration inspector (see #44)

  • Status changed to Fixed 6 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Committed f562df4 and pushed to 11.x. Thanks!

    • alexpott committed f562df44 on 11.x
      Issue #3436164 by omkar.podey, kunal.sachdev, pradhumanjain2311,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024