@Test public void testSpecificFieldExpressionText() { @Entity @Include @UpdatePermission(expression = "user has no access") class Model { @Id private long id; @UpdatePermission(expression = "user has all access OR user has no access") private int foo; } dictionary.bindEntity(Model.class); PersistentResource resource = newResource(new Model(), Model.class); ChangeSpec changes = new ChangeSpec(resource, "foo", 1, 2); Expression expression = builder.buildSpecificFieldExpressions( resource, UpdatePermission.class, "foo", changes); assertEquals( "UPDATE PERMISSION WAS INVOKED ON PersistentResource{type=model, id=0} WITH CHANGES ChangeSpec { " + "resource=PersistentResource{type=model, id=0}, field=foo, original=1, modified=2} " + "FOR EXPRESSION [FIELD(((user has all access " + "\u001B[34mWAS UNEVALUATED\u001B[m)) OR ((user has no access " + "\u001B[34mWAS UNEVALUATED\u001B[m)))]", expression.toString()); expression.evaluate(Expression.EvaluationMode.ALL_CHECKS); assertEquals( "UPDATE PERMISSION WAS INVOKED ON PersistentResource{type=model, id=0} WITH CHANGES ChangeSpec { " + "resource=PersistentResource{type=model, id=0}, field=foo, original=1, modified=2} " + "FOR EXPRESSION [FIELD(((user has all access " + "\u001B[32mPASSED\u001B[m)) OR ((user has no access " + "\u001B[34mWAS UNEVALUATED\u001B[m)))]", expression.toString()); }
public <A extends Annotation> Expression buildSpecificFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final String field, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> buildExpressionFn = (checkFn) -> buildSpecificFieldExpression( PermissionCondition.create(annotationClass, resource, field, changeSpec), checkFn ); return buildExpressionFn.apply(leafBuilderFn); }
PermissionExpressionBuilder implements CheckInstantiator { public <A extends Annotation> Expression buildSpecificFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final String field, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> buildExpressionFn = (checkFn) -> buildSpecificFieldExpression( PermissionCondition.create(annotationClass, resource, field, changeSpec), checkFn ); return buildExpressionFn.apply(leafBuilderFn); } }
PermissionExpressionBuilder implements CheckInstantiator { public <A extends Annotation> Expression buildSpecificFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final String field, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> buildExpressionFn = (checkFn) -> buildSpecificFieldExpression( PermissionCondition.create(annotationClass, resource, field, changeSpec), checkFn ); return buildExpressionFn.apply(leafBuilderFn); } PermissionExpressionBuilder(ExpressionResultCache cache, EntityDictionary dictionary); }
PermissionExpressionBuilder implements CheckInstantiator { public <A extends Annotation> Expression buildSpecificFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final String field, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> buildExpressionFn = (checkFn) -> buildSpecificFieldExpression( PermissionCondition.create(annotationClass, resource, field, changeSpec), checkFn ); return buildExpressionFn.apply(leafBuilderFn); } PermissionExpressionBuilder(ExpressionResultCache cache, EntityDictionary dictionary); Expression buildSpecificFieldExpressions(final PersistentResource resource,
                                                                           final Class<A> annotationClass,
                                                                           final String field,
                                                                           final ChangeSpec changeSpec); Expression buildAnyFieldExpressions(final PersistentResource resource,
                                                                       final Class<A> annotationClass,
                                                                       final ChangeSpec changeSpec); Expression buildUserCheckFieldExpressions(final Class<?> resourceClass,
                                                                             final RequestScope scope,
                                                                             final Class<A> annotationClass,
                                                                             final String field); Expression buildUserCheckAnyExpression(final Class<?> resourceClass,
                                                                         final Class<A> annotationClass,
                                                                         final RequestScope requestScope); FilterExpression buildAnyFieldFilterExpression(Class<?> forType, RequestScope requestScope); }
PermissionExpressionBuilder implements CheckInstantiator { public <A extends Annotation> Expression buildSpecificFieldExpressions(final PersistentResource resource, final Class<A> annotationClass, final String field, final ChangeSpec changeSpec) { Class<?> resourceClass = resource.getResourceClass(); if (!entityDictionary.entityHasChecksForPermission(resourceClass, annotationClass)) { return SUCCESSFUL_EXPRESSION; } final Function<Check, Expression> leafBuilderFn = leafBuilder(resource, changeSpec); final Function<Function<Check, Expression>, Expression> buildExpressionFn = (checkFn) -> buildSpecificFieldExpression( PermissionCondition.create(annotationClass, resource, field, changeSpec), checkFn ); return buildExpressionFn.apply(leafBuilderFn); } PermissionExpressionBuilder(ExpressionResultCache cache, EntityDictionary dictionary); Expression buildSpecificFieldExpressions(final PersistentResource resource,
                                                                           final Class<A> annotationClass,
                                                                           final String field,
                                                                           final ChangeSpec changeSpec); Expression buildAnyFieldExpressions(final PersistentResource resource,
                                                                       final Class<A> annotationClass,
                                                                       final ChangeSpec changeSpec); Expression buildUserCheckFieldExpressions(final Class<?> resourceClass,
                                                                             final RequestScope scope,
                                                                             final Class<A> annotationClass,
                                                                             final String field); Expression buildUserCheckAnyExpression(final Class<?> resourceClass,
                                                                         final Class<A> annotationClass,
                                                                         final RequestScope requestScope); FilterExpression buildAnyFieldFilterExpression(Class<?> forType, RequestScope requestScope); static final Expression FAIL_EXPRESSION; }