From 65e651c05bfdd38d826b6489164075e0c0ab31a2 Mon Sep 17 00:00:00 2001 From: James Fredley Date: Mon, 19 Aug 2024 10:47:02 -0400 Subject: [PATCH 01/11] Grails 6.2.1 compatible Grails Profile Snapshots --- grails-bom/profiles.properties | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grails-bom/profiles.properties b/grails-bom/profiles.properties index ccf86d4712a..8a1559f1cbe 100644 --- a/grails-bom/profiles.properties +++ b/grails-bom/profiles.properties @@ -1,10 +1,10 @@ -rest-api=5.0.1 -base=5.1.1 -web=5.0.5 -react=5.0.1 -vue=5.0.3 -plugin=5.0.1 -profile=5.0.2 -rest-api-plugin=5.0.1 -web-plugin=4.0.1 -angular=8.0.2 +rest-api=6.0.0-SNAPSHOT +base=6.0.0-SNAPSHOT +web=6.0.0-SNAPSHOT +react=6.0.0-SNAPSHOT +vue=6.0.0-SNAPSHOT +plugin=6.0.0-SNAPSHOT +profile=6.0.0-SNAPSHOT +rest-api-plugin=6.0.0-SNAPSHOT +web-plugin=6.0.0-SNAPSHOT +angular=9.0.0-SNAPSHOT From 7cd2e81d62ebde933c3875cc6df950bcd6147eff Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 7 Sep 2024 16:06:07 -0700 Subject: [PATCH 02/11] Support controller attribute in tags with resource attribute. Fixes #13627 --- .../groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index 14de639d420..2c8386cbe7f 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -189,7 +189,7 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware { } } List tokens = resource.contains('/') ? resource.tokenize('/') :[resource] - controller = tokens[-1] + controller = controllerAttribute?:tokens[-1] if (tokens.size()>1) { for(t in tokens[0..-2]) { final key = "${t}Id".toString() From 7b13fd09b5eb8cc6fb8c652f4cd78c0869251aa8 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sun, 8 Sep 2024 16:06:11 -0700 Subject: [PATCH 03/11] Fix for when domain classes have a static id mapping to another property that is not id. e.g. static mapping = { id: name: 'customId' } --- .../grails/web/mapping/DefaultLinkGenerator.groovy | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index 2c8386cbe7f..e8f34611069 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -291,6 +291,17 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware { @CompileStatic(TypeCheckingMode.SKIP) protected String getResourceId(resourceAttribute) { + try { + // Alternative is to check instanceof GormEntity, but that would require coupling + // web-common to grails-datastore-gorm + def ident = resourceAttribute.ident().toString() + if (ident) { + return ident.toString() + } + } catch (MissingMethodException | IllegalStateException e) { + // An IllegalStateException occurs if GORM is not initialized. + } + final id = resourceAttribute.id if (id) { return id.toString() From 4a0ea2bb3dcc4dd7c2e778b6f82b91926eff1d7b Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Mon, 9 Sep 2024 09:43:00 -0700 Subject: [PATCH 04/11] Document options. Remove accidental toString() --- .../org/grails/web/mapping/DefaultLinkGenerator.groovy | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index e8f34611069..5f1516fe6a6 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -292,14 +292,17 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware { @CompileStatic(TypeCheckingMode.SKIP) protected String getResourceId(resourceAttribute) { try { - // Alternative is to check instanceof GormEntity, but that would require coupling - // web-common to grails-datastore-gorm - def ident = resourceAttribute.ident().toString() + // Three options for using indent(): + // 1. Check instanceof GormEntity, but that would require coupling web-common to grails-datastore-gorm + // 2. GrailsMetaClassUtils.invokeMethodIfExists(o, "ident", new Object[0]); Slow? + // 3. Just assuming resource is a GormEntity and catching an exception if it is not. + def ident = resourceAttribute.ident() if (ident) { return ident.toString() } } catch (MissingMethodException | IllegalStateException e) { // An IllegalStateException occurs if GORM is not initialized. + // A MissingMethodException if it is not a GormEntity } final id = resourceAttribute.id From 807a6d6d2ec783ded396c8e56d09a69d0bb13405 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Mon, 9 Sep 2024 11:18:40 -0700 Subject: [PATCH 05/11] update comment --- .../groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index 5f1516fe6a6..7d9343ec7f6 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -295,7 +295,7 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware { // Three options for using indent(): // 1. Check instanceof GormEntity, but that would require coupling web-common to grails-datastore-gorm // 2. GrailsMetaClassUtils.invokeMethodIfExists(o, "ident", new Object[0]); Slow? - // 3. Just assuming resource is a GormEntity and catching an exception if it is not. + // 3. Just assuming resource is a GormEntity or has ident() implemented and catching an exception if it is not. def ident = resourceAttribute.ident() if (ident) { return ident.toString() From 1dd266e2675082e7012c8739986be876afe07f14 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Mon, 9 Sep 2024 12:24:25 -0700 Subject: [PATCH 06/11] Add unit test for #13627 --- .../web/mapping/LinkGeneratorSpec.groovy | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy index 77ce45e3d78..d58d63ba2fe 100644 --- a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy +++ b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy @@ -1,5 +1,6 @@ package org.grails.web.mapping +import grails.artefact.Artefact import grails.core.DefaultGrailsApplication import grails.plugins.DefaultGrailsPluginManager import grails.util.GrailsWebMockUtil @@ -289,6 +290,29 @@ class LinkGeneratorSpec extends Specification { cacheKey == "somePrefix[resource:org.grails.web.mapping.Widget->2]" } + // + def 'resource links should use ident and allow controller override'() { + given: + final webRequest = GrailsWebMockUtil.bindMockWebRequest() + MockHttpServletRequest request = webRequest.currentRequest + linkParams.method = 'GET' + + when: 'a resource is specified, ident() is used for id' + linkParams.resource = new Widget(id: 1, name: 'Some Widget') + + then: + link == "/bar/widget/1/show" + + then: + linkParams.resource.identCalled + + when: "A controller is specified" + linkParams.controller = 'widgetAdmin' + + then: + link == "/bar/widgetAdmin/1/show" + } + def 'link should take into affect namespace'() { given: final webRequest = GrailsWebMockUtil.bindMockWebRequest() @@ -341,7 +365,8 @@ class LinkGeneratorSpec extends Specification { def generator = cache ? new CachingLinkGenerator(baseUrl, context) : new DefaultLinkGenerator(baseUrl, context) final callable = { String controller, String action, String namespace, String pluginName, String httpMethod, Map params -> [createRelativeURL: { String c, String a, String n, String p, Map parameterValues, String encoding, String fragment -> - "${namespace ? '/' + namespace : ''}/$controller/$action".toString() + + "${namespace ? '/' + namespace : ''}/$controller${parameterValues.id? '/'+parameterValues.id:''}/$action".toString() }] as UrlCreator } generator.grailsUrlConverter = new CamelCaseUrlConverter() @@ -381,11 +406,14 @@ class LinkGeneratorSpec extends Specification { } } +@Artefact('Domain') class Widget { Long id String name + boolean identCalled = false Long ident() { + identCalled = true id } From 72ab5f84a55d33fb80b3feb7756b081e8971f5f2 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Tue, 10 Sep 2024 10:19:58 -0700 Subject: [PATCH 07/11] Add link to github issue --- .../test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy index d58d63ba2fe..38b3549f611 100644 --- a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy +++ b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy @@ -290,7 +290,7 @@ class LinkGeneratorSpec extends Specification { cacheKey == "somePrefix[resource:org.grails.web.mapping.Widget->2]" } - // + @Issue('https://github.com/grails/grails-core/issues/13627') def 'resource links should use ident and allow controller override'() { given: final webRequest = GrailsWebMockUtil.bindMockWebRequest() From 16ec0c1b8060252620fcd1c46fef6c5599361a8f Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Tue, 10 Sep 2024 10:22:04 -0700 Subject: [PATCH 08/11] Update copyright --- .../groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index 7d9343ec7f6..61d5ae37af1 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2011 SpringSource + * Copyright 2011-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From f0602de754fc7ebcfe452c66113c91dd438a2d4e Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Tue, 10 Sep 2024 10:24:09 -0700 Subject: [PATCH 09/11] change exception variable to ignored --- .../groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy index 61d5ae37af1..40aa581c6be 100644 --- a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy +++ b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultLinkGenerator.groovy @@ -300,7 +300,7 @@ class DefaultLinkGenerator implements LinkGenerator, PluginManagerAware { if (ident) { return ident.toString() } - } catch (MissingMethodException | IllegalStateException e) { + } catch (MissingMethodException | IllegalStateException ignored) { // An IllegalStateException occurs if GORM is not initialized. // A MissingMethodException if it is not a GormEntity } From bf6a0c35d19c4b208086d2f44a0612d6d3e06fe7 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Tue, 10 Sep 2024 13:32:34 -0700 Subject: [PATCH 10/11] Change from resources mapping to default mapping --- .../groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy index 38b3549f611..75e498c2d53 100644 --- a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy +++ b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/LinkGeneratorSpec.groovy @@ -301,7 +301,7 @@ class LinkGeneratorSpec extends Specification { linkParams.resource = new Widget(id: 1, name: 'Some Widget') then: - link == "/bar/widget/1/show" + link == "/bar/widget/show/1" then: linkParams.resource.identCalled @@ -310,7 +310,7 @@ class LinkGeneratorSpec extends Specification { linkParams.controller = 'widgetAdmin' then: - link == "/bar/widgetAdmin/1/show" + link == "/bar/widgetAdmin/show/1" } def 'link should take into affect namespace'() { @@ -366,7 +366,7 @@ class LinkGeneratorSpec extends Specification { final callable = { String controller, String action, String namespace, String pluginName, String httpMethod, Map params -> [createRelativeURL: { String c, String a, String n, String p, Map parameterValues, String encoding, String fragment -> - "${namespace ? '/' + namespace : ''}/$controller${parameterValues.id? '/'+parameterValues.id:''}/$action".toString() + "${namespace ? '/' + namespace : ''}/$controller/$action${parameterValues.id? '/'+parameterValues.id:''}".toString() }] as UrlCreator } generator.grailsUrlConverter = new CamelCaseUrlConverter() From 33bddf787ea27ee1ac847d46389e07b80402679f Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Fri, 13 Sep 2024 17:25:41 -0700 Subject: [PATCH 11/11] Update profiles --- grails-bom/profiles.properties | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/grails-bom/profiles.properties b/grails-bom/profiles.properties index 8a1559f1cbe..9d04a641538 100644 --- a/grails-bom/profiles.properties +++ b/grails-bom/profiles.properties @@ -1,10 +1,10 @@ -rest-api=6.0.0-SNAPSHOT -base=6.0.0-SNAPSHOT -web=6.0.0-SNAPSHOT -react=6.0.0-SNAPSHOT -vue=6.0.0-SNAPSHOT -plugin=6.0.0-SNAPSHOT -profile=6.0.0-SNAPSHOT -rest-api-plugin=6.0.0-SNAPSHOT -web-plugin=6.0.0-SNAPSHOT -angular=9.0.0-SNAPSHOT +rest-api=7.0.0-SNAPSHOT +base=7.0.0-SNAPSHOT +web=7.0.0-SNAPSHOT +react=7.0.0-SNAPSHOT +vue=7.0.0-SNAPSHOT +plugin=7.0.0-SNAPSHOT +profile=7.0.0-SNAPSHOT +rest-api-plugin=7.0.0-SNAPSHOT +web-plugin=7.0.0-SNAPSHOT +angular=10.0.0-SNAPSHOT