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

Derive Name from DisplayName #2943

Closed
kantord opened this issue Apr 4, 2024 · 1 comment · Fixed by #4335
Closed

Derive Name from DisplayName #2943

kantord opened this issue Apr 4, 2024 · 1 comment · Fixed by #4335
Labels
good first issue Good for newcomers P2 Nice to fix: non-critical items that should be evaluated and planned during issue triage user-story

Comments

@kantord
Copy link

kantord commented Apr 4, 2024

Please describe the enhancement

Name is required to be in a specific format, whereas DisplayName is more freeform. When creating something new (such as a profile) using the API, the caller needs to have a display name, and will possibly derive the name by doing certain transformation (regexp replace, trim, etc) on the display name.

This means that clients of the API might implement this logic in different ways, and the logic is duplicated within the ecosystem, increasing the overall complexity in the ecosystem.

Solution Proposal

The logic to derive Name from DisplayName could be moved to all POST endpoints in the API. This would mean that the clients don't need to directly supply the Name value when creating a new object from scratch, and this logic could be removed from all client code.

Describe alternatives you've considered

No response

Additional context

No response

Acceptance Criteria

No response

@evankanderson evankanderson added P2 Nice to fix: non-critical items that should be evaluated and planned during issue triage good first issue Good for newcomers labels Jul 16, 2024
@eleftherias
Copy link
Contributor

The description does not call this out explicitly, but let's scope this down to profile creation.

Acceptance criteria

Given a logged in Minder user
when they call ProfileService.CreateProfile
and provide a display name, but no name
then the profile name is created and saved based on the profile display name*

Given a logged in Minder user
when they call ProfileService.CreateProfile
and provide both a display name and a profile name
then the profile name from the incoming request is used as the profile name

Given a logged in Minder user
when they call ProfileService.CreateProfile
and provide both a display name and a profile name
and the project already has a profile with that name
then Minder returns an error

*Deriving the profile name from the profile display name

The profile name should be derived from the profile display name given the following logic:

  • Trim the leading and trailing whitespace from the display name
  • Remove any non-alphanumeric characters
  • Replace all whitespace with underscores
  • Turn all upper-case characters into lower-case
  • Trim the string to be a maximum length of 63 characters

If the derived profile name already exists in the same project, then we append a -1 to the end of the derived profile name (my_profile-1).
If the new name also exists in the project, then we increment the appending digit by 1 until we find a name that doesn't already exist. (my_profile-2, my_profile-3 etc)

Examples

Below are some examples of profile names derived from profile display names.
"My custom profile" -> "my_custom_profile"
"A very long profile name that is longer than sixty three characters and will be trimmed" -> "a_very_long_profile_name_that_is_longer_than_sixty_three_charac"
"Profile with !#$() characters" -> "profile_with_characters"
"My 1st Profile" -> "my_1st_profile"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers P2 Nice to fix: non-critical items that should be evaluated and planned during issue triage user-story
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants