ctm / mb2-doc

Mb2, poker software
https://devctm.com
7 stars 2 forks source link

DieselNewType(Nick) may have implications #1365

Closed ctm closed 3 months ago

ctm commented 3 months ago

Stop using DieselNewType on Nick.

I'm adding Nick as the type for nicknames. The constructor is fairly strict and prevents Zalgoed text, as well as other things as nicknames. As such, nothing currently unacceptable can be used for logging in or creating accounts, which means the nicknames logged have to pass the constructor. However, if we tighten the rules, there will be nothing that will prevent us from pulling something out of the database that's not allowed, because DieselNewType bypasses the constructor.

So, instead of using DieselNewType, we need to implement the various Diesel traits ourselves and we also need to be sure that nothing breaks if we try to pull out data that can't be converted from the Text to Nick.

ctm commented 3 months ago

I think pulling DieselNewType from Nick makes sense and all I need to do is make a DieselNewType DieselNick and then I'll have to write the glue to convert from DieselNick to Nick.

ctm commented 3 months ago

I did a bunch of this work of work on this earlier this evening. I'd like to be able to use &Nick for inserts since inserting a Nick is safe, but I haven't figured a nice way to be able to do so. Obviously, I can turn a &Nick into a DieselNick, but that requires a copy that I'd prefer to avoid on principle.

ctm commented 3 months ago

D'oh. I can just use Insertable structs that use &str but whose constructors only take Nicks. Then as_ref can be used to populate the structs.

ctm commented 3 months ago

Done and merged to master. I can't deploy from here, but it'll go out with the next deploy.

ctm commented 3 months ago

Deploying now.