-
-
Notifications
You must be signed in to change notification settings - Fork 967
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
base: 7.1.x
Are you sure you want to change the base?
Changes from all commits
39f1d0e
4d7a5dc
71f7c09
ebf2912
232cfea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The library being changed here doesn't have anything to do with scaffolding. Wouldn't it be better to introduce a constraint specific to scaffolding? The more I think about this this seems very view-centric and it's being added to the domain layer. This just feels wrong from a separation perspective.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jdaugherty I am just expanding on the existing constraint which currently supports true/false and actually fixing it for when true is set. it can now be a boolean or an enum value. |
||
| * | ||
| * <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 | ||
|
|
||
| } | ||
| 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 | ||
| } | ||
| } |
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.