Problem/Motivation

Currently, we only have basic validation such as username beginning or ending with a space, or username too long. There is no logic to check if user actually exist on Drupal.org or not.

Steps to reproduce

Enter a wrong username and field would still save the data.

Proposed resolution

We can add another validation, which will verify the user data from this link https://www.drupal.org/api-d7/user.json?name=gaurav.kapoor and then based on information returned by the API we can show appropriate error message.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gaurav.kapoor created an issue. See original summary.

hussainweb’s picture

It's a good idea. But I would like to make this conditional. How about adding a field setting that lets someone enable/disable this validation?

andregp’s picture

Assigned: Unassigned » andregp

I'll try to work on this.
@hussainweb, is there anything else you'd like to point out or request?

andregp’s picture

I don't know for which reason, but as soon as I try to add a new field of type "Drupal.org username" my site crashes.

hussainweb’s picture

Interesting @andregp, can you post any recent log messages? It may be a good idea to do this in a new issue.

andregp’s picture

These are the messages on the browser console.
I get this error when I create a new content type, add a 'Drupal.org username' field and select 'save and continue'.
It's strange because the fields are somehow added to the new content type (if I go back in the browser and refresh the page the field appears listed there), but as soon as I try to access or create a new node of this content type I get the same error page.
It can be a new issue or I just did something wrong during this module installation.

andregp’s picture

Assigned: andregp » Unassigned
StatusFileSize
new100.61 KB

Also when I try to uninstall the module, even after deleting all related content, I get this error (see screenshot) which prevents me from trying to uninstalling/reinstalling the module.

hussainweb’s picture

@andregp, can you share errors from the dblog instead of the console. You should find it at /admin/reports/dblog or from the toolbar "Reports" -> "Recent Log messages".

And the error is as designed. You need to manually delete the field before uninstalling the module. This is the behaviour with all modules that provide a field type.

andregp’s picture

StatusFileSize
new7.65 KB

Oh okay, so here is attached a log error message from /admin/reports/dblog (thanks for the tip).
Also I manually deleted all fields before uninstalling the module, but I haven't added any field called 'user.field_do_username' and thus wasn't able to delete it. The only place I could find it on the code was on the yml files that came with the project (under config/install/).

gaurav.kapoor’s picture

@andregp You will have to run composer and make sure all the dependencies of the module are installed in your setup.

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

sahal_va’s picture

Status: Active » Needs review

I have added a new field setting to enable validation which will appear as a checkbox in the field's storage settings form.
Added a new constraint to validate the username from the API if the validate setting is ON.
Please review and let me know if any changes are needed.

  • b599e8c committed on 8.x-1.x
    Issue #3255230 by sahal_va, hussainweb: Add validation to check the...
hussainweb’s picture

Status: Needs review » Reviewed & tested by the community

I tested this and it works well. The problem is that on existing sites, the option is turned on by default without notice. This means there is a behavior change because of this patch. Since the module is currently alpha, this is okay.

hussainweb’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.