File

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

Index

Properties

Properties

id
id: string
Type : string
name
name: string
Type : string
type
type: string
Type : string
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 ""