-
-
Notifications
You must be signed in to change notification settings - Fork 969
7.1.x Scaffolding Display Constraint Expansion #15266
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
Open
codeconsole
wants to merge
5
commits into
apache:7.1.x
Choose a base branch
from
codeconsole:7.1.x-display-constraint
base: 7.1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39f1d0e
display constraint expansion
codeconsole 4d7a5dc
Change DisplayType.INPUT/OUTPUT to DisplayType.INPUT/OUTPUT_ONLY
codeconsole 71f7c09
update documentation for display constraint
codeconsole ebf2912
add documentation to upgrade guide
codeconsole 232cfea
Merge branch '7.1.x' into 7.1.x-display-constraint
codeconsole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
grails-datamapping-validation/src/main/groovy/grails/gorm/validation/DisplayType.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package grails.gorm.validation | ||
|
|
||
| /** | ||
| * Enum representing the display behavior for a constrained property in scaffolded views. | ||
jdaugherty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * <p>This enum controls where a property is displayed in generated scaffolding views:</p> | ||
| * <ul> | ||
| * <li>{@link #ALL} - Display everywhere, including overriding default blacklists (e.g., dateCreated, lastUpdated)</li> | ||
| * <li>{@link #NONE} - Never display in any view</li> | ||
| * <li>{@link #INPUT_ONLY} - Display only in input forms (create/edit views)</li> | ||
| * <li>{@link #OUTPUT_ONLY} - Display only in output views (show/index views)</li> | ||
| * </ul> | ||
| * | ||
| * <p>Example usage in domain class constraints:</p> | ||
| * <pre> | ||
| * import static grails.gorm.validation.DisplayType.* | ||
| * | ||
| * class Book { | ||
| * String title | ||
| * Date dateCreated | ||
| * String internalNotes | ||
| * | ||
| * static constraints = { | ||
| * dateCreated display: ALL // Override blacklist, show everywhere | ||
| * internalNotes display: NONE // Never show | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * | ||
| * <p>For backwards compatibility, boolean values are also supported:</p> | ||
| * <ul> | ||
| * <li>{@code display: true} is equivalent to the default behavior (not setting display)</li> | ||
| * <li>{@code display: false} is equivalent to {@link #NONE}</li> | ||
| * </ul> | ||
| * | ||
| * @author Scott Murphy Heiberg | ||
| * @since 7.1 | ||
| */ | ||
| enum DisplayType { | ||
|
|
||
| /** | ||
| * Display the property in all views (input and output). | ||
| * This also overrides the default blacklist for properties like dateCreated and lastUpdated. | ||
| */ | ||
| ALL, | ||
|
|
||
| /** | ||
| * Never display the property in any view. | ||
| */ | ||
| NONE, | ||
|
|
||
| /** | ||
| * Display the property only in input views (create and edit forms). | ||
| */ | ||
| INPUT_ONLY, | ||
|
|
||
| /** | ||
| * Display the property only in output views (show and index/list views). | ||
| */ | ||
| OUTPUT_ONLY | ||
|
|
||
| } | ||
151 changes: 151 additions & 0 deletions
151
grails-datamapping-validation/src/test/groovy/grails/gorm/validation/DisplayTypeSpec.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package grails.gorm.validation | ||
|
|
||
| import org.grails.datastore.gorm.validation.constraints.registry.DefaultConstraintRegistry | ||
| import spock.lang.Specification | ||
|
|
||
| class DisplayTypeSpec extends Specification { | ||
|
|
||
| DefaultConstrainedProperty constrainedProperty | ||
|
|
||
| void setup() { | ||
| constrainedProperty = new DefaultConstrainedProperty( | ||
| TestDomain, | ||
| "testProperty", | ||
| String, | ||
| new DefaultConstraintRegistry() | ||
| ) | ||
| } | ||
|
|
||
| void "test default displayType is null"() { | ||
| expect: | ||
| constrainedProperty.displayType == null | ||
| } | ||
|
|
||
| void "test default isDisplay returns true"() { | ||
| expect: | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| void "test setDisplay with boolean false sets displayType to NONE"() { | ||
| when: | ||
| constrainedProperty.setDisplay(false) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.NONE | ||
| constrainedProperty.display == false | ||
| } | ||
|
|
||
| void "test setDisplay with boolean true sets displayType to null"() { | ||
| when: | ||
| constrainedProperty.setDisplay(true) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == null | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| void "test setDisplay with DisplayType.ALL"() { | ||
| when: | ||
| constrainedProperty.setDisplay(DisplayType.ALL) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.ALL | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| void "test setDisplay with DisplayType.NONE"() { | ||
| when: | ||
| constrainedProperty.setDisplay(DisplayType.NONE) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.NONE | ||
| constrainedProperty.display == false | ||
| } | ||
|
|
||
| void "test setDisplay with DisplayType.INPUT_ONLY"() { | ||
| when: | ||
| constrainedProperty.setDisplay(DisplayType.INPUT_ONLY) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.INPUT_ONLY | ||
| constrainedProperty.display == true // isDisplay still returns true for INPUT_ONLY | ||
| } | ||
|
|
||
| void "test setDisplay with DisplayType.OUTPUT_ONLY"() { | ||
| when: | ||
| constrainedProperty.setDisplay(DisplayType.OUTPUT_ONLY) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.OUTPUT_ONLY | ||
| constrainedProperty.display == true // isDisplay still returns true for OUTPUT_ONLY | ||
| } | ||
|
|
||
| void "test setDisplay with null resets to default"() { | ||
| given: | ||
| constrainedProperty.setDisplay(DisplayType.NONE) | ||
|
|
||
| when: | ||
| constrainedProperty.setDisplay(null) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == null | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| void "test setDisplay with invalid type throws exception"() { | ||
| when: | ||
| constrainedProperty.setDisplay("invalid") | ||
|
|
||
| then: | ||
| thrown(IllegalArgumentException) | ||
| } | ||
|
|
||
| void "test applyConstraint with display false sets displayType to NONE"() { | ||
| when: | ||
| constrainedProperty.applyConstraint("display", false) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.NONE | ||
| constrainedProperty.display == false | ||
| } | ||
|
|
||
| void "test applyConstraint with display true sets displayType to null"() { | ||
| when: | ||
| constrainedProperty.applyConstraint("display", true) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == null | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| void "test applyConstraint with DisplayType enum"() { | ||
| when: | ||
| constrainedProperty.applyConstraint("display", DisplayType.INPUT_ONLY) | ||
|
|
||
| then: | ||
| constrainedProperty.displayType == DisplayType.INPUT_ONLY | ||
| constrainedProperty.display == true | ||
| } | ||
|
|
||
| static class TestDomain { | ||
| String testProperty | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to date, everything has been an optional / minor breaking change. But changing constrained means that this will be a breaking change, no? @matrei what are your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdaugherty is adding a constraint breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the constraint isn't, but changing the base interface that's applied to every object I assume would be breaking. We need to test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbglasius is going to test this change with his side project to ensure it's backwards compatible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should test this, we don't want to have to recompile/re-release plugins for 7.1 compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out, I'm implementing
grails.gorm.validation.Constraintand notgrails.gorm.validation.ConstrainedI think it would be best, if @codeconsole makes a
Constrainedimplementation with 7.0.4 and run it with 7.1.0-SNAPSHOTOr direct me on how to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbglasius I think the real concern is this being a breaking change across domain objects for 7.x.
If you have your plugin with a domain class on 7.0.4, and you have your application on 7.1, what happens when you call
findConstrainedProperties(Holders.grailsApplication.mappingContext.getPersistentEntity(MyDomain.class))in your application? If it works, this isnt' a breaking change, if it doesn't, it is.