File

src/lib/model/eo-user.model.ts

Index

Properties
Methods

Constructor

constructor(json: any)

Creates a new instance

Parameters :
Name Type Optional Description
json any no

The JSON object received from the backend. This will be used to construct the new user instance

Properties

Public deputies
deputies: any[]
Type : any[]

List of the users deputies

Public email
email: string
Type : string

The users email address

Public firstname
firstname: string
Type : string

The users firstname

Public id
id: string
Type : string

The users ID

Public imageUri
imageUri: string
Type : string

URI to the users avatar image

Public lastname
lastname: string
Type : string

The users lastname

Public name
name: string
Type : string

The users name

Public passwortvalidation
passwortvalidation: any
Type : any

Password validation settings

Public present
present: boolean
Type : boolean

Flag indicating whether or not the user is present

Public privileges
privileges: Privileges[]
Type : Privileges[]

List of the users privileges

Public roles
roles: any[]
Type : any[]

List of roles the user belongs to

Public substitutesOf
substitutesOf: any[]
Type : any[]

List of the users substitutes

Public title
title: string
Type : string

The users title (generated from backends title pattern)

Public userSettings
userSettings: any
Type : any

Custom user settings

Methods

Public getClientLocale
getClientLocale()

Gets the users configured client locale

Returns : string

locale string

Public getSchemaLocale
getSchemaLocale()

Gets the users configured schema locale

Returns : string

locale string

hasPrivilege
hasPrivilege(privilege: string)

Checks if the user has a certain privilege

Parameters :
Name Type Optional Description
privilege string no

The privilege to be checked

Returns : boolean

True if the user has this particular privilege, false otherwise

hasRole
hasRole(role: string)

Checks if the user has a certain role

Parameters :
Name Type Optional Description
role string no

The role to be checked

Returns : boolean

True if the user has this particular role, false otherwise

Public setImageBase
setImageBase(base: string)

adds the base path for the users image path.

Parameters :
Name Type Optional Description
base string no

The base path

Returns : void
export interface Privileges {
  id: string;
  type: string;
  name: string;
}

export interface LicenseState {
  type: string;
  error?: string;
  expires?: string;
}

export class EoUser {

  /**
   * The users ID
   */
  public id: string;
  /**
   * The users name
   */
  public name: string;
  /**
   * The users firstname
   */
  public firstname: string;
  /**
   * The users lastname
   */
  public lastname: string;
  /**
   * The users title (generated from backends title pattern)
   */
  public title: string;
  /**
   * The users email address
   */
  public email: string;
  /**
   * Flag indicating whether or not the user is present
   */
  public present: boolean;
  /**
   * URI to the users avatar image
   */
  public imageUri: string;
  /**
   * Custom user settings
   */
  public userSettings: any;
  /**
   * @ignore
   */
  public schema: any;
  /**
   * List of the users privileges
   */
  public privileges: Privileges[];
  /**
   * List of roles the user belongs to
   */
  public roles: any[];
  /**
   * List of the users deputies
   */
  public deputies: any[];
  /**
   * List of the users substitutes
   */
  public substitutesOf: any[];
  /**
   * Password validation settings
   */
  public passwortvalidation: any;
  /**
   * @ignore
   */public schemaLocale: string;
  /**
   * @ignore
   */
  public uiDirection: string;
  /**
   * @ignore
   */
  public license: LicenseState;

  /**
   * Creates a new instance
   * @param json The JSON object received from the backend. This will be used to construct the new user instance
   */
  constructor(json: any) {

    const jUser = json['user'];
    const jSchema = json['schema'];

    this.id = jUser.id;
    this.name = jUser.name;
    this.firstname = jUser.firstname;
    this.lastname = jUser.lastname;
    this.title = jUser.title;
    this.email = jUser.email;
    this.present = jUser.present;
    if (jUser.hasimage === true) {
      this.imageUri = '/organization/image/' + this.id;
    }
    this.userSettings = typeof json['usersettings'] === 'object' ? json['usersettings'] : {};
    this.schema = {
      version: jSchema.version,
      supportedLocales: jSchema.supportedlocales
    };

    this.privileges = jUser.privileges;
    this.roles = jUser.effectiveroles;
    this.deputies = jUser.deputies || [];
    this.substitutesOf = jUser.substitutesOf || [];
    this.schemaLocale = jUser.locale;
    this.license = json['license'];
  }

  /**
   * Checks if the user has a certain privilege
   * @param privilege The privilege to be checked
   * @returns True if the user has this particular privilege, false otherwise
   */
  hasPrivilege(privilege: string): boolean {

    let match = false;
    if (this.privileges) {
      let i = 0;
      while (!match && i < this.privileges.length) {
        match = this.privileges[i].name === privilege;
        i++;
      }
    }
    return match;
  }

  /**
   * Checks if the user has a certain role
   * @param role The role to be checked
   * @returns True if the user has this particular role, false otherwise
   */
  hasRole(role: string): boolean {
    let match = false;
    if (this.roles) {
      let i = 0;
      while (!match && i < this.roles.length) {
        match = this.roles[i].name === role;
        i++;
      }
    }
    return match;
  }

  /**
   * adds the base path for the users image path.
   * @param base The base path
   */
  public setImageBase(base: string) {
    if (this.imageUri) {
      this.imageUri = base + this.imageUri;
    }
  }

  /**
   * Gets the users configured client locale
   * @returns locale string
   */
  public getClientLocale(): string {
    return this.userSettings['clientlocale'];
  }

  /**
   * Gets the users configured schema locale
   * @returns locale string
   */
  public getSchemaLocale(): string {
    return this.schemaLocale;
  }

}

results matching ""

    No results matching ""