/* global conjur, jQuery, async */ (function(conjur, $, async, errback) { 'use strict'; var Generic = this.Generic; var User = this.User = function(args) { if (!(this instanceof User)) { return new User(args); } var superArguments = Array.prototype.slice.call(arguments); superArguments.unshift('user'); Generic.apply(this, superArguments); return undefined; }; User.prototype = Object.create(Generic.prototype); User.prototype.constructor = User; User.prototype.publicKeys = function(callback) { $.ajax({ url: '/api/pubkeys/' + window.encodeURIComponent(this.id), success: function(data) { callback(null, data.split('\n').filter(function(d) { return d.trim().length > 0; })); }, error: callback }); }; User.prototype.fetch = function(callback, customErrback) { var self = this; if (typeof(customErrback) === 'undefined') { customErrback = errback; // reset to default } async.parallel([ this.attributes.bind(this), this.ownedResources.bind(this), this.allRoles.bind(this), this.resource.bind(this), this.publicKeys.bind(this), this.auditRole.bind(this), this.auditResource.bind(this) ], function(err, results) { if (err) { return customErrback(err.status); } callback({ user: results[0], owned: results[1], roles: results[2], owner: results[3].owner, annotations: results[3].annotations, pubkeys: results[4], audit: self.mergeAudit(results[5], results[6]) }); return undefined; }); }; }).bind(conjur.models.Record) ( conjur, jQuery, async, conjur.utils.errback );