expressions: set exception as message field
This commit is contained in:
		| @ -28,7 +28,7 @@ class PropertyMappingEvaluator(BaseEvaluator): | |||||||
|         event = Event.new( |         event = Event.new( | ||||||
|             EventAction.PROPERTY_MAPPING_EXCEPTION, |             EventAction.PROPERTY_MAPPING_EXCEPTION, | ||||||
|             expression=expression_source, |             expression=expression_source, | ||||||
|             error=error_string, |             message=error_string, | ||||||
|         ) |         ) | ||||||
|         if "user" in self._context: |         if "user" in self._context: | ||||||
|             event.set_user(self._context["user"]) |             event.set_user(self._context["user"]) | ||||||
|  | |||||||
| @ -48,12 +48,13 @@ class PolicyProcess(Process): | |||||||
|         if connection: |         if connection: | ||||||
|             self.connection = connection |             self.connection = connection | ||||||
|  |  | ||||||
|     def create_event(self, action: str, **kwargs): |     def create_event(self, action: str, message: str, **kwargs): | ||||||
|         """Create event with common values from `self.request` and `self.binding`.""" |         """Create event with common values from `self.request` and `self.binding`.""" | ||||||
|         # Keep a reference to http_request even if its None, because cleanse_dict will remove it |         # Keep a reference to http_request even if its None, because cleanse_dict will remove it | ||||||
|         http_request = self.request.http_request |         http_request = self.request.http_request | ||||||
|         event = Event.new( |         event = Event.new( | ||||||
|             action=action, |             action=action, | ||||||
|  |             message=message, | ||||||
|             policy_uuid=self.binding.policy.policy_uuid.hex, |             policy_uuid=self.binding.policy.policy_uuid.hex, | ||||||
|             binding=self.binding, |             binding=self.binding, | ||||||
|             request=self.request, |             request=self.request, | ||||||
| @ -76,7 +77,11 @@ class PolicyProcess(Process): | |||||||
|         try: |         try: | ||||||
|             policy_result = self.binding.policy.passes(self.request) |             policy_result = self.binding.policy.passes(self.request) | ||||||
|             if self.binding.policy.execution_logging: |             if self.binding.policy.execution_logging: | ||||||
|                 self.create_event(EventAction.POLICY_EXECUTION, message="Policy Execution", result=policy_result) |                 self.create_event( | ||||||
|  |                     EventAction.POLICY_EXECUTION, | ||||||
|  |                     message="Policy Execution", | ||||||
|  |                     result=policy_result, | ||||||
|  |                 ) | ||||||
|         except PolicyException as exc: |         except PolicyException as exc: | ||||||
|             # Create policy exception event |             # Create policy exception event | ||||||
|             error_string = "".join(format_tb(exc.__traceback__)) + str(exc) |             error_string = "".join(format_tb(exc.__traceback__)) + str(exc) | ||||||
|  | |||||||
| @ -1,25 +1,24 @@ | |||||||
| import { DefaultClient, QueryArguments, PBResponse } from "./Client"; | import { DefaultClient, QueryArguments, PBResponse } from "./Client"; | ||||||
|  | import { Event } from "./Events"; | ||||||
|  |  | ||||||
| export class Notification { | export class Notification { | ||||||
|     pk: string; |     pk: string; | ||||||
|     name: string; |     severity: string; | ||||||
|     mode: string; |     body: string; | ||||||
|     mode_verbose: string; |     created: string; | ||||||
|     webhook_url: string; |     event?: Event; | ||||||
|  |     seen: boolean; | ||||||
|  |  | ||||||
|     constructor() { |     constructor() { | ||||||
|         throw Error(); |         throw Error(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static get(pk: string): Promise<Transport> { |     static get(pk: string): Promise<Notification> { | ||||||
|         return DefaultClient.fetch<Transport>(["events", "transports", pk]); |         return DefaultClient.fetch<Notification>(["events", "notifications", pk]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static list(filter?: QueryArguments): Promise<PBResponse<Transport>> { |     static list(filter?: QueryArguments): Promise<PBResponse<Notification>> { | ||||||
|         return DefaultClient.fetch<PBResponse<Transport>>(["events", "transports"], filter); |         return DefaultClient.fetch<PBResponse<Notification>>(["events", "notifications"], filter); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static adminUrl(rest: string): string { |  | ||||||
|         return `/administration/events/transports/${rest}`; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| import { css, CSSResult, customElement, html, LitElement, TemplateResult } from "lit-element"; | import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; | ||||||
| // @ts-ignore | // @ts-ignore | ||||||
| import NavStyle from "@patternfly/patternfly/components/Nav/nav.css"; | import NavStyle from "@patternfly/patternfly/components/Nav/nav.css"; | ||||||
| // @ts-ignore | // @ts-ignore | ||||||
| @ -8,8 +8,11 @@ import AvatarStyle from "@patternfly/patternfly/components/Avatar/avatar.css"; | |||||||
| import { User } from "../../api/Users"; | import { User } from "../../api/Users"; | ||||||
| import { until } from "lit-html/directives/until"; | import { until } from "lit-html/directives/until"; | ||||||
|  |  | ||||||
|  | import "../notifications/NotificationTrigger"; | ||||||
|  |  | ||||||
| @customElement("ak-sidebar-user") | @customElement("ak-sidebar-user") | ||||||
| export class SidebarUser extends LitElement { | export class SidebarUser extends LitElement { | ||||||
|  |  | ||||||
|     static get styles(): CSSResult[] { |     static get styles(): CSSResult[] { | ||||||
|         return [ |         return [ | ||||||
|             fa, |             fa, | ||||||
| @ -24,19 +27,8 @@ export class SidebarUser extends LitElement { | |||||||
|                 } |                 } | ||||||
|                 .pf-c-nav__link { |                 .pf-c-nav__link { | ||||||
|                     align-items: center; |                     align-items: center; | ||||||
|                 } |  | ||||||
|                 .user-avatar { |  | ||||||
|                     display: flex; |                     display: flex; | ||||||
|                     flex-direction: row; |                     justify-content: center; | ||||||
|                 } |  | ||||||
|                 .user-avatar > span { |  | ||||||
|                     line-height: var(--pf-c-avatar--Height); |  | ||||||
|                     padding-left: var(--pf-global--spacer--sm); |  | ||||||
|                     font-size: var(--pf-global--FontSize--lg); |  | ||||||
|                 } |  | ||||||
|                 .user-logout { |  | ||||||
|                     flex-shrink: 3; |  | ||||||
|                     max-width: 75px; |  | ||||||
|                 } |                 } | ||||||
|             `, |             `, | ||||||
|         ]; |         ]; | ||||||
| @ -46,10 +38,11 @@ export class SidebarUser extends LitElement { | |||||||
|         return html` |         return html` | ||||||
|             <a href="#/-/user/" class="pf-c-nav__link user-avatar" id="user-settings"> |             <a href="#/-/user/" class="pf-c-nav__link user-avatar" id="user-settings"> | ||||||
|                 ${until(User.me().then(u => { |                 ${until(User.me().then(u => { | ||||||
|         return html`<img class="pf-c-avatar" src="${u.avatar}" alt="" /> |         return html`<img class="pf-c-avatar" src="${u.avatar}" alt="" />`;}), html``)} | ||||||
|                     <span>${u.name}</span>`; |  | ||||||
|     }), html``)} |  | ||||||
|             </a> |             </a> | ||||||
|  |             <ak-notification-trigger class="pf-c-nav__link user-notifications"> | ||||||
|  |                 <i class="fas fa-bell pf-c-dropdown__toggle-icon" aria-hidden="true"></i> | ||||||
|  |             </ak-notification-trigger> | ||||||
|             <a href="/flows/-/default/invalidation/" class="pf-c-nav__link user-logout" id="logout"> |             <a href="/flows/-/default/invalidation/" class="pf-c-nav__link user-logout" id="logout"> | ||||||
|                 <i class="fas fa-sign-out-alt" aria-hidden="true"></i> |                 <i class="fas fa-sign-out-alt" aria-hidden="true"></i> | ||||||
|             </a> |             </a> | ||||||
|  | |||||||
| @ -5,11 +5,15 @@ import { SidebarItem } from "../elements/sidebar/Sidebar"; | |||||||
| import "../elements/router/RouterOutlet"; | import "../elements/router/RouterOutlet"; | ||||||
| import "../elements/messages/MessageContainer"; | import "../elements/messages/MessageContainer"; | ||||||
| import "../elements/sidebar/SidebarHamburger"; | import "../elements/sidebar/SidebarHamburger"; | ||||||
|  | import "../elements/notifications/NotificationDrawer" | ||||||
|  |  | ||||||
| export abstract class Interface extends LitElement { | export abstract class Interface extends LitElement { | ||||||
|     @property({type: Boolean}) |     @property({type: Boolean}) | ||||||
|     sidebarOpen = true; |     sidebarOpen = true; | ||||||
|  |  | ||||||
|  |     @property({type: Boolean}) | ||||||
|  |     notificationOpen = false; | ||||||
|  |  | ||||||
|     abstract get sidebar(): SidebarItem[]; |     abstract get sidebar(): SidebarItem[]; | ||||||
|  |  | ||||||
|     createRenderRoot(): ShadowRoot | Element { |     createRenderRoot(): ShadowRoot | Element { | ||||||
| @ -25,6 +29,9 @@ export abstract class Interface extends LitElement { | |||||||
|         window.addEventListener("ak-sidebar-toggle", () => { |         window.addEventListener("ak-sidebar-toggle", () => { | ||||||
|             this.sidebarOpen = !this.sidebarOpen; |             this.sidebarOpen = !this.sidebarOpen; | ||||||
|         }); |         }); | ||||||
|  |         window.addEventListener("ak-notification-toggle", () => { | ||||||
|  |             this.notificationOpen = !this.notificationOpen; | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     render(): TemplateResult { |     render(): TemplateResult { | ||||||
| @ -35,10 +42,22 @@ export abstract class Interface extends LitElement { | |||||||
|                 </ak-sidebar-hamburger> |                 </ak-sidebar-hamburger> | ||||||
|                 <ak-sidebar class="pf-c-page__sidebar ${this.sidebarOpen ? "pf-m-expanded" : "pf-m-collapsed"}" .items=${this.sidebar}> |                 <ak-sidebar class="pf-c-page__sidebar ${this.sidebarOpen ? "pf-m-expanded" : "pf-m-collapsed"}" .items=${this.sidebar}> | ||||||
|                 </ak-sidebar> |                 </ak-sidebar> | ||||||
|                 <main class="pf-c-page__main"> |                 <div class="pf-c-page__drawer"> | ||||||
|                     <ak-router-outlet role="main" class="pf-c-page__main" tabindex="-1" id="main-content" defaultUrl="/library"> |                     <div class="pf-c-drawer ${this.notificationOpen ? "pf-m-expanded" : "pf-m-collapsed"}"> | ||||||
|                     </ak-router-outlet> |                         <div class="pf-c-drawer__main"> | ||||||
|                 </main> |                             <div class="pf-c-drawer__content"> | ||||||
|  |                                 <div class="pf-c-drawer__body"> | ||||||
|  |                                     <main class="pf-c-page__main"> | ||||||
|  |                                         <ak-router-outlet role="main" class="pf-c-page__main" tabindex="-1" id="main-content" defaultUrl="/library"> | ||||||
|  |                                         </ak-router-outlet> | ||||||
|  |                                     </main> | ||||||
|  |                                 </div> | ||||||
|  |                             </div> | ||||||
|  |                             <ak-notification-drawer class="pf-c-drawer__panel pf-m-width-33"> | ||||||
|  |                             </ak-notification-drawer> | ||||||
|  |                         </div> | ||||||
|  |                     </div> | ||||||
|  |                 </div> | ||||||
|             </div>`; |             </div>`; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -95,7 +95,7 @@ export class EventInfo extends LitElement { | |||||||
|             return html`<div class="pf-l-flex"> |             return html`<div class="pf-l-flex"> | ||||||
|                     <div class="pf-l-flex__item"> |                     <div class="pf-l-flex__item"> | ||||||
|                         <h3>${gettext("Exception")}</h3> |                         <h3>${gettext("Exception")}</h3> | ||||||
|                         <code>${this.event.context.error || this.event.context.message}</code> |                         <code>${this.event.context.message || this.event.context.error}</code> | ||||||
|                     </div> |                     </div> | ||||||
|                     <div class="pf-l-flex__item"> |                     <div class="pf-l-flex__item"> | ||||||
|                         <h3>${gettext("Expression")}</h3> |                         <h3>${gettext("Expression")}</h3> | ||||||
| @ -117,7 +117,7 @@ export class EventInfo extends LitElement { | |||||||
|                     </div> |                     </div> | ||||||
|                     <div class="pf-l-flex__item"> |                     <div class="pf-l-flex__item"> | ||||||
|                         <h3>${gettext("Exception")}</h3> |                         <h3>${gettext("Exception")}</h3> | ||||||
|                         <code>${this.event.context.error}</code> |                         <code>${this.event.context.message || this.event.context.error}</code> | ||||||
|                     </div> |                     </div> | ||||||
|                 </div>`; |                 </div>`; | ||||||
|         case "policy_execution": |         case "policy_execution": | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer