/**
* This file is part of Sesatheque.
* Copyright 2014-2015, Association Sésamath
*
* Sesatheque is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3
* as published by the Free Software Foundation.
*
* Sesatheque is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Sesatheque (LICENCE.txt).
* @see http://www.gnu.org/licenses/agpl.txt
*
*
* Ce fichier fait partie de l'application Sésathèque, créée par l'association Sésamath.
*
* Sésathèque est un logiciel libre ; vous pouvez le redistribuer ou le modifier suivant
* les termes de la GNU Affero General Public License version 3 telle que publiée par la
* Free Software Foundation.
* Sésathèque est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ;
* sans même la garantie tacite de QUALITÉ MARCHANDE ou d'ADÉQUATION à UN BUT PARTICULIER.
* Consultez la GNU Affero General Public License pour plus de détails.
* Vous devez avoir reçu une copie de la GNU General Public License en même temps que Sésathèque
* (cf LICENCE.txt et http://vvlibri.org/fr/Analyse/gnu-affero-general-public-license-v3-analyse
* pour une explication en français)
*/
'use strict'
const Structure = require('./Structure')
/**
* Objet User passé entre l'authentification (sesalab) et le client (sesatheque)
* @param {object} user les propriétés pour initialiser ce User
* @constructor
*/
function User (user) {
if (this instanceof User) {
if (!user) user = {}
/**
* Nom
* @type {string}
*/
this.nom = user.nom
/**
* Prénom
* @type {string}
*/
this.prenom = user.prenom
/**
* mail (on regarde les propriétés email puis mail dans l'objet passé)
* @type {string}
*/
this.email = user.email || user.mail
/**
* Liste des roles {role1:true, …}
* @type {object}
*/
this.roles = user.roles
if (user.pid) {
/**
* L'id "universel" de ce user, sous la forme authBaseId/oid
*/
this.pid = user.pid
} else if (user.origine && user.idOrigine) {
// pour compatibilité ascendante
console.error(new Error('DEPRECATED : user avec origine et idOrigine'), user)
this.pid = user.origine + '/' + user.idOrigine
}
/**
* Les structures
* @type {Structure[]}
*/
this.structures = []
if (Array.isArray(user.structures)) {
user.structures.forEach((structure) => {
this.structures.push(new Structure(structure))
})
}
} else {
throw new Error('Constructeur qui doit être appelé avec new')
}
}
module.exports = User