setup-your-mac / Setup-Your-Mac

Setup Your Mac aims to simplify initial device configuration by leveraging swiftDialog and Jamf Pro Policy Custom Events to allow end-users to self-complete Mac setup post-enrollment.
https://snelson.us/sym
MIT License
246 stars 54 forks source link

Adding forced capitalize for AssetTag #53

Closed bizzare closed 1 year ago

bizzare commented 1 year ago

I wanted to allow users to enter asset tags like "P12345" or "p12345" but still have them end up with a capital P. Using the regex i just tell users to use the capital, but with this change we can allow them to type lowercase or not and capture it as capital.

Added: capitalizeAssetTag="true" option to allow to flag if the asset tag should be forced to be capital letters. Aso The if statement to check for the flag, if "true" then we use tr to bring letters from lower case to upper case.

This allows the use of a case insensitive regex in the json for the assettag and users dont have to worry about capitalizing the letters.

Not sure the location of the capital option, but the user input boxes section seemed right, right next to the assetag option

bizzare commented 1 year ago

After submitting this, thinking it could be changed to allow "upper" or "lower" as options. Otherwise, "false" would just leave the value as is. The if statement would just have to be expanded a little

dan-snelson commented 1 year ago

Thanks, @bizzare!

dan-snelson commented 1 year ago

@bizzare: Just skimming this between meetings, doesn't this defeat the purpose of a regex ?

bizzare commented 1 year ago

@dan-snelson Thanks for reviewing.

Almost, but not completely.

    "regex" : "^(?i)(ACME)?[0-9]{5,}$",

This allows the users to type "acme12345" or "ACME12345" or "Acme12345" or "12345"

Currently I do not mind if users use ACME12345 or 12345, though I do not want "AcME12345" or"acme12345"

I have found in my own testing that I enter lowercase letters by default, get caught by the regex, then have to enter the capital letters and move on. I like the idea of allowing users to enter the lowercase/uppercase letters but forcing the admins preferred format. Lets the users have little more flexibility in entering while ultimately respecting what the admins want.

Probably a bit of a niche and nit-picky change ha!

dan-snelson commented 1 year ago

I'm no regex ninja, but would this meet your use-case?

[A][C][M][E]?[0-9]{5,}$

Screenshot 2023-05-09 at 2 21 54 PM