Skip to content

Use the user record full_name method everywhere a user's full name is shown. - #3279

Open
drgrice1 wants to merge 2 commits into
openwebwork:developfrom
drgrice1:user-full-name
Open

drgrice1 wants to merge 2 commits into
openwebwork:developfrom
drgrice1:user-full-name

Conversation

@drgrice1

Copy link
Copy Markdown
Member

Several places built a user's full name by joining the first and last names manually instead of using the full_name method of the user database record. Those places now all use that method.

@somiaj

somiaj commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Thinking out loud. Since the database returns '' for null rows, would it be worth updating the full_name method to use the join(' ', $record->first_name, $record->last_name) approach? Or just easier to read with its current approach? I guess there isn't really that much difference, outside of making the method a one line. Could also use $record->first_name // '' to deal with undefined case.

@somiaj somiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. This will help Claude out too.

@somiaj

somiaj commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Nevermind previous comment, join(' ', '', '') would actually be ' ', leaving a space. So trying to simplify this would actually be worse unless some other processing was done to trim any white space.

@drgrice1

Copy link
Copy Markdown
Member Author

This takes things just a bit further. There are numerous places where the user's name is displayed in the last, first format (and sometimes with (user_id) after it or using the user_id as a fallback). There is now a sortable_name method for the user record that returns the last, first format falling back to only the first or only the last or the empty string.

@somiaj

somiaj commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

In testing the user menu, full_name and the other methods can return a name with only white space if the first and last name in the data base are ' '. This makes it so full_name || user_id logic may fail to show the user_id for a white space name. This is a tiny edge case, but should the methods be updated to trim the white space from first name and last name? My guess is this really isn't a problem, and something that occurs with aggressive testing, so mostly just commenting that it can happen.

@drgrice1

Copy link
Copy Markdown
Member Author

When users are added via the "Accounts Manager" we trim spaces from the first and last name. I note that we don't do that for users added via LTI. Although I think that is going to be pretty unlikely, and almost always the result of some data entry error. In any case, I updated the full_name and sortable_name methods to treat a first or last name consisting entirely of white space as not set.

@somiaj

somiaj commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Looks like the Options.pm page doesn't trim white space. I will go update that in my changes with the user menu.

drgrice1 and others added 2 commits November 12, 2026 15:50
… shown.

Several places built a user's full name by joining the first and last names
manually instead of using the `full_name` method of the user database record.
Those places now all use that method.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irst" names.

Places that displayed a user's name in "last, first" format built it manually,
and handled missing first or last names inconsistently (or not at all, which
resulted in a stray comma).  The new `sortable_name` method of the user
database record returns "last, first", or just the name that is set, or an
empty string if neither is set.

Places that show just the name fall back to the user id when the name is
empty.  Places that also show the user id in parentheses show "(user_id)"
alone when the name is empty.

Also clean up the style of the other methods in the user record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants