core: fix error when raising SkipObject in mapping (#10153) * core: fix error when raising SkipObject in mapping * fix events not being saved thanks tests --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens L <jens@goauthentik.io>
This commit is contained in:
		![98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com](/assets/img/avatar_default.png) gcp-cherry-pick-bot[bot]
					gcp-cherry-pick-bot[bot]
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							7b7a7e3073
						
					
				
				
					commit
					9ea517d606
				
			| @ -76,8 +76,11 @@ class PropertyMappingEvaluator(BaseEvaluator): | |||||||
|         ) |         ) | ||||||
|         if "request" in self._context: |         if "request" in self._context: | ||||||
|             req: PolicyRequest = self._context["request"] |             req: PolicyRequest = self._context["request"] | ||||||
|             event.from_http(req.http_request, req.user) |             if req.http_request: | ||||||
|             return |                 event.from_http(req.http_request, req.user) | ||||||
|  |                 return | ||||||
|  |             elif req.user: | ||||||
|  |                 event.set_user(req.user) | ||||||
|         event.save() |         event.save() | ||||||
|  |  | ||||||
|     def evaluate(self, *args, **kwargs) -> Any: |     def evaluate(self, *args, **kwargs) -> Any: | ||||||
|  | |||||||
| @ -16,3 +16,7 @@ class SkipObjectException(PropertyMappingExpressionException): | |||||||
|     """Exception which can be raised in a property mapping to skip syncing an object. |     """Exception which can be raised in a property mapping to skip syncing an object. | ||||||
|     Only applies to Property mappings which sync objects, and not on mappings which transitively |     Only applies to Property mappings which sync objects, and not on mappings which transitively | ||||||
|     apply to a single user""" |     apply to a single user""" | ||||||
|  |  | ||||||
|  |     def __init__(self) -> None: | ||||||
|  |         # For this class only, both of these are set by the function evaluating the property mapping | ||||||
|  |         super().__init__(exc=None, mapping=None) | ||||||
|  | |||||||
| @ -4,7 +4,10 @@ from django.db.models import QuerySet | |||||||
| from django.http import HttpRequest | from django.http import HttpRequest | ||||||
|  |  | ||||||
| from authentik.core.expression.evaluator import PropertyMappingEvaluator | from authentik.core.expression.evaluator import PropertyMappingEvaluator | ||||||
| from authentik.core.expression.exceptions import PropertyMappingExpressionException | from authentik.core.expression.exceptions import ( | ||||||
|  |     PropertyMappingExpressionException, | ||||||
|  |     SkipObjectException, | ||||||
|  | ) | ||||||
| from authentik.core.models import PropertyMapping, User | from authentik.core.models import PropertyMapping, User | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -57,6 +60,10 @@ class PropertyMappingManager: | |||||||
|             mapping.set_context(user, request, **kwargs) |             mapping.set_context(user, request, **kwargs) | ||||||
|             try: |             try: | ||||||
|                 value = mapping.evaluate(mapping.model.expression) |                 value = mapping.evaluate(mapping.model.expression) | ||||||
|  |             except SkipObjectException as exc: | ||||||
|  |                 exc.exc = exc | ||||||
|  |                 exc.mapping = mapping | ||||||
|  |                 raise exc from exc | ||||||
|             except PropertyMappingExpressionException as exc: |             except PropertyMappingExpressionException as exc: | ||||||
|                 raise exc from exc |                 raise exc from exc | ||||||
|             except Exception as exc: |             except Exception as exc: | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user