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

First and Last Name fields can't be populated by cas_attributes module #396

Closed
jemisonf opened this issue Apr 7, 2020 · 8 comments · Fixed by #407
Closed

First and Last Name fields can't be populated by cas_attributes module #396

jemisonf opened this issue Apr 7, 2020 · 8 comments · Fixed by #407
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jemisonf
Copy link

jemisonf commented Apr 7, 2020

Describe the bug
I'd like to be able to populate the "First Name" and "Last Name" fields for a user using CAS attribute tokens provided by the cas_attributes module. This is possible for "normal" fields like username/email, and "normal" custom fields -- I tested this out by adding a "Nickname" field that I was able to configure.

I think this is an issue related to how those fields are added to the user entity, but I have no idea how to approach this problem otherwise.

If this is the wrong repository for this issue, let me know and I can move it somewhere else.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new apigee kickstart site (this is how I encountered the issue)
  2. Install and configure the drupal/cas module (I don't think you need a working CAS server to test this)
  3. Enable the cas_attributes module
  4. Navigate to /admin/config/people/cas/attributes -- the "User Field Mappings" > "Fields" section should only show the email and username fields, and not first name and last name

Expected behavior
I would expect the "Fields" section in step four to also show "First Name" and "Last Name".

Screenshots
Here's what the user fields mapping section looks like:

Screenshot from 2020-04-07 16-25-08

Additional context
This also causes an issue where users whose accounts are created via a CAS sign-in don't have a first name and last name configured by default, which can then cause issues on subsequent sign-ins. Previously, in our D7 portal, we were able to use cas_attributes to automatically populate these values, which made the process transparent to users.

Version Info
1.8.0

@jemisonf jemisonf added the bug Something isn't working label Apr 7, 2020
@varuntit101
Copy link

varuntit101 commented Apr 8, 2020

I am facing the similar issue, but with different module - Social Auth Google

On logging with google, email and username is updating, but not First Name and Last Name, this results in not creating a Developer in Edge as First name and Last Name are also mandatory fields.
Please refer the screenshot
apigee-edge-error

Can we set default First Name and Last Name in Apigee Edge module, as It is not sure that third party login modules will set all default attributes.

@kscheirer
Copy link
Contributor

@varuntit101 For social auth logins, you can use this https://github.com/kscheirer/Social-Auth-Map-Name to enable first name and last name field mapping. I wrote up some sparse instructions here: apigee/apigee-devportal-kickstart-drupal#238 (comment).

@kscheirer
Copy link
Contributor

@jemisonf The problem is likely here in the cas_attributes module: https://git.drupalcode.org/project/cas_attributes/-/blob/8.x-1.x/src/Form/CasAttributesSettings.php#L131, though I havent tested that out. The fields that will be rendered must have a target bundle defined, and be of type 'string' or 'list_string', so I'm guessing one of those conditions is not true.

@varuntit101
Copy link

@kscheirer I tried using https://github.com/kscheirer/Social-Auth-Map-Name, this works absolutely fine with Social Auth Google, but It is failing with Social Auth GitHub, it is giving error on following code :-

$user->set('first_name', $userInfo->getFirstName());
$user->set('last_name', $userInfo->getLastName());

@jemisonf
Copy link
Author

jemisonf commented Apr 9, 2020

@kscheirer thanks, that's a good find! It looks like the first_name and last_name fields are defined here as string_textfield, so it makes perfect sense if that's causing the issue. Not sure if it makes more sense to change this module to address it or to make a PR to cas_attributes so they can handle more field types.

Either way, that gives me a way I can temporarily fix it right now to resolve the issue, which is great.

@jemisonf
Copy link
Author

jemisonf commented Apr 9, 2020

Follow-on to that: it looks like the issue isn't actually that first_name and last_name have the wrong type, it's this check:

if (!empty($definition->getTargetBundle())) {

Which is failing because first_name and last_name aren't part of a bundle. Taking this check out resolves the issue, but does cause some extra fields to show up, which might not be desirable behavior. It seems like a better fix would be to add the fields to a bundle when they're created, although I'm not sure what the best option for that is.

@arunz6161 arunz6161 added this to the 8.x-1.10 milestone Apr 28, 2020
arlina-espinoza added a commit to arlina-espinoza/apigee-edge-drupal that referenced this issue May 1, 2020
@arlina-espinoza
Copy link
Contributor

@jemisonf I added a PR that would add the bundle to the first/last name fields. Not sure if any other module is needing this, but I don't see harm in adding it either.
PR: [#396] Add a target bundle to first and last name user fields.

@jemisonf
Copy link
Author

jemisonf commented May 1, 2020

@arlina-espinoza that looks great, thank you! I'll keep an eye out for it in future releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants