src/app/features/change-history/display-audit-user/display-audit-user.component.ts

Description

Who made an audited change.

The backend records whatever the authenticated session carried, which is a user-entity id on systems with user records and a bare username elsewhere. Only the former can be resolved to a record, so the bare name is shown as-is rather than rendered as a broken link.

Extends

ViewDirective<AuditUser>

Example

Metadata

Relationships

Used by

No results matching.

Index

Properties
Inputs

Inputs

config
Type : C
Default value : undefined
Inherited from ViewDirective
entity
Type : Entity
Inherited from ViewDirective
formFieldConfig
Type : FormFieldConfig
Inherited from ViewDirective
id
Type : string
Inherited from ViewDirective
tooltip
Type : string
Inherited from ViewDirective
value
Type : T
Inherited from ViewDirective

Properties

Readonly author
Type : unknown
Default value : computed( () => this.value()?.name ?? this.value()?.id ?? "", )
Readonly userEntityId
Type : unknown
Default value : computed(() => ensureValidEntityId(this.author()))
Readonly config
Type : unknown
Default value : computed<C>(() => { const ffc = this.formFieldConfig(); return ffc !== undefined ? (ffc.additional as C) : this._directConfig(); })
Inherited from ViewDirective
Readonly isPartiallyAnonymized
Type : unknown
Default value : computed<boolean>(() => { const entity = this.entity(); const id = this.id(); return ( (entity?.anonymized && entity?.getSchema()?.get(id)?.anonymize === "retain-anonymized") ?? false ); })
Inherited from ViewDirective
import { Component, computed } from "@angular/core";
import { ViewDirective } from "../../../core/entity/default-datatype/view.directive";
import { DynamicComponent } from "../../../core/config/dynamic-components/dynamic-component.decorator";
import { EntityBlockComponent } from "../../../core/basic-datatypes/entity/entity-block/entity-block.component";
import { AuditUser } from "../model/audit-record";

/**
 * The given author as an entity id, or undefined when it is not one.
 * An entity id is type-prefixed, which a plain username is not.
 */
export function ensureValidEntityId(author: string): string | undefined {
  return author?.includes(":") ? author : undefined;
}

/**
 * Who made an audited change.
 *
 * The backend records whatever the authenticated session carried, which is a
 * user-entity id on systems with user records and a bare username elsewhere.
 * Only the former can be resolved to a record, so the bare name is shown as-is
 * rather than rendered as a broken link.
 */
@DynamicComponent("DisplayAuditUser")
@Component({
  selector: "app-display-audit-user",
  imports: [EntityBlockComponent],
  template: `
    @if (userEntityId()) {
      <app-entity-block
        [entityId]="userEntityId()"
        [showEntityId]="true"
      ></app-entity-block>
    } @else {
      <span>{{ author() || "-" }}</span>
    }
  `,
})
export class DisplayAuditUserComponent extends ViewDirective<AuditUser> {
  readonly author = computed(
    () => this.value()?.name ?? this.value()?.id ?? "",
  );

  readonly userEntityId = computed(() => ensureValidEntityId(this.author()));
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""