You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2026/08/24 19:08:14 UTC

(causeway) branch main updated: CAUSEWAY-4050: adds missing visibility consent handlers to simple assoc. fetchers

This is an automated email from the ASF dual-hosted git repository.

andi-huber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/main by this push:
     new c01d1a459ee CAUSEWAY-4050: adds missing visibility consent handlers to simple assoc. fetchers
c01d1a459ee is described below

commit c01d1a459eeeb5a822b4dd0df208d6731612f595
Author: andi-huber <ah...@apache.org>
AuthorDate: Mon Aug 24 21:08:04 2026 +0200

    CAUSEWAY-4050: adds missing visibility consent handlers to simple assoc.
    fetchers
---
 .../model/domain/simple/query/SimpleAction.java    |  4 +-
 .../domain/simple/query/SimpleCollection.java      | 20 +++++---
 .../model/domain/simple/query/SimpleProperty.java  | 50 +++++++++++---------
 viewers/graphql/test/src/test/resources/schema.gql | 53 ----------------------
 4 files changed, 44 insertions(+), 83 deletions(-)

diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleAction.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleAction.java
index f21997c9dce..b28f9e40347 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleAction.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleAction.java
@@ -317,7 +317,9 @@ protected Object fetchData(final DataFetchingEnvironment dataFetchingEnvironment
 			throw new IllegalArgumentException(validityConsent.getReasonAsString().orElse("Invalid"));
 
         var resultManagedObject = objectAction.execute(head, argumentManagedObjects, InteractionInitiatedBy.USER);
-        return resultManagedObject.getPojo();
+        return resultManagedObject != null
+                ? resultManagedObject.getPojo()
+                : null;
     }
 
 }
diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleCollection.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleCollection.java
index db7b38852c1..ce398d32bf4 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleCollection.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleCollection.java
@@ -18,17 +18,20 @@
  */
 package org.apache.causeway.viewer.graphql.model.domain.simple.query;
 
-import graphql.schema.DataFetchingEnvironment;
-
 import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
 
+import org.apache.causeway.applib.annotation.Where;
+import org.apache.causeway.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
 import org.apache.causeway.viewer.graphql.model.context.Context;
 import org.apache.causeway.viewer.graphql.model.domain.Element;
 import org.apache.causeway.viewer.graphql.model.domain.common.interactors.ObjectInteractor;
+import org.apache.causeway.viewer.graphql.model.exceptions.HiddenException;
 import org.apache.causeway.viewer.graphql.model.fetcher.BookmarkedPojo;
 
+import graphql.schema.DataFetchingEnvironment;
+
 public class SimpleCollection
         extends Element {
 
@@ -64,19 +67,22 @@ public String getId() {
     @Override
     protected Object fetchData(final DataFetchingEnvironment environment) {
 
+    	var coll = objectMember;
         var sourcePojo = BookmarkedPojo.sourceFrom(environment);
 
         var sourcePojoClass = sourcePojo.getClass();
         var objectSpecification = context.specificationLoader.loadSpecification(sourcePojoClass);
-        if (objectSpecification == null) {
-            // not expected
+        if (objectSpecification == null)
+			// not expected
             return null;
-        }
 
-        var otma = objectMember;
         var managedObject = ManagedObject.adaptSingular(objectSpecification, sourcePojo);
-        var resultManagedObject = otma.get(managedObject);
 
+        var visibleConsent = coll.isVisible(managedObject, InteractionInitiatedBy.USER, Where.ANYWHERE);
+        if (visibleConsent.isVetoed())
+			throw new HiddenException(coll.getFeatureIdentifier());
+
+        var resultManagedObject = coll.get(managedObject);
         return resultManagedObject != null
                 ? resultManagedObject.getPojo()
                 : null;
diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleProperty.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleProperty.java
index 28437eb031e..8ad8dd6a812 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleProperty.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/SimpleProperty.java
@@ -21,8 +21,10 @@
 import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
 import static graphql.schema.GraphQLObjectType.newObject;
 
+import org.apache.causeway.applib.annotation.Where;
 import org.apache.causeway.applib.value.Blob;
 import org.apache.causeway.applib.value.Clob;
+import org.apache.causeway.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
 import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
@@ -33,6 +35,7 @@
 import org.apache.causeway.viewer.graphql.model.domain.TypeNames;
 import org.apache.causeway.viewer.graphql.model.domain.common.interactors.MemberInteractor;
 import org.apache.causeway.viewer.graphql.model.domain.common.interactors.ObjectInteractor;
+import org.apache.causeway.viewer.graphql.model.exceptions.HiddenException;
 import org.apache.causeway.viewer.graphql.model.fetcher.BookmarkedPojo;
 
 import graphql.schema.DataFetchingEnvironment;
@@ -119,9 +122,8 @@ private static GraphQLOutputType outputType(
             return newObject()
                     .name(typeName)
                     .build();
-        } else {
-            return context.typeMapper.outputTypeFor(otoa, objectInteractor.getSchemaType());
-        }
+        } else
+			return context.typeMapper.outputTypeFor(otoa, objectInteractor.getSchemaType());
     }
 
     static <T extends Element> void addChildFieldFor(
@@ -152,37 +154,41 @@ protected void addDataFetchersForChildren() {
     @Override
     protected Object fetchData(final DataFetchingEnvironment dataFetchingEnvironment) {
 
-        if(isBlobOrClob(getObjectMember())) {
-            return BookmarkedPojo.sourceFrom(dataFetchingEnvironment, context);
-        } else {
+    	var prop = getObjectMember();
+
+        if(isBlobOrClob(prop))
+			return BookmarkedPojo.sourceFrom(dataFetchingEnvironment, context);
+		else {
             var sourcePojo = BookmarkedPojo.sourceFrom(dataFetchingEnvironment);
 
             var sourcePojoClass = sourcePojo.getClass();
             var objectSpecification = context.specificationLoader.loadSpecification(sourcePojoClass);
-            if (objectSpecification == null) {
-                // not expected
+            if (objectSpecification == null)
+				// not expected
                 return null;
-            }
 
-            var association = getObjectMember();
             var managedObject = ManagedObject.adaptSingular(objectSpecification, sourcePojo);
-            var resultManagedObject = association.get(managedObject);
 
+            var visibleConsent = prop.isVisible(managedObject, InteractionInitiatedBy.USER, Where.ANYWHERE);
+            if (visibleConsent.isVetoed())
+    			throw new HiddenException(prop.getFeatureIdentifier());
+
+            var resultManagedObject = prop.get(managedObject);
             return resultManagedObject != null
                     ? resultManagedObject.getPojo()
                     : null;
         }
     }
 
-    private static boolean isBlobOrClob(OneToOneAssociation otota) {
+    private static boolean isBlobOrClob(final OneToOneAssociation otota) {
         return isBlob(otota) || isClob(otota);
     }
 
-    private static boolean isBlob(OneToOneAssociation otoa) {
+    private static boolean isBlob(final OneToOneAssociation otoa) {
         return otoa.getElementType().correspondingClass() == Blob.class;
     }
 
-    private static boolean isClob(OneToOneAssociation otoa) {
+    private static boolean isClob(final OneToOneAssociation otoa) {
         return otoa.getElementType().correspondingClass() == Clob.class;
     }
 
@@ -196,19 +202,19 @@ public SchemaType getSchemaType() {
         return objectInteractor.getSchemaType();
     }
 
-    public final FieldCoordinates coordinatesFor(final GraphQLFieldDefinition field) {
-        if (gqlObjectType == null) {
-            throw new IllegalStateException(
+    @Override
+	public final FieldCoordinates coordinatesFor(final GraphQLFieldDefinition field) {
+        if (gqlObjectType == null)
+			throw new IllegalStateException(
                     String.format("GQL Object Type for '%s' not yet built", getTypeName()));
-        }
         return FieldCoordinates.coordinates(gqlObjectType, field);
     }
 
-    public final FieldCoordinates coordinatesFor(final String fieldName) {
-        if (gqlObjectType == null) {
-            throw new IllegalStateException(
+    @Override
+	public final FieldCoordinates coordinatesFor(final String fieldName) {
+        if (gqlObjectType == null)
+			throw new IllegalStateException(
                     String.format("GQL Object Type for '%s' not yet built", getTypeName()));
-        }
         return FieldCoordinates.coordinates(gqlObjectType, fieldName);
     }
 
diff --git a/viewers/graphql/test/src/test/resources/schema.gql b/viewers/graphql/test/src/test/resources/schema.gql
index 5170bdbfc44..cc51fedad4c 100644
--- a/viewers/graphql/test/src/test/resources/schema.gql
+++ b/viewers/graphql/test/src/test/resources/schema.gql
@@ -93,7 +93,6 @@ type RICHSchema {
   causeway_security_LogoutMenu: rich__causeway_security_LogoutMenu
   causeway_testing_fixtures_FixtureResult(object: rich__causeway_testing_fixtures_FixtureResult__gqlv_input): rich__causeway_testing_fixtures_FixtureResult
   java_lang_Record(object: rich__java_lang_Record__gqlv_input): rich__java_lang_Record
-  java_lang_Runnable(object: rich__java_lang_Runnable__gqlv_input): rich__java_lang_Runnable
   java_util_concurrent_Callable(object: rich__java_util_concurrent_Callable__gqlv_input): rich__java_util_concurrent_Callable
   java_util_function_Consumer(object: rich__java_util_function_Consumer__gqlv_input): rich__java_util_function_Consumer
   java_util_function_Function(object: rich__java_util_function_Function__gqlv_input): rich__java_util_function_Function
@@ -134,7 +133,6 @@ type SIMPLESchema {
   causeway_security_LogoutMenu: simple__causeway_security_LogoutMenu
   causeway_testing_fixtures_FixtureResult(object: simple__causeway_testing_fixtures_FixtureResult__gqlv_input): simple__causeway_testing_fixtures_FixtureResult
   java_lang_Record(object: simple__java_lang_Record__gqlv_input): simple__java_lang_Record
-  java_lang_Runnable(object: simple__java_lang_Runnable__gqlv_input): simple__java_lang_Runnable
   java_util_concurrent_Callable(object: simple__java_util_concurrent_Callable__gqlv_input): simple__java_util_concurrent_Callable
   java_util_function_Consumer(object: simple__java_util_function_Consumer__gqlv_input): simple__java_util_function_Consumer
   java_util_function_Function(object: simple__java_util_function_Function__gqlv_input): simple__java_util_function_Function
@@ -185,7 +183,6 @@ type ScenarioStep {
   causeway_security_LogoutMenu: rich__causeway_security_LogoutMenu
   causeway_testing_fixtures_FixtureResult(object: rich__causeway_testing_fixtures_FixtureResult__gqlv_input): rich__causeway_testing_fixtures_FixtureResult
   java_lang_Record(object: rich__java_lang_Record__gqlv_input): rich__java_lang_Record
-  java_lang_Runnable(object: rich__java_lang_Runnable__gqlv_input): rich__java_lang_Runnable
   java_util_concurrent_Callable(object: rich__java_util_concurrent_Callable__gqlv_input): rich__java_util_concurrent_Callable
   java_util_function_Consumer(object: rich__java_util_function_Consumer__gqlv_input): rich__java_util_function_Consumer
   java_util_function_Function(object: rich__java_util_function_Function__gqlv_input): rich__java_util_function_Function
@@ -1290,22 +1287,6 @@ type rich__java_lang_Record__gqlv_meta {
   title: String!
 }
 
-type rich__java_lang_Runnable {
-  "Object metadata"
-  _meta: rich__java_lang_Runnable__gqlv_meta
-}
-
-type rich__java_lang_Runnable__gqlv_meta {
-  cssClass: String
-  grid: String
-  icon: String
-  id: String!
-  layout: String
-  logicalTypeName: String!
-  saveAs(ref: String): String
-  title: String!
-}
-
 type rich__java_util_concurrent_Callable {
   "Object metadata"
   _meta: rich__java_util_concurrent_Callable__gqlv_meta
@@ -4879,22 +4860,6 @@ type simple__java_lang_Record__gqlv_meta {
   title: String!
 }
 
-type simple__java_lang_Runnable {
-  "Object metadata"
-  _meta: simple__java_lang_Runnable__gqlv_meta
-}
-
-type simple__java_lang_Runnable__gqlv_meta {
-  cssClass: String
-  grid: String
-  icon: String
-  id: String!
-  layout: String
-  logicalTypeName: String!
-  saveAs(ref: String): String
-  title: String!
-}
-
 type simple__java_util_concurrent_Callable {
   "Object metadata"
   _meta: simple__java_util_concurrent_Callable__gqlv_meta
@@ -5490,15 +5455,6 @@ input rich__java_lang_Record__gqlv_input {
   ref: String
 }
 
-input rich__java_lang_Runnable__gqlv_input {
-  "Use either 'id' or 'ref'; looks up an entity from the persistent data store, or if a view model, then recreates using the id as a memento of the object's state"
-  id: ID
-  "If object identified by 'id', then optionally specifies concrete type.  This is only required if the parameter type defines a super class"
-  logicalTypeName: logicalTypeNames__gqlv_enum
-  "Use either 'ref' or 'id'; looks up an object previously saved to the execution context using 'saveAs(ref: ...)'"
-  ref: String
-}
-
 input rich__java_util_concurrent_Callable__gqlv_input {
   "Use either 'id' or 'ref'; looks up an entity from the persistent data store, or if a view model, then recreates using the id as a memento of the object's state"
   id: ID
@@ -5733,15 +5689,6 @@ input simple__java_lang_Record__gqlv_input {
   ref: String
 }
 
-input simple__java_lang_Runnable__gqlv_input {
-  "Use either 'id' or 'ref'; looks up an entity from the persistent data store, or if a view model, then recreates using the id as a memento of the object's state"
-  id: ID
-  "If object identified by 'id', then optionally specifies concrete type.  This is only required if the parameter type defines a super class"
-  logicalTypeName: logicalTypeNames__gqlv_enum
-  "Use either 'ref' or 'id'; looks up an object previously saved to the execution context using 'saveAs(ref: ...)'"
-  ref: String
-}
-
 input simple__java_util_concurrent_Callable__gqlv_input {
   "Use either 'id' or 'ref'; looks up an entity from the persistent data store, or if a view model, then recreates using the id as a memento of the object's state"
   id: ID