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

Validation for @default attribute on userEntity #2311

Merged
merged 3 commits into from
Oct 1, 2024

Conversation

infomiho
Copy link
Contributor

Closes #2308

@@ -54,18 +52,15 @@ getPslModelBody = pslModelBody
getIdField :: Entity -> Maybe Psl.Model.Field
getIdField = findIdField . getPslModelBody

isFieldUnique :: String -> Entity -> Maybe Bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was unused.

[ GenericValidationError $ "Entity '" ++ userEntityName ++ "' (referenced by app.auth.userEntity) must have an ID field (specified with the '@id' attribute)"
| isNothing idFieldType
]
concat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIP: I'll rewrite this to be nicer

@infomiho infomiho force-pushed the miho-validate-user-autogenerate-attribute branch from b581339 to b43e4ad Compare September 28, 2024 02:14
@infomiho infomiho force-pushed the miho-validate-user-autogenerate-attribute branch from b43e4ad to 1c3e228 Compare September 28, 2024 02:15
@infomiho infomiho marked this pull request as ready for review September 28, 2024 02:17
isFieldUnique :: String -> Entity -> Maybe Bool
isFieldUnique fieldName = doesFieldHaveAttribute fieldName "unique"

doesFieldHaveAttribute :: String -> String -> Entity -> Maybe Bool
Copy link
Contributor Author

@infomiho infomiho Sep 30, 2024

Choose a reason for hiding this comment

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

This was a weirdly specific function which I tried to rewrite but in the end it was easier just to use the lower level helper doesPslFieldHaveAttribute directly in the one place where we needed to check if a field has an attribute.

Copy link
Member

@Martinsos Martinsos left a comment

Choose a reason for hiding this comment

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

LGTM! Left one tiny comment.

Comment on lines +132 to +137
case Entity.getIdField userEntity of
Nothing -> [userEntityMissingIdFieldError]
Just idField ->
if Psl.Util.doesPslFieldHaveAttribute "default" idField
then []
else [userEntityIdFieldMissingDefaultAttrError]
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Might be tempting to use Either here as a monad? Btw there is even this thing: https://hackage.haskell.org/package/validation .
But probably just not to complicate, it is simple enough for now, I am writing this just to give ideas for the future!

@infomiho infomiho merged commit c61f08e into main Oct 1, 2024
6 checks passed
@infomiho infomiho deleted the miho-validate-user-autogenerate-attribute branch October 1, 2024 11:54
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.

Ensure userEntity has autogenerate on the @id field
2 participants